Rails: waiting for jobs on the RSpec model layout

I am trying to set expectations on a mocked ActiveRecord model. I created the following example, which should go based on the documentation I can find.

it "should pass given the correct expectations" do
  payment = mock_model(Payment)
  payment.should_receive(:membership_id).with(12)
  payment.membership_id = 12
end

Error with error "... Mock" Payment_1004 "received an unexpected message: membership_id = with (12)"

I understand that I'm testing a mocking structure, I'm just trying to figure out how to set up expectations.

+3
source share
2 answers

You set the expectation of the wrong method name - :membership_idis "getter", :membership_id=is "setter". The correct line is:

payment.should_receive(:membership_id=).with(12)
+10
source

"" - id - - :

mock_model(Payment,:[]= => nil, :save=> nil)

...

mock_model(Payment,:[]= => nil)

Lille

+1

Source: https://habr.com/ru/post/1712590/


All Articles