Class: Contracts::Expects
Instance Attribute Summary collapse
-
#expectations ⇒ Object
readonly
Returns the value of attribute expectations.
Attributes inherited from Base
Instance Method Summary collapse
- #before_call(receiver, *args, &blk) ⇒ Object
-
#initialize(expectations) ⇒ Expects
constructor
A new instance of Expects.
Methods inherited from Base
Constructor Details
#initialize(expectations) ⇒ Expects
Returns a new instance of Expects.
143 144 145 |
# File 'lib/contracts.rb', line 143 def initialize(expectations) @expectations = expectations end |
Instance Attribute Details
#expectations ⇒ Object (readonly)
Returns the value of attribute expectations.
141 142 143 |
# File 'lib/contracts.rb', line 141 def expectations @expectations end |
Instance Method Details
#before_call(receiver, *args, &blk) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/contracts.rb', line 147 def before_call(receiver, *args, &blk) @parameter_names ||= method.parameters.map(&:last) @parameter_names.each_with_index do |parameter_name, idx| next unless expectation = expectations[parameter_name] Expectation.match! args[idx], expectation end rescue Expectation::Error raise Contracts::Error, "#{$!} in call to `#{method_name}`", caller[5..-1] end |