Class: Cadenza::Library::Expectation

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenza/library/expectation.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Expectation

Returns a new instance of Expectation.


18
19
20
# File 'lib/cadenza/library/expectation.rb', line 18

def initialize(params)
   @params = params
end

Instance Method Details

#argc(expected) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cadenza/library/expectation.rb', line 22

def argc(expected)
   pass = case expected
      when Fixnum then params.length == expected
      when Range then expected.include?(params.length)
   end

   raise InvalidArgumentCountError.new(expected, params.length) unless pass

   # return self to allow chaining
   self
end

#eighth(e) ⇒ Object


41
# File 'lib/cadenza/library/expectation.rb', line 41

def eighth(e);  nth(7, e); end

#fifth(e) ⇒ Object


38
# File 'lib/cadenza/library/expectation.rb', line 38

def fifth(e);   nth(4, e); end

#first(e) ⇒ Object


34
# File 'lib/cadenza/library/expectation.rb', line 34

def first(e);   nth(0, e); end

#fourth(e) ⇒ Object


37
# File 'lib/cadenza/library/expectation.rb', line 37

def fourth(e);  nth(3, e); end

#ninth(e) ⇒ Object


42
# File 'lib/cadenza/library/expectation.rb', line 42

def ninth(e);   nth(8, e); end

#nth(idx, e) ⇒ Object

if anyone really expects more than 10 parameters they will just have to use the #nth function


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cadenza/library/expectation.rb', line 46

def nth(idx, e)
   # do no validations if insufficient parameters are given (the argc validation is used for that)
   return if idx > (params.length - 1)

   val = params[idx]

   raise InvalidArgumentTypeError.new(e[:is_a], val.class) if e.has_key?(:is_a) && !val.is_a?(e[:is_a])

   # return self to allow chaining
   self
end

#second(e) ⇒ Object


35
# File 'lib/cadenza/library/expectation.rb', line 35

def second(e);  nth(1, e); end

#seventh(e) ⇒ Object


40
# File 'lib/cadenza/library/expectation.rb', line 40

def seventh(e); nth(6, e); end

#sixth(e) ⇒ Object


39
# File 'lib/cadenza/library/expectation.rb', line 39

def sixth(e);   nth(5, e); end

#tenth(e) ⇒ Object


43
# File 'lib/cadenza/library/expectation.rb', line 43

def tenth(e);   nth(9, e); end

#third(e) ⇒ Object


36
# File 'lib/cadenza/library/expectation.rb', line 36

def third(e);   nth(2, e); end