I’m writing a plugin that modifies Rails routes, and I wanted to write an RSpec test that would verify that if I write an arbitrary route, it gets added to Rails. The test is at https://github.com/carpeliam/governor/blob/master/spec/action_dispatch/routing/mapper_spec.rb#L23. The line in question is:
{:get => "/articles/#{@article.id}/foos"}.should route_to(:controller => 'foos', :action => 'show', :governor_mapping => :articles)
This fails with No route matches "/articles/1/foos", but (1) I just verified two lines above that there’s an articles_foos route in Rails.application.routes, and (2) even if the spec doesn’t pass, the code works in the wild, so I know that the test is either wrong, or rather, I’m not testing it properly.
How do I fix my test to get it to pass?
I actually spoke to David Chelimsky about this at RailsConf, and we traced the issue down to Rack::Test. David then spoke to Yehuda Katz to see if what we were experiencing was expected, or a bug, and as it turns out, Rack::Test is just not built for this kind of thing. All in all, RailsConf was a great opportunity to get questions answered by the people who are the most intimate with the code. Thanks to David and Yehuda.