Skip to content

Instantly share code, notes, and snippets.

@helino
Created December 1, 2010 05:30
Show Gist options
  • Save helino/723015 to your computer and use it in GitHub Desktop.
Save helino/723015 to your computer and use it in GitHub Desktop.
How does scoped before works in rspec?
require_relative '../router'
describe Router, "#handle" do
before do
puts "I'm being run before each 'it'"
@router = Router.new
end
it "raises an ArgumentError on empty request string" do
lambda{@router.handle("")}.should raise_error(ArgumentError)
end
it "runs the handler when the request is matched" do
@router.get '/' do 2 end
@router.handle('/').should equal 2
end
context "runs the correct handler when multiple handlers have been added" do
before(:all) do
puts "I'm being run once before the 'it's in my scope"
@router.get '/' do 1 end
@router.get '/foo' do 2 end
@router.get '/bar' do 3 end
end
it "returns 1 for /" do
@router.handle('/').should equal 1
end
it "returns 2 for /foo" do
@router.handle('/foo').should equal 2
end
it "returns 3 foo /bar" do
@router.handle('/bar').should equal 3
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment