The Expectable gem is used as follows:
- The given class and it's methods are defined, e.g.:
class A
# Instance method - use include on your instance
def b
end
# Static method - use extend on your class
def self.b
end
end
- Include Expectable on this class, e.g.:
a = A.new
a.include Expectable
or
a = A
a.extend Expectable
(Note: You don't need to reassign A
, I simply doing this so that the next step will always work).
- In a given test case, we would like to expect a method call on an instance of this class, e.g.:
def test_a_calls_b
a.expect(:b, 'my-return-value', ['my-required-input'])
puts a.b('my-required-input')
end
end
test_a_calls_b
This case would return:
my-required-input
=> true