Class: Orangutan::Expectation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpectation

Returns a new instance of Expectation.



8
9
10
11
12
# File 'lib/orangutan/expectation.rb', line 8

def initialize
  @return_container = nil
  @yield_container = nil
  @raiser = nil
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



6
7
8
# File 'lib/orangutan/expectation.rb', line 6

def count
  @count
end

#raiserObject (readonly)

Returns the value of attribute raiser.



6
7
8
# File 'lib/orangutan/expectation.rb', line 6

def raiser
  @raiser
end

#return_containerObject (readonly)

Returns the value of attribute return_container.



6
7
8
# File 'lib/orangutan/expectation.rb', line 6

def return_container
  @return_container
end

#yield_containerObject (readonly)

Returns the value of attribute yield_container.



6
7
8
# File 'lib/orangutan/expectation.rb', line 6

def yield_container
  @yield_container
end

Instance Method Details

#exactly(count) ⇒ Object



51
52
53
54
# File 'lib/orangutan/expectation.rb', line 51

def exactly count
  @limit = count
  self
end

#matched?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/orangutan/expectation.rb', line 68

def matched?
  if @limit
    @count && @count >= @limit
  else
    @count
  end 
end

#matches?(method, *args) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
# File 'lib/orangutan/expectation.rb', line 40

def matches? method, *args
  return false unless method == @method
  matched = @args ? @args == args : true
  return false if @limit && @count && @count >= @limit
  if matched
    @count ||= 0
    @count += 1
  end
  matched
end

#onceObject



56
57
58
# File 'lib/orangutan/expectation.rb', line 56

def once
  exactly 1
end

#raise(*args) ⇒ Object



35
36
37
38
# File 'lib/orangutan/expectation.rb', line 35

def raise *args
  @raiser = Raiser.new args
  self
end

#receives(method) ⇒ Object



14
15
16
17
# File 'lib/orangutan/expectation.rb', line 14

def receives method
  @method = method
  self
end

#return(*value) ⇒ Object



24
25
26
27
# File 'lib/orangutan/expectation.rb', line 24

def return *value
  @return_container = Container.new value
  self
end

#timesObject



64
65
66
# File 'lib/orangutan/expectation.rb', line 64

def times
  self
end

#twiceObject



60
61
62
# File 'lib/orangutan/expectation.rb', line 60

def twice
  exactly 2
end

#with(*args) ⇒ Object



19
20
21
22
# File 'lib/orangutan/expectation.rb', line 19

def with *args
  @args = args
  self
end

#yield(*value) ⇒ Object



29
30
31
32
33
# File 'lib/orangutan/expectation.rb', line 29

def yield *value
  @yield_container ||= Container.new([])
  @yield_container.value << value
  self
end