Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `last_response' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_5::Nested_1:0x184dd658> #174

Closed
malagant opened this issue Aug 20, 2010 · 10 comments

Comments

@malagant
Copy link

After setting up a new app with the following Gemfile, I get the strange error which could be related to webrat (which I am not using and rspec-rails shouldn't either).

source 'http://rubygems.org'

gem 'rails', '3.0.0.rc'

gem 'mongoid', '>= 2.0.0.beta.16'

group :development, :test do
  gem 'capybara', :git => "http://github.com/jnicklas/capybara.git"
  gem "factory_girl"
  gem "faker"
  gem "rspec-rails",        :git => "http://github.com/rspec/rspec-rails.git"
  gem "rspec",              :git => "http://github.com/rspec/rspec.git"
  gem "rspec-core",         :git => "http://github.com/rspec/rspec-core.git"
  gem "rspec-expectations", :git => "http://github.com/rspec/rspec-expectations.git"
  gem "rspec-mocks",        :git => "http://github.com/rspec/rspec-mocks.git"
end

In application.rb I use the following:

config.generators do |g|
  g.orm :mongoid
  g.test_framework :rspec
end

And finally the specs failing:

  it "redirects to the created post" do
    Post.stub(:new) { mock_post(:save => true) }
    post :create, :post => {}
    response.should redirect_to(post_url(mock_post))
  end
end

This is all on trunk and by now I only have generated specs.

All help is very welcome.

Michael

@dchelimsky
Copy link
Contributor

Generated specs only support ActiveRecord, but let's see if we can at least narrow down the problem. Please post the full backtrace of the error.

@malagant
Copy link
Author

I'm afraid, that's all I got:

  1. PostsController POST create with valid params redirects to the created post
    Failure/Error: response.should redirect_to(post_url(mock_post))
    undefined method `last_response' for #RSpec::Core::ExampleGroup::Nested_1::Nested_5::Nested_1:0x79ed7c11

    /Users/mjohann/.rvm/gems/jruby-1.5.1/gems/actionpack-3.0.0.rc/lib/action_dispatch/testing/assertions/routing.rb:174:in`method_missing'

    /Users/mjohann/.rvm/gems/jruby-1.5.1/gems/webrat-0.7.2.beta.1/lib/webrat/adapters/rack.rb:26:in `response'

    /Users/mjohann/.rvm/gems/jruby-1.5.1/gems/webrat-0.7.2.beta.1/lib/webrat/core/methods.rb:29:in`response'

    ./spec/controllers/posts_controller_spec.rb:53

    :1

@dchelimsky
Copy link
Contributor

Trying to set this up and running into a few config hiccups - I don't have any mongo apps yet. Would you kindly set one up in a github repo so I can pull exactly what you have?

@dchelimsky
Copy link
Contributor

Also - before you do that - I just updated the gemspec so there is no longer a dependency on webrat. Would you please bundle update and see if you still have the problem?

@malagant
Copy link
Author

Okay, thanks that solved the problem.

@malagant
Copy link
Author

But...
...unfortunately I guess we're having still a problem in mocks.

147 # == Examples
148 #
149 # stub_model(Person)
150 # stub_model(Person).as_new_record
151 # stub_model(Person, :id => 37)
152 # stub_model(Person) do |person|
153 # person.first_name = "David"
154 # end
155 def stub_model(model_class, stubs={})
156 primary_key = model_class.primary_key.to_sym
157 stubs = {primary_key => next_id}.merge(stubs)
158 model_class.new.tap do |m|
159 m.send("#{primary_key}=", stubs.delete(primary_key))
160 m.extend ModelStubber
161 m.stub(stubs)
162 yield m if block_given?
163 end
164 end

In line 156 primary_key returns nil.

I guess this is due to ActiveRecord dependencies.
Let me know if I can support you in finding a solution to make it work with mongoid.

BTW. I made a repo at gihub with the mentioned app.
You can find it here : git://github.com/malagant/capa-test.git

Cheers
Michael Johann

@dchelimsky
Copy link
Contributor

The last_response issue is resolved, so I'm closing this. Please raise the primary_key issue separately. Thx. And thx for setting up the repo. Please reference that again in the new issue.

@tilo
Copy link

tilo commented Feb 3, 2014

it's not clear according to the comment history as to what the fix actually was.

I'm running into the same issue trying to test an HTTP post request with JSON data.
Using active-record, and:

rspec 2.14.1
rspec-core 2.14.7
rspec-expectations 2.14.5
rspec-mocks 2.14.5
rspec-rails 2.14.1

@myronmarston
Copy link
Member

@tilo -- please open a new issue. This issue is 3 years old and since it's closed it doesn't stay on our active list.

@tilo
Copy link

tilo commented Feb 3, 2014

cool! will do

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants