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

Closed
jimryan opened this Issue Jan 25, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@jimryan

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
  UserSession.should_receive(:create).with(user)
  post :create
end

And some code:

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

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.

Thanks,
Jim

@justinko justinko closed this in de283b3 Jan 26, 2012

@jimryan

This comment has been minimized.

Show comment Hide comment
@jimryan

jimryan Jan 27, 2012

Thanks!

jimryan commented Jan 27, 2012

Thanks!

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