Sha256: 9d9e0ed14ed45e64440b1de8e182fb34cf7f0ba63f13fdc0c0d5f87ef3f2ae76
Contents?: true
Size: 1.4 KB
Versions: 61
Compression:
Stored size: 1.4 KB
Contents
require 'mocha/parameter_matchers/base' require 'yaml' module Mocha module ParameterMatchers # Matches any YAML that represents the specified +object+ # # @param [Object] object object whose YAML to compare. # @return [YamlEquivalent] parameter matcher. # # @see Expectation#with # # @example Actual parameter is YAML equivalent of specified +object+. # object = mock() # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) # object.method_1("--- \n- 1\n- 2\n- 3\n") # # no error raised # # @example Actual parameter is not YAML equivalent of specified +object+. # object = mock() # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) # object.method_1("--- \n- 1\n- 2\n") # # error raised, because method_1 was not called with YAML representing the specified Array def yaml_equivalent(object) YamlEquivalent.new(object) end # Parameter matcher which matches if actual parameter is YAML equivalent of specified object. class YamlEquivalent < Base # @private def initialize(object) @object = object end # @private def matches?(available_parameters) parameter = available_parameters.shift @object == YAML.load(parameter) end # @private def mocha_inspect "yaml_equivalent(#{@object.mocha_inspect})" end end end end
Version data entries
61 entries across 50 versions & 5 rubygems