Module: RR::Extensions::DoubleMethods

Included in:
Adapters::Rspec, Adapters::TestUnit
Defined in:
lib/rr/extensions/double_methods.rb

Instance Method Summary collapse

Instance Method Details

#anythingObject

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

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


37
38
39
# File 'lib/rr/extensions/double_methods.rb', line 37

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

#booleanObject

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

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


61
62
63
# File 'lib/rr/extensions/double_methods.rb', line 61

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

#do_not_allow(subject, &definition) ⇒ Object Also known as: dont_allow

Sets up a DoNotAllowCreator that generates a Double Scenario that expects never to be called.

do_not_allow(object).method_name


28
29
30
# File 'lib/rr/extensions/double_methods.rb', line 28

def do_not_allow(subject, &definition)
  RR::Space.instance.create_do_not_allow_creator(subject, &definition)
end

#duck_type(*args) ⇒ Object

Sets up a DuckType wildcard ArgumentEqualityError that succeeds when passed the 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


72
73
74
# File 'lib/rr/extensions/double_methods.rb', line 72

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

#is_a(klass) ⇒ Object

Sets up an IsA wildcard ArgumentEqualityError 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


45
46
47
# File 'lib/rr/extensions/double_methods.rb', line 45

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

#mock(subject, &definition) ⇒ Object

Sets up a MockCreator that generates a Double Scenario that acts like a mock.

mock(object).method_name(arg1, arg2) {return_value}


7
8
9
# File 'lib/rr/extensions/double_methods.rb', line 7

def mock(subject, &definition)
  RR::Space.instance.create_mock_creator(subject, &definition)
end

#numericObject

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

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


53
54
55
# File 'lib/rr/extensions/double_methods.rb', line 53

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

#probe(subject, &definition) ⇒ Object

Sets up a ProbeCreator that generates a Double Scenario that acts like a probe.

probe(controller.template).render(:partial => "my/socks")


21
22
23
# File 'lib/rr/extensions/double_methods.rb', line 21

def probe(subject, &definition)
  RR::Space.instance.create_probe_creator(subject, &definition)
end

#stub(subject, &definition) ⇒ Object

Sets up a StubCreator that generates a Double Scenario that acts like a stub.

stub(object).method_name {return_value}


14
15
16
# File 'lib/rr/extensions/double_methods.rb', line 14

def stub(subject, &definition)
  RR::Space.instance.create_stub_creator(subject, &definition)
end