Class: Stendhal::Mocks::MockVerifier::MessageExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/stendhal/mocks/mock_verifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, options = {}) ⇒ MessageExpectation

Returns a new instance of MessageExpectation.



67
68
69
70
71
# File 'lib/stendhal/mocks/mock_verifier.rb', line 67

def initialize(method, options = {})
  @method = method
  @times_expected = options[:negative] ? 0 : 1
  @times_called = 0
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



63
64
65
# File 'lib/stendhal/mocks/mock_verifier.rb', line 63

def method
  @method
end

#times_calledObject (readonly)

Returns the value of attribute times_called.



64
65
66
# File 'lib/stendhal/mocks/mock_verifier.rb', line 64

def times_called
  @times_called
end

#times_expectedObject

Returns the value of attribute times_expected.



65
66
67
# File 'lib/stendhal/mocks/mock_verifier.rb', line 65

def times_expected
  @times_expected
end

Instance Method Details

#register_callObject



73
74
75
# File 'lib/stendhal/mocks/mock_verifier.rb', line 73

def register_call
  @times_called += 1
end

#verifyObject



77
78
79
# File 'lib/stendhal/mocks/mock_verifier.rb', line 77

def verify
  raise Stendhal::Exceptions::ExpectationNotMet.new "expected to be sent :#{method} #{times_expected} time#{times_expected == 1 ? '' : 's'}, but received it #{times_called} time#{times_called == 1 ? '' : 's'}" unless times_expected == times_called
end