Class: MiniSpec::Mocks::Expectations

Inherits:
Object
  • Object
show all
Defined in:
lib/minispec/mocks/expectations.rb

Instance Method Summary collapse

Constructor Details

#initialize(base, object, context, *args) ⇒ Expectations

Returns a new instance of Expectations.



5
6
7
8
# File 'lib/minispec/mocks/expectations.rb', line 5

def initialize base, object, context, *args
  @base, @object, @context, @args = base, object, context, args
  @expectations = []
end

Instance Method Details

#and_raise(*args, &proc) ⇒ Object



41
42
43
# File 'lib/minispec/mocks/expectations.rb', line 41

def and_raise *args, &proc
  push {|v| v.and_raise(*args, &proc)}
end

#and_return(*args, &proc) ⇒ Object Also known as: and_returned



28
29
30
# File 'lib/minispec/mocks/expectations.rb', line 28

def and_return *args, &proc
  push {|v| proc ? v.and_return(&proc) : v.and_return(*args)}
end

#and_throw(*args, &proc) ⇒ Object



49
50
51
# File 'lib/minispec/mocks/expectations.rb', line 49

def and_throw *args, &proc
  push {|v| v.and_throw(*args, &proc)}
end

#and_yield(*args, &proc) ⇒ Object



33
34
35
# File 'lib/minispec/mocks/expectations.rb', line 33

def and_yield *args, &proc
  push {|v| proc ? v.and_yield(&proc) : v.and_yield(*args)}
end

#count(*expected, &proc) ⇒ Object Also known as: times



57
58
59
# File 'lib/minispec/mocks/expectations.rb', line 57

def count *expected, &proc
  push {|v| proc ? v.count(&proc) : v.count(*expected)}
end

#onceObject



62
# File 'lib/minispec/mocks/expectations.rb', line 62

def once;  count(1); end

#ordered(n = 1) ⇒ Object



65
66
67
# File 'lib/minispec/mocks/expectations.rb', line 65

def ordered n = 1
  push {|v| v.ordered(n)}
end

#twiceObject



63
# File 'lib/minispec/mocks/expectations.rb', line 63

def twice; count(2); end

#validate!Object



10
11
12
13
# File 'lib/minispec/mocks/expectations.rb', line 10

def validate!
  validator = Validations.new(@base, @object, @context, *@args)
  @expectations.each {|e| e.call(validator)}
end

#with(*args, &proc) ⇒ Object



15
16
17
# File 'lib/minispec/mocks/expectations.rb', line 15

def with *args, &proc
  push {|v| proc ? v.with(&proc) : v.with(*args)}
end

#with_caller(*args, &proc) ⇒ Object



24
25
26
# File 'lib/minispec/mocks/expectations.rb', line 24

def with_caller *args, &proc
  push {|v| proc ? v.with_caller(&proc) : v.with_caller(*args)}
end

#without_argumentsObject Also known as: without_any_arguments



19
20
21
# File 'lib/minispec/mocks/expectations.rb', line 19

def without_arguments
  push {|v| v.without_arguments}
end

#without_raiseObject



45
46
47
# File 'lib/minispec/mocks/expectations.rb', line 45

def without_raise
  push {|v| v.without_raise}
end

#without_throwObject



53
54
55
# File 'lib/minispec/mocks/expectations.rb', line 53

def without_throw
  push {|v| v.without_throw}
end

#without_yieldObject



37
38
39
# File 'lib/minispec/mocks/expectations.rb', line 37

def without_yield
  push {|v| v.without_yield}
end