Implements the methods needed for a pure test double. RSpec::Mocks::Double includes this module, and it is provided for cases where you want a pure test double without subclassing RSpec::Mocks::Double.
Creates a new test double with a `name` (that will be used in error messages only)
# File lib/rspec/mocks/test_double.rb, line 9 def initialize(name=nil, stubs={}) @__expired = false if Hash === name && stubs.empty? stubs = name @name = nil else @name = name end assign_stubs(stubs) end
This allows for comparing the mock to other objects that proxy such as ActiveRecords belongs_to proxy objects. By making the other object run the comparison, we’re sure the call gets delegated to the proxy target.
# File lib/rspec/mocks/test_double.rb, line 36 def ==(other) other == __mock_proxy end
@private
# File lib/rspec/mocks/test_double.rb, line 56 def __build_mock_proxy_unless_expired(order_group) __raise_expired_error or __build_mock_proxy(order_group) end
@private
# File lib/rspec/mocks/test_double.rb, line 61 def __disallow_further_usage! @__expired = true end
Tells the object to respond to all messages. If specific stub values are declared, they’ll work as expected. If not, the receiver is returned.
# File lib/rspec/mocks/test_double.rb, line 23 def as_null_object __mock_proxy.as_null_object end
Override for default freeze implementation to prevent freezing of test doubles.
# File lib/rspec/mocks/test_double.rb, line 67 def freeze RSpec.warn_with("WARNING: you attempted to freeze a test double. This is explicitly a no-op as freezing doubles can lead to undesired behaviour when resetting tests.") end
@private
# File lib/rspec/mocks/test_double.rb, line 41 def inspect "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>" end
Returns true if this object has received `as_null_object`
# File lib/rspec/mocks/test_double.rb, line 28 def null_object? __mock_proxy.null_object? end
Generated with the Darkfish Rdoc Generator 2.