/expectable

The Expectable gem allows you to expect methods to be called on objects that are not MiniTest::Mock

Primary LanguageRubyMIT LicenseMIT

The Expectable gem is used as follows:

  1. 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
  1. 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).

  1. 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