| Class | FlexMock |
| In: |
vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb
|
| Parent: | Object |
Class method to make sure that verify is called at the end of a test.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 78
78: def self.use
79: mock = new
80: yield mock
81: ensure
82: mock.mock_verify
83: end
Handle missing methods by attempting to look up a handler.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 66
66: def method_missing(sym, *args, &block)
67: if handler = @handlers[sym]
68: @counts[sym] += 1
69: args << block if block_given?
70: handler.call(*args)
71: else
72: super(sym, *args, &block) unless @ignore_missing
73: end
74: end
Report how many times a method was called.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 56
56: def mock_count(sym)
57: @counts[sym]
58: end
Handle all messages denoted by sym by calling the given block and passing any parameters to the block. If we know exactly how many calls are to be made to a particular method, we may check that by passing in the number of expected calls as a second paramter.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 36
36: def mock_handle(sym, expected_count=nil, &block)
37: if block_given?
38: @handlers[sym] = block
39: else
40: @handlers[sym] = proc { }
41: end
42: @expected_counts[sym] = expected_count if expected_count
43: end
Ignore all undefined (missing) method calls.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 61
61: def mock_ignore_missing
62: @ignore_missing = true
63: end
Verify that each method that had an explicit expected count was actually called that many times.
# File vendor/rails/activesupport/lib/active_support/vendor/flexmock.rb, line 47
47: def mock_verify
48: @expected_counts.keys.each do |key|
49: assert_equal @expected_counts[key], @counts[key],
50: "Expected method #{key} to be called #{@expected_counts[key]} times, " +
51: "got #{@counts[key]}"
52: end
53: end