[rspec-users] route_for testing multiple request methods

Brandon Olivares programmer2188 at gmail.com
Fri Apr 10 01:08:23 EDT 2009


I'm trying to use route_for to test my routes. I have two routes that have
the same path, but different request methods.

map.with_options :controller => 'contact' do |c|
  c.contact 'contact.html', :action => 'index',
  :conditions => {:method => :get}
  c.process_contact_form 'contact.html', :action => 'process_form',
  :conditions => {:method => :post}

My test is:

    it "should map  {:controller => 'contact', :action => 'process_form'} to
/contact.html" do
      route_for(:controller => 'contact', :action => 'process_form').should
    end # it should map  {:controller => 'contact', :action =>
'process_form'} to /contact.html

The error:

Test::Unit::AssertionFailedError in 'ContactController route generation
should map  {:controller => 'contact', :action => 'process_form'} to
The recognized options <{"action"=>"index", "controller"=>"contact"}> did
not match <{"action"=>"process_form", "controller"=>"contact"}>, difference:

Is this a bug, or am I doing something wrong? It works when I use
assert_generates, so I think the routes are correct.


More information about the rspec-users mailing list