module Mocks::DSL::Methods
Overview
Common DSL methods for defining mocks, doubles, and stubs. This module should be included wherever necessary to specify DSL methods.
Defined in:
mocks/dsl/methods.crMacro Summary
- double(name, *stubs, **named_stubs, &block)
- mock(type, **stubs, &block)
- mock!(type, **stubs, &block)
Instance Method Summary
-
#anything
Returns an object that returns true when compared to anything.
-
#new_double(name = nil, **values) : LazyDouble
Creates a new lazy double.
-
#receive(method : Symbol)
Constructs a stub for a method.
-
#receive(method : Symbol, &block : -> _)
Constructs a stub for a method.
-
#receive(**value_stubs)
Constructs multiple method stubs for an object.
Macro Detail
Instance Method Detail
Creates a new lazy double.
The double returned by this method will respond to methods with the values specified in values. An optional name can be given to the double to help with debugging.
double = new_double(:test_double, test_method: 42)
double.test_method # => 42
Constructs a stub for a method.
The method is the name of the method to stub.
This is also the start of a fluent interface for defining stubs.
See: StubModifiers
Can syntax:
dbl.can receive(:some_method)
dbl.can receive(:the_answer).and_return(42)
Allow syntax:
allow(dbl).to receive(:some_method)
allow(dbl).to receive(:the_answer).and_return(42)
Constructs a stub for a method.
The method is the name of the method to stub. The provided block is invoked when the stubbed method is called.
Can syntax:
dbl.can receive(:the_answer) { 42 }
Allow syntax:
allow(dbl).to receive(:the_answer) { 42 }
Constructs multiple method stubs for an object.
A collection of key-value pairs is used. Each key is a method's name. The value is what is returned by the corresponding method.
Can syntax:
dbl.can receive(the_answer: 42, some_method: "foobar")
Allow syntax:
allow(dbl).to receive(the_answer: 42, some_method: "foobar")