Module: Rogue::Support::MockMethods

Defined in:
lib/rogue/support/mock_methods.rb

Defined Under Namespace

Classes: MockContext

Instance Method Summary collapse

Instance Method Details

#expect_chained_call(mock, chain_call, ret_val, args = []) ⇒ Object

Chained method calls in the form of mock.first.second.third can be made on a mock with this auxillary method



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rogue/support/mock_methods.rb', line 8

def expect_chained_call(mock, chain_call, ret_val, args = [])
  calls = chain_call.split('.')
  calls[0, calls.length - 1].each do |each|
    mock.expect(each.to_sym, mock)
  end
  mock.expect(calls.last, ret_val, args) unless block_given?
  if block_given?
    mock.expect(calls.last, ret_val) do |*var_args|
      yield var_args
    end
  end
end

#with_new_mock(&block) ⇒ Object



34
35
36
# File 'lib/rogue/support/mock_methods.rb', line 34

def with_new_mock(&block)
  MockContext.new(block)
end