Sha256: e3728ce9c6e47a9d19ddc738ddc9f175f0b9d0aa0bc270284d181e69c27247cc
Contents?: true
Size: 1.39 KB
Versions: 5
Compression:
Stored size: 1.39 KB
Contents
require 'mocha/expectation' module Mocha module MockMethods def expectations @expectations ||= [] end def expects(symbol) expectations << Expectation.new(symbol) expectations.last end def stubs(symbol) expectations << Stub.new(symbol) expectations.last end def method_missing(symbol, *arguments, &block) matching_expectation = matching_expectation(symbol, *arguments) if matching_expectation then matching_expectation.invoke else begin super_method_missing(symbol, *arguments, &block) rescue NoMethodError unexpected_method_called(symbol, *arguments) end end end def super_method_missing(symbol, *arguments, &block) raise NoMethodError end def unexpected_method_called(symbol, *arguments) MissingExpectation.new(symbol, expectations).with(*arguments).verify end def matching_expectation(symbol, *arguments) expectations.detect { |expectation| expectation.match?(symbol, *arguments) } end def expectations_matching(method_names) expectations.select { |expectation| method_names.include?(expectation.method_name) } end def verify(*method_names) for_verification = method_names.empty? ? expectations : expectations_matching(method_names) for_verification.each { |expectation| expectation.verify } end end end
Version data entries
5 entries across 5 versions & 1 rubygems