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

malagant opened this Issue Aug 20, 2010 · 10 comments


None yet
4 participants

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"

In application.rb I use the following:

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

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))

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

All help is very welcome.



dchelimsky commented Aug 20, 2010

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.

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/webrat-0.7.2.beta.1/lib/webrat/adapters/rack.rb:26:in `response'





dchelimsky commented Aug 23, 2010

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 commented Aug 23, 2010

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?

Okay, thanks that solved the problem.

...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

Michael Johann


dchelimsky commented Aug 24, 2010

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 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 commented Feb 3, 2014

@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 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