Route works in application, fails in Cucumber test
I have a route that works (recognized, can follow it) in a Rails 3 application, but fails in the Cucumber test:
routes.rb:
resources :tests do
member do
post 'start'
end
end
Working link in application:
=button_to 'Start', start_test_path(@test)
Gherkin step:
And I am on the test start page for "Sample Test"
Failing in paths.rb
when /the test start page for "([^\"]*)"/
start_test_path(Test.find_by_name($1))
...
(::) failed steps (::)
No route matches "/tests/1/start" (ActionController::RoutingError)
<internal:prelude>:10:in `synchronize'
./features/step_definitions/web_steps.rb:30:in `/^(?:|I )am on (.+)$/'
featur开发者_如何学Pythones/test_workflow.feature:24:in `And I am on the test start page for "Sample Test"'
Any ideas? Thanks!
The reason is that 'start' is a post
action, not a get
action. When you use the I am on the ...
cucumber step you are generating a get request, not a post request. To fix this, simply press the button in Cucumber, instead of visiting the direct path. This can be done with the press
cucumber step, like this:
When I press "Start"
This step will generate the appropriate post request, but it must be called after you visit the page that the button is located on. Alternatively, you can generate a post request in a custom cucumber step by doing something like this:
When /^I am on the test start page$/ do
post("/tests/1/start")
end
I don't know cucumber, but try this:
Rename your route from test
to tests
and your controller from TestController
to TestsController
This just might be a case where your naming conventions are messing things up, because they are not what Rails expects.
I don't know if I am right - just a guess.
精彩评论