Class Index [+]

Quicksearch

Spec::Mocks::Methods

Public Instance Methods

as_null_object() click to toggle source

Record and otherwise ignore all messages that aren’t specified, with stub, stub!, or should_receive.

Returns

  self
    # File lib/spec/mocks/methods.rb, line 63
63:       def as_null_object
64:         __mock_proxy.as_null_object
65:       end
null_object?() click to toggle source
    # File lib/spec/mocks/methods.rb, line 67
67:       def null_object?
68:         __mock_proxy.null_object?
69:       end
should_not_receive(sym, &block) click to toggle source
    # File lib/spec/mocks/methods.rb, line 8
 8:       def should_not_receive(sym, &block)
 9:         __mock_proxy.add_negative_message_expectation(caller(1)[0], sym.to_sym, &block)
10:       end
should_receive(sym, opts={}, &block) click to toggle source
   # File lib/spec/mocks/methods.rb, line 4
4:       def should_receive(sym, opts={}, &block)
5:         __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], sym.to_sym, opts, &block)
6:       end
stub(sym_or_hash, opts={}, &block) click to toggle source
Alias for: stub!
stub!(sym_or_hash, opts={}, &block) click to toggle source
    # File lib/spec/mocks/methods.rb, line 12
12:       def stub!(sym_or_hash, opts={}, &block)
13:         if Hash === sym_or_hash
14:           sym_or_hash.each {|method, value| stub!(method).and_return value }
15:         else
16:           __mock_proxy.add_stub(caller(1)[0], sym_or_hash.to_sym, opts, &block)
17:         end
18:       end
Also aliased as: stub
and_return(:this) click to toggle source

Supports stubbing a chain of methods. Each argument represents a method name to stub, and each one returns a proxy object that can accept more stubs, until the last, which returns whatever is passed to +and_return_.

Examples

  
  # with this in an example ...
  article = double('article')
  Article.stub_chain(:authored_by, :published, :recent).and_return([article])
  # then this will return an Array with the article double in it:
  Article.authored_by(params[:author_id]).published.recent
    # File lib/spec/mocks/methods.rb, line 43
43:       def stub_chain(*methods)
44:         if methods.length > 1
45:           if matching_stub = __mock_proxy.find_matching_method_stub(methods[0])
46:             methods.shift
47:             matching_stub.invoke_return_block.stub_chain(*methods)
48:           else
49:             next_in_chain = Object.new
50:             stub!(methods.shift) {next_in_chain}
51:             next_in_chain.stub_chain(*methods)
52:           end
53:         else
54:           stub!(methods.shift)
55:         end
56:       end
unstub(message) click to toggle source
Alias for: unstub!
unstub!(message) click to toggle source
    # File lib/spec/mocks/methods.rb, line 22
22:       def unstub!(message)
23:         __mock_proxy.remove_stub(message)
24:       end
Also aliased as: unstub

Private Instance Methods

__mock_proxy() click to toggle source
    # File lib/spec/mocks/methods.rb, line 85
85:       def __mock_proxy
86:         if Mock === self
87:           @mock_proxy ||= Proxy.new(self, @name, @options)
88:         else
89:           @mock_proxy ||= Proxy.new(self)
90:         end
91:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.