# File lib/mocha/mockery.rb, line 158 158: def logger 159: @logger ||= Logger.new($stderr) 160: end
# File lib/mocha/mockery.rb, line 81 81: def mocha_inspect 82: message = "" 83: message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty? 84: message << "satisfied expectations:\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty? 85: message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty? 86: message 87: end
# File lib/mocha/mockery.rb, line 33 33: def mock_impersonating(object, &block) 34: add_mock(Mock.new(self, ImpersonatingName.new(object), &block)) 35: end
# File lib/mocha/mockery.rb, line 37 37: def mock_impersonating_any_instance_of(klass, &block) 38: add_mock(Mock.new(self, ImpersonatingAnyInstanceName.new(klass), &block)) 39: end
# File lib/mocha/mockery.rb, line 73 73: def mocks 74: @mocks ||= [] 75: end
# File lib/mocha/mockery.rb, line 25 25: def named_mock(name, &block) 26: add_mock(Mock.new(self, Name.new(name), &block)) 27: end
# File lib/mocha/mockery.rb, line 41 41: def new_state_machine(name) 42: add_state_machine(StateMachine.new(name)) 43: end
# File lib/mocha/mockery.rb, line 89 89: def on_stubbing(object, method) 90: method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym 91: unless Mocha::Configuration.allow?(:stubbing_non_existent_method) 92: unless object.method_exists?(method, include_public_methods = true) 93: on_stubbing_non_existent_method(object, method) 94: end 95: end 96: unless Mocha::Configuration.allow?(:stubbing_non_public_method) 97: if object.method_exists?(method, include_public_methods = false) 98: on_stubbing_non_public_method(object, method) 99: end 100: end 101: unless Mocha::Configuration.allow?(:stubbing_method_on_nil) 102: if object.nil? 103: on_stubbing_method_on_nil(object, method) 104: end 105: end 106: unless Mocha::Configuration.allow?(:stubbing_method_on_non_mock_object) 107: on_stubbing_method_on_non_mock_object(object, method) 108: end 109: end
# File lib/mocha/mockery.rb, line 129 129: def on_stubbing_method_on_nil(object, method) 130: if Mocha::Configuration.prevent?(:stubbing_method_on_nil) 131: raise StubbingError.new("stubbing method on nil: #{object.mocha_inspect}.#{method}", caller) 132: end 133: if Mocha::Configuration.warn_when?(:stubbing_method_on_nil) 134: logger.warn "stubbing method on nil: #{object.mocha_inspect}.#{method}" 135: end 136: end
# File lib/mocha/mockery.rb, line 138 138: def on_stubbing_method_on_non_mock_object(object, method) 139: if Mocha::Configuration.prevent?(:stubbing_method_on_non_mock_object) 140: raise StubbingError.new("stubbing method on non-mock object: #{object.mocha_inspect}.#{method}", caller) 141: end 142: if Mocha::Configuration.warn_when?(:stubbing_method_on_non_mock_object) 143: logger.warn "stubbing method on non-mock object: #{object.mocha_inspect}.#{method}" 144: end 145: end
# File lib/mocha/mockery.rb, line 147 147: def on_stubbing_method_unnecessarily(expectation) 148: if Mocha::Configuration.prevent?(:stubbing_method_unnecessarily) 149: raise StubbingError.new("stubbing method unnecessarily: #{expectation.method_signature}", expectation.backtrace) 150: end 151: if Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily) 152: logger.warn "stubbing method unnecessarily: #{expectation.method_signature}" 153: end 154: end
# File lib/mocha/mockery.rb, line 111 111: def on_stubbing_non_existent_method(object, method) 112: if Mocha::Configuration.prevent?(:stubbing_non_existent_method) 113: raise StubbingError.new("stubbing non-existent method: #{object.mocha_inspect}.#{method}", caller) 114: end 115: if Mocha::Configuration.warn_when?(:stubbing_non_existent_method) 116: logger.warn "stubbing non-existent method: #{object.mocha_inspect}.#{method}" 117: end 118: end
# File lib/mocha/mockery.rb, line 120 120: def on_stubbing_non_public_method(object, method) 121: if Mocha::Configuration.prevent?(:stubbing_non_public_method) 122: raise StubbingError.new("stubbing non-public method: #{object.mocha_inspect}.#{method}", caller) 123: end 124: if Mocha::Configuration.warn_when?(:stubbing_non_public_method) 125: logger.warn "stubbing non-public method: #{object.mocha_inspect}.#{method}" 126: end 127: end
# File lib/mocha/mockery.rb, line 77 77: def state_machines 78: @state_machines ||= [] 79: end
# File lib/mocha/mockery.rb, line 69 69: def stubba 70: @stubba ||= Central.new 71: end
# File lib/mocha/mockery.rb, line 64 64: def teardown 65: stubba.unstub_all 66: reset 67: end
# File lib/mocha/mockery.rb, line 29 29: def unnamed_mock(&block) 30: add_mock(Mock.new(self, &block)) 31: end
# File lib/mocha/mockery.rb, line 45 45: def verify(assertion_counter = nil) 46: unless mocks.all? { |mock| mock.__verified__?(assertion_counter) } 47: message = "not all expectations were satisfied\n#{mocha_inspect}" 48: if unsatisfied_expectations.empty? 49: backtrace = caller 50: else 51: backtrace = unsatisfied_expectations[0].backtrace 52: end 53: raise ExpectationError.new(message, backtrace) 54: end 55: expectations.each do |e| 56: unless Mocha::Configuration.allow?(:stubbing_method_unnecessarily) 57: unless e.used? 58: on_stubbing_method_unnecessarily(e) 59: end 60: end 61: end 62: end
# File lib/mocha/mockery.rb, line 177 177: def add_mock(mock) 178: mocks << mock 179: mock 180: end
# File lib/mocha/mockery.rb, line 182 182: def add_state_machine(state_machine) 183: state_machines << state_machine 184: state_machine 185: end
# File lib/mocha/mockery.rb, line 165 165: def expectations 166: mocks.map { |mock| mock.__expectations__.to_a }.flatten 167: end
# File lib/mocha/mockery.rb, line 187 187: def reset 188: @stubba = nil 189: @mocks = nil 190: @state_machines = nil 191: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.