简体   繁体   中英

Method get of ActionController::TestCase ignores routes.rb?

I'm running into issue which seems to indicate that ActionController::TestCase.get() method ignores what I have in routes.rb.

Rails version is 3.0.10.

I have the following RSpec2 test of my XmlRpcController#index action:

it "should get nothing in response to GET request" do
  get :index
  response.response_code.should == 400 #bad_request
end

And the only line related to this route in routes.rb is:

post 'rpc', :to => "xml_rpc#index"

'rake routes' also shows only this route defined.

As a result when I run this test that action actually DOES get executed! I judge this by putting a simple puts inside it) and also a log contains:

Processing by XmlRpcController#index as HTML

Also if I go to 'localhost:3000/rpc' in browser - it says no route found: just like it should. But tests have other behavior and this puzzles me...

Can anybody hint my why does this happen? I'm only starting learning about RoR :) Earlier it seemed to me that these 'get/post' methods of TestCase do respect routes.rb...

Am I missing something obvious? :)

It seems that 'get :index' method is ignoring the routes.rb indeed.

The real solution for me was to use be_routable rspec matcher written for this particular purpose:

  describe "GET 'contact'" do
    it "should be successful" do
      { :get => '/rpc' }.should_not be_routable
    end
  end

Figured this out thanks to some user from Ruby-Forum. More info here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM