Skip to content

undefined method `mock' for some controller specs that expect a mocked model should receive a message #218

@modellurgist

Description

@modellurgist

To replicate:

  • use ree-1.8.7-2010.02 (via RVM with a gemset, but not sure if that affects result)
  • use rails 3.0.0, rspec-rails 2.0.0.beta.22
  • create a new rails project and cd into its directory
  • $ rails g rspec:install
  • $ rails g scaffold Project (where Project is arbitrary model name)
  • create and migrate the database
  • $ rails g scaffold Project # an arbitrary model name
  • copy the spec for ProjectController's #create method to the specs for its #new method
  • modify that spec example to call 'get :new' but otherwise leave it the same
    
    it "saves the project" do
      Project.stub(:new).with({'these' => 'params'}) { mock_project(:save => true) }
      mock_project.should_receive(:save)
      get :new
    end 
    
  • in the Project controller's #new method add a line to call save on @project (this step is not necessary to reproduce the error)
  • execute $ rake spec
  • instead of a failure (on just the #new spec we added), it gives this error:
    
    Failure/Error: @mock_project ||= mock_model(Project, stubs).as_null_object
     undefined method `mock' for #
     # /Users/myuser/.rvm/gems/ree-1.8.7-2010.02@mygemset/gems/actionpack-3.0.0/lib/action_dispatch/testing/assertions/routing.rb:177:in`method_missing'
     # /Users/myuser/.rvm/gems/ree-1.8.7-2010.02@mygemset/gems/rspec-rails-2.0.0.beta.22/lib/rspec/rails/mocks.rb:71:in `mock_model'
     # ./spec/controllers/projects_controller_spec.rb:6:in`mock_project'
     # ./spec/controllers/projects_controller_spec.rb:37
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions