Module: RR::Adapters::RRMethods

Includes:
DoubleDefinitions::Strategies::StrategyMethods
Included in:
RR, MiniTest, 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

- (Object) any_times

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}


52
53
54
# File 'lib/rr/adapters/rr_methods.rb', line 52

def any_times
  TimesCalledMatchers::AnyTimesMatcher.new
end

- (Object) anything

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


60
61
62
# File 'lib/rr/adapters/rr_methods.rb', line 60

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

- (Object) boolean

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


84
85
86
# File 'lib/rr/adapters/rr_methods.rb', line 84

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

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



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

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

- (Object) duck_type(*args)

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


95
96
97
# File 'lib/rr/adapters/rr_methods.rb', line 95

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

- (Object) hash_including(expected_hash)

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


104
105
106
# File 'lib/rr/adapters/rr_methods.rb', line 104

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

- (Object) instance_of(subject = DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name = nil, &definition_eval_block) Also known as: any_instance_of, all_instances_of



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

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

- (Object) is_a(klass)

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


68
69
70
# File 'lib/rr/adapters/rr_methods.rb', line 68

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

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



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

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

- (Object) new_instance_of(*args, &block)



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

def new_instance_of(*args, &block)
  RR::DoubleDefinitions::DoubleInjections::NewInstanceOf.call(*args, &block)
end

- (Object) numeric

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


76
77
78
# File 'lib/rr/adapters/rr_methods.rb', line 76

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

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



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

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

- (Object) received(subject)



126
127
128
# File 'lib/rr/adapters/rr_methods.rb', line 126

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

- (Object) reset

Resets the registered Doubles and ordered Doubles



44
45
46
# File 'lib/rr/adapters/rr_methods.rb', line 44

def reset
  RR::Space.instance.reset
end

- (Object) satisfy(expectation_proc = nil, &block)

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


113
114
115
116
# File 'lib/rr/adapters/rr_methods.rb', line 113

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

- (Object) spy(subject)



118
119
120
121
122
123
124
# File 'lib/rr/adapters/rr_methods.rb', line 118

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

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



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

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

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



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

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

- (Object) verify

Verifies all the DoubleInjection objects have met their TimesCalledExpectations.



39
40
41
# File 'lib/rr/adapters/rr_methods.rb', line 39

def verify
  RR::Space.instance.verify_doubles
end