Class: Contracts::Expects

Inherits:
Base
  • Object
show all
Defined in:
lib/contracts/expects.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#method

Instance Method Summary collapse

Methods inherited from Base

#+@, #method_name

Constructor Details

#initialize(expectations) ⇒ Expects

Returns a new instance of Expects.



15
16
17
# File 'lib/contracts/expects.rb', line 15

def initialize(expectations)
  @expectations = expectations
end

Instance Attribute Details

#expectationsObject (readonly)

Returns the value of attribute expectations.



13
14
15
# File 'lib/contracts/expects.rb', line 13

def expectations
  @expectations
end

Instance Method Details

#before_call(_receiver, *args, &_blk) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/contracts/expects.rb', line 19

def before_call(_receiver, *args, &_blk)
  args.each_with_index do |value, idx|
    next unless expectation = expectations_ary[idx]
    Expectation::Matcher.match! value, expectation
  end

  nil
rescue Expectation::Error
  error! "#{$ERROR_INFO} in call to `#{method_name}`"
end