[rspec-users] rspec route question
David Chelimsky
dchelimsky at gmail.com
Fri Jul 16 07:19:53 EDT 2010
On Jul 15, 2010, at 6:24 PM, Matt Kolenda wrote:
> Hello
>
> I'm having some trouble getting rspec to recognize a route.
>
> # This works
> describe "routes" do
> it "should have a route" do
> { :get => "/accounts/3/jobs/3/
> applications/1/edit" }.should route_to(:controller => 'applications', :action => 'edit', :id => "1", :account_id => "3", :job_id => "3" )
> end
> end
>
> # This fails
> describe "#edit" do
> it "should respond to application/edit" do
> get "#{edit_account_job_application_path(@account.id, @job.id, @application.id)}"
> response.should be_success
> end
> end
Controller specs include behavior from ActionController::TestCase, which is designed to handle requests using a hash representing the action and params rather than a URL (or route). The proper way to do this is:
get :edit, :id => @application.id, :job_id => @job.id, :account_id => @account_id
If you want to, you can use urls in request specs in rspec-rails-2 (integration specs in rspec-rails-1). But I wouldn't recommend that unless you feel you'll benefit from going through routing and rendering views.
HTH,
David
>
> Here is the stack trace
> 1)
> ActionController::RoutingError in 'ApplicationsController#edit should respond to application/edit'
> No route matches {:action=>"/accounts/23/jobs/
> 99/applications/299/edit", :controller=>"applications"}
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:419:in `generate'
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:352:in `generate_extras'
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:348:in `extra_keys'
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:96:in `assign_parameters'
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:440:in `process'
> /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:398:in `get'
> ./spec/controllers/applications_controller_spec.rb:26:
>
>
> Note that this route works fine at runtime in the browser. Also rails is able to resolve the route "edit_account_job_application_path".
>
> I'm running rspec 1.3.0 and rspec-rails 1.3.2
>
> Thanks in advance!
>
> Matt
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100716/205dd2fa/attachment.html>
More information about the rspec-users
mailing list