Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Rails 3, I'm getting a NoMethodError for the recycle! method during testing

Tags:

I've got a functional test that's using fixtures. I also am using fixtures in my Unit tests, but they work without flaw. When running the functional tests, I get a:

NoMethodError: undefined method 'recycle!' for #<Response:0x10346be10> /test/functional/responses_controller_test.rb:10:in 'test_testing'

My functional tests, at this point, are doing nothing more than a get to the index action. Example:

setup do   @response = responses(:one) end  test "testing" do   get :index   assert true end 

My TestHelper class does include all fixtures, so the Responses fixtures are definitely loading. And like I said, the fixtures work perfectly fine in Unit tests.

Any idea what might be causing this?

like image 403
the_gastropod Avatar asked Oct 02 '10 15:10

the_gastropod


1 Answers

Change

setup do   @response = responses(:one) end 

to

setup do   @myresponse = responses(:one) end 

and off you go!

The problem lies in "actionpack-3.0.1/lib/action_controller/test_case.rb" around line 386.

The testcase assumes that @response holds a "ActionDispatch::Response". You overwrite it, it's no "ActionDispatch::Response" anymore and the testcase fails.

I'm not sure if this is intended behaviour.

Anyway, just make sure you don't overwrite @response/@request/@controller/@routes and it should work.

like image 109
flo Avatar answered Oct 27 '22 00:10

flo