Skip to content

Loading…

API for uni-directional routing expectations #221

Closed
dchelimsky opened this Issue · 5 comments

2 participants

@dchelimsky
RSpec member

route_to delegates to assert_routing, which only passes if assert_generates and assert_recognizes would both pass. The Rails-3 router lets us define routes that are recognizable, but not generated. The simplest example is:

root :to => "projects#index"

In this case, this passes:

assert_recognizes({:controller => "projects", :action => "index"}, {:method => "get", :path => "/"})

But this fails:

assert_generates("/",{:controller => "projects", :action => "index"})

Therefore, these both fail:

assert_routing("/",{:controller => "projects", :action => "index"})
(:get => "/").should route_to({:controller => "projects", :action => "index"})

See http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4bd3a78/2a60d77662a1ec31 for a lengthy discussion on this topic.

@dchelimsky
RSpec member

After more thought, I'm going to make route_to delegate to assert_recognizes instead of assert_routing. Generation is something that rails knows how to do, so at that point we're spec'ing rails.

@dchelimsky
RSpec member

route_to delegates to assert_recognizes rather than assert_routing

  • aligns better with the matcher name
  • eliminates failures on alternate routes to same controllers
  • route generation can be spec'd in the context of view specs
  • Closed by b45d093.
@jensb

This should be documented properly, the publicly available docs still speak about "delegating to assert_routing". I spent hours trying to fix bugs in my app that weren't there ... :-(

How do I test route generation then with RSpec? I have some fairly complicated SEO routes (with multiple constraints) that need to be tested both ways.

@jensb

Actually, it was http://www.ruby-forum.com/topic/212050, via Google.

Maybe I should put less trust into old forum posts. :-)

@amatsuda amatsuda pushed a commit that referenced this issue
@dchelimsky dchelimsky route_to delegates to assert_recognizes rather than assert_routing
- aligns better with the matcher name
- eliminates failures on alternate routes to same controllers
- route generation can be spec'd in the context of view specs
- Closes #221.
b45d093
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.