Skip to content

Instantly share code, notes, and snippets.

@mislav
Created March 9, 2009 14:30
Show Gist options
  • Save mislav/76330 to your computer and use it in GitHub Desktop.
Save mislav/76330 to your computer and use it in GitHub Desktop.
Cucumber steps that integrate with Rails named routes
When /^I go to(?: the)? (.*?)(?: page)?$/ do |name|
visit get_named_route(name)
end
Then /^I should be on(?: the)? (.*?)(?: page)?$/ do |name|
path.should == get_named_route(name)
end
## features/support/env.rb
ActionController::Integration::Session.class_eval do
def get_named_route(name)
case name
when 'my profile'
"/users/#{request.session[:user]}"
else
send(name.gsub(' ', '_') + '_path')
end
end
end
@lorint
Copy link

lorint commented Oct 17, 2016

In Rails 4+ then this also works, just change ActionController to ActionDispatch:

## features/support/env.rb
ActionDispatch::Integration::Session.class_eval do
  def get_named_route(name)
    case name
    when 'my profile'
      "/users/#{request.session[:user]}"
    else
      send(name.gsub(' ', '_') + '_path')
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment