Forum: RSpec route_for testing multiple request methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Brandon O. (Guest)
on 2009-04-10 09:35
(Received via mailing list)

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

map.with_options :controller => 'contact' do |c| '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 =>
    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"}>
not match <{"action"=>"process_form", "controller"=>"contact"}>,

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

David C. (Guest)
on 2009-04-10 11:00
(Received via mailing list)
On Fri, Apr 10, 2009 at 2:08 AM, Brandon O.
<removed_email_address@domain.invalid> wrote:
> End
> assert_generates, so I think the routes are correct.
assert_recognizes, however, will fail in the same way :)


route_for(:controller => 'contact', :action => 'index')
  .should == {:path => '/contact.html', :method => :get}

route_for(:controller => 'contact', :action => 'process_form')
  .should == {:path => '/contact.html', :method => :post}

The default is :method => :get, so the first doesn't require the
:method in the hash:

route_for(:controller => 'contact', :action => 'index')
  .should == :method => :get
This topic is locked and can not be replied to.