Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Damian Sieczkowski
9,730 PointsTest that a class method is called is called using Rspec
I have an after_update callback that is meant to call a class method in another model if certain conditions are met. How can I test that it is actually called during an update?
3 Answers
Kyle Daugherty
16,441 PointsYeah, respond_to will just test that the method exists. You want something like:
expect(notification).to receive(:twilio_text_invite).with(arg_name)
You can also add additional constraints like specifying how many times you expect the message to be received.
Kyle Daugherty
16,441 PointsTake a look at the message expectations section here:
There's also an example on stackoverflow. Keep in mind the top voted answer uses RSpec v2 and it's changed for RSpec v3.
Damian Sieczkowski
9,730 PointsThanks, I ended up going with
expect(Notification).to respond_to(:twilio_text_invite).with(1).argument
But the way I understand it - that only tests the method exists - not that the method I'm testing is calling to it. Correct?