#with fails when passed a #mock_model behaving as a null object #98

jimryan opened this Issue Jan 25, 2012 · 1 comment


None yet
2 participants

jimryan commented Jan 25, 2012

Given a spec like this:

let(:user) { mock_model(User).as_null_object }

before { User.stub_chain(:where, :first).and_return(user) }

it "logs user in" do
  post :create

And some code:

def create
    user = User.find(...).first

The spec will fail, claiming:

<UserSession (class)> received :create with unexpected arguments
    expected: ()
         got: ()

And this is due to how the ArgumentExpectation determines if the argument is a null object, which will fail to detect a mock_model behaving as a null object.

I'm not exactly clear on why this method was used to determine if the object was a null object, when we have #null_object?, so unless I'm missing something, I suggest we simply use that to determine if the object is a null object.

If not, then we can fix this on the rspec-rails side.

I'm happy to implement my fix, I just wanted someone else with a deeper understanding of RSpec to chime in and make sure my fix and this issue are valid.


@justinko justinko closed this in de283b3 Jan 26, 2012


This comment has been minimized.

Show comment Hide comment

jimryan Jan 27, 2012


jimryan commented Jan 27, 2012


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment