[rspec-users] custom matchers for request specs

Alan B liststuff at gmail.com
Fri Feb 4 04:30:36 EST 2011

Hi all, I'm trying to create a custom matcher that will visit a given
path and check it's authenticated.
Here's what I have so far (using rspec-rails and capybara):

matcher :require_authentication do
  match do |path|
    visit path
    #page.current_path.should == sign_in_path
    page.current_path.should == '/sign_in'

The above version works, but when using the commented out line I get:

       undefined local variable or method `sign_in_path' for

sign_in_path is one of the routes in my application and works fine
inside a describe/it block.
I don't understand why the matcher recognises visit() but not

any ideas?

More information about the rspec-users mailing list