I can't understand why the following code does not work in rspec when running my tests.
Lead.update_status(2,2,true)
expect(Lead).to receive(:update_status).with(2, 2, true)
I have also tried
Lead.update_status(2,2,true)
expect_any_instance_of(Lead).to receive(:update_status).with(2, 2, true)
The error I I get is
(<Lead(id: integer, contact_id: integer, course_presentation_id: integer, status: integer, created_by_user_id: integer, updated_by_user_id: integer, created_at: datetime, updated_at: datetime, mailchimp_status: integer) (class)>).update_status(2, 2, true)
expected: 1 time with arguments: (2, 2, true)
received: 0 times with arguments: (2, 2, true)
Note if I add puts "test" into my code this is prints out, so I know that update_status is actually working.
Any ideas? Thanks.
You should place your expectation before the code you expect to call that method:
expect(Lead).to receive(:update_status).with(2, 2, true)
Lead.update_status(2,2,true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With