RSpec::Mocks::Methods

Public Instance Methods

as_null_object() click to toggle source
# File lib/rspec/mocks/methods.rb, line 65
def as_null_object
  __mock_proxy.as_null_object
end
null_object?() click to toggle source
# File lib/rspec/mocks/methods.rb, line 69
def null_object?
  __mock_proxy.null_object?
end
should_not_receive(sym, &block) click to toggle source
# File lib/rspec/mocks/methods.rb, line 8
def should_not_receive(sym, &block)
  __mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block)
end
should_receive(sym, opts={}, &block) click to toggle source
# File lib/rspec/mocks/methods.rb, line 4
def should_receive(sym, opts={}, &block)
  __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block)
end
stub(sym_or_hash, opts={}, &block) click to toggle source
# File lib/rspec/mocks/methods.rb, line 12
def stub(sym_or_hash, opts={}, &block)
  if Hash === sym_or_hash
    sym_or_hash.each {|method, value| stub!(method).and_return value }
  else
    __mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts, &block)
  end
end
Also aliased as: stub!
stub!(sym_or_hash, opts={}, &block) click to toggle source
Alias for: stub
stub_chain("foo.bar") { :baz } click to toggle source
stub_chain(:foo, :bar) { :baz }

Stubs a chain of methods. Especially useful with fluent and/or composable interfaces.

Examples

Article.stub_chain("recent.published") { [Article.new] }
# File lib/rspec/mocks/methods.rb, line 37
def stub_chain(*chain, &blk)
  chain, blk = format_chain(*chain, &blk)
  if chain.length > 1
    if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym)
      chain.shift
      matching_stub.invoke.stub_chain(*chain, &blk)
    else
      next_in_chain = Object.new
      stub(chain.shift) { next_in_chain }
      next_in_chain.stub_chain(*chain, &blk)
    end
  else
    stub(chain.shift, &blk)
  end
end
unstub(sym) click to toggle source
# File lib/rspec/mocks/methods.rb, line 20
def unstub(sym)
  __mock_proxy.remove_stub(sym)
end
Also aliased as: unstub!
unstub!(sym) click to toggle source
Alias for: unstub

[Validate]

Generated with the Darkfish Rdoc Generator 2.