Module: RR::Adapters::RRMethods

Includes:
DoubleDefinitions::Strategies::StrategyMethods
Included in:
RR, MiniTest, RSpec2, Rspec, TestUnit
Defined in:
lib/rr/adapters/rr_methods.rb

Instance Method Summary collapse

Methods included from DoubleDefinitions::Strategies::StrategyMethods

#any_instance_of!, #dont_allow!, #instance_of!, #mock!, #proxy!, #strong!, #stub!

Instance Method Details

#any_instance_of(*args, &block) ⇒ Object



36
37
38
# File 'lib/rr/adapters/rr_methods.rb', line 36

def any_instance_of(*args, &block)
  RR::DoubleDefinitions::DoubleInjections::AnyInstanceOf.call(*args, &block)
end

#any_timesObject

Returns a AnyTimesMatcher. This is meant to be passed in as an argument to Double#times.

mock(object).method_name(anything).times(any_times) {return_value}


55
56
57
# File 'lib/rr/adapters/rr_methods.rb', line 55

def any_times
  TimesCalledMatchers::AnyTimesMatcher.new
end

#anythingObject

Sets up an Anything wildcard ArgumentEqualityExpectation that succeeds when passed any argument.

mock(object).method_name(anything) {return_value}
object.method_name("an arbitrary value") # passes


63
64
65
# File 'lib/rr/adapters/rr_methods.rb', line 63

def anything
  RR::WildcardMatchers::Anything.new
end

#booleanObject

Sets up an Boolean wildcard ArgumentEqualityExpectation that succeeds when passed an argument that is a ::Boolean.

mock(object).method_name(boolean) {return_value}
object.method_name(false) # passes


87
88
89
# File 'lib/rr/adapters/rr_methods.rb', line 87

def boolean
  RR::WildcardMatchers::Boolean.new
end

#dont_allow(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



16
17
18
19
# File 'lib/rr/adapters/rr_methods.rb', line 16

def dont_allow(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.dont_allow(subject, method_name, &definition_eval_block)
end

#duck_type(*args) ⇒ Object

Sets up a DuckType wildcard ArgumentEqualityExpectation that succeeds when the passed argument implements the methods.

arg = Object.new
def arg.foo; end
def arg.bar; end
mock(object).method_name(duck_type(:foo, :bar)) {return_value}
object.method_name(arg) # passes


98
99
100
# File 'lib/rr/adapters/rr_methods.rb', line 98

def duck_type(*args)
  RR::WildcardMatchers::DuckType.new(*args)
end

#hash_including(expected_hash) ⇒ Object

Sets up a HashIncluding wildcard ArgumentEqualityExpectation that succeeds when the passed argument contains at least those keys and values of the expectation.

mock(object).method_name(hash_including(:foo => 1)) {return_value}
object.method_name({:foo => 1, :bar => 2) # passes


107
108
109
# File 'lib/rr/adapters/rr_methods.rb', line 107

def hash_including(expected_hash)
  RR::WildcardMatchers::HashIncluding.new(expected_hash)
end

#instance_of(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



31
32
33
34
# File 'lib/rr/adapters/rr_methods.rb', line 31

def instance_of(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.instance_of(subject, method_name, &definition_eval_block)
end

#is_a(klass) ⇒ Object

Sets up an IsA wildcard ArgumentEqualityExpectation that succeeds when passed an argument of a certain type.

mock(object).method_name(is_a(String)) {return_value}
object.method_name("A String") # passes


71
72
73
# File 'lib/rr/adapters/rr_methods.rb', line 71

def is_a(klass)
  RR::WildcardMatchers::IsA.new(klass)
end

#mock(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



6
7
8
9
# File 'lib/rr/adapters/rr_methods.rb', line 6

def mock(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.mock(subject, method_name, &definition_eval_block)
end

#numericObject

Sets up an Numeric wildcard ArgumentEqualityExpectation that succeeds when passed an argument that is ::Numeric.

mock(object).method_name(numeric) {return_value}
object.method_name(99) # passes


79
80
81
# File 'lib/rr/adapters/rr_methods.rb', line 79

def numeric
  RR::WildcardMatchers::Numeric.new
end

#proxy(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



21
22
23
24
# File 'lib/rr/adapters/rr_methods.rb', line 21

def proxy(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.proxy(subject, method_name, &definition_eval_block)
end

#received(subject) ⇒ Object



129
130
131
# File 'lib/rr/adapters/rr_methods.rb', line 129

def received(subject)
  RR::SpyVerificationProxy.new(subject)
end

#resetObject

Resets the registered Doubles and ordered Doubles



47
48
49
# File 'lib/rr/adapters/rr_methods.rb', line 47

def reset
  RR::Space.instance.reset
end

#satisfy(expectation_proc = nil, &block) ⇒ Object

Sets up a Satisfy wildcard ArgumentEqualityExpectation that succeeds when the passed argument causes the expectation's proc to return true.

mock(object).method_name(satisfy {|arg| arg == :foo}) {return_value}
object.method_name(:foo) # passes


116
117
118
119
# File 'lib/rr/adapters/rr_methods.rb', line 116

def satisfy(expectation_proc=nil, &block)
  expectation_proc ||= block
  RR::WildcardMatchers::Satisfy.new(expectation_proc)
end

#spy(subject) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/rr/adapters/rr_methods.rb', line 121

def spy(subject)
  methods_to_stub = subject.public_methods.map {|method_name| method_name.to_sym} -
    [:methods, :==, :__send__, :__id__, :object_id, :class]
  methods_to_stub.each do |method|
    stub.proxy(subject, method)
  end
end

#strong(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



26
27
28
29
# File 'lib/rr/adapters/rr_methods.rb', line 26

def strong(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.strong(subject, method_name, &definition_eval_block)
end

#stub(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) ⇒ Object



11
12
13
14
# File 'lib/rr/adapters/rr_methods.rb', line 11

def stub(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
  double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
  double_definition_create.stub(subject, method_name, &definition_eval_block)
end

#verifyObject

Verifies all the DoubleInjection objects have met their TimesCalledExpectations.



42
43
44
# File 'lib/rr/adapters/rr_methods.rb', line 42

def verify
  RR::Space.instance.verify_doubles
end