diff --git a/benchmarks/rr_benchmark.rb b/benchmarks/rr_benchmark.rb new file mode 100644 index 00000000..3fa9e1be --- /dev/null +++ b/benchmarks/rr_benchmark.rb @@ -0,0 +1,32 @@ +dir = File.dirname(__FILE__) +require File.expand_path("#{dir}/../lib/rr") +require "benchmark" + +o = Object.new + +Benchmark.bm do |x| + x.report do + 1000.times do + RR.mock(o).foobar.returns("baz") + o.foobar + RR.reset + end + end +end + +#require "ruby-prof" +#RubyProf.start +# +##RR.mock(o).foobar.returns("baz") +##o.foobar +#250.times do +# RR.mock(o).foobar.returns("baz") +# o.foobar +# RR.reset +#end +# +#result = RubyProf.stop +# +## Print a flat profile to text +#printer = RubyProf::FlatPrinter.new(result) +#printer.print(STDOUT, 0) \ No newline at end of file diff --git a/benchmarks/rspec_benchmark.rb b/benchmarks/rspec_benchmark.rb new file mode 100644 index 00000000..65c54eb3 --- /dev/null +++ b/benchmarks/rspec_benchmark.rb @@ -0,0 +1,14 @@ +require "rubygems" +require "spec/mocks" +require "benchmark" + +o = Object.new + +Benchmark.bm do |x| + x.report do + 1000.times do + o.should_receive(:foobar).and_return("baz") + o.foobar + end + end +end diff --git a/lib/rr/double_definitions/double_definition_creator_proxy.rb b/lib/rr/double_definitions/double_definition_creator_proxy.rb index d7eb365d..613c1286 100644 --- a/lib/rr/double_definitions/double_definition_creator_proxy.rb +++ b/lib/rr/double_definitions/double_definition_creator_proxy.rb @@ -1,6 +1,17 @@ module RR module DoubleDefinitions class DoubleDefinitionCreatorProxy + class << self + def blank_slate_methods + instance_methods.each do |m| + unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == "instance_eval" || m.to_s == 'respond_to?' + alias_method "__blank_slated_#{m}", m + undef_method m + end + end + end + end + def initialize(creator, &block) #:nodoc: @creator = creator class << self @@ -12,12 +23,7 @@ def __apply_blank_slate? @apply_blank_slate ||= false end - instance_methods.each do |m| - unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == "instance_eval" || m.to_s == 'respond_to?' - alias_method "__blank_slated_#{m}", m - undef_method m - end - end + blank_slate_methods def instance_eval return_value = super diff --git a/lib/rr/expectations/argument_equality_expectation.rb b/lib/rr/expectations/argument_equality_expectation.rb index 5fc8a67d..8820c89c 100644 --- a/lib/rr/expectations/argument_equality_expectation.rb +++ b/lib/rr/expectations/argument_equality_expectation.rb @@ -8,17 +8,17 @@ def initialize(*expected_arguments) end def exact_match?(*arguments) - return false unless arguments.length == @expected_arguments.length + return false unless arguments.length == expected_arguments.length arguments.each_with_index do |arg, index| - return false unless equality_match(@expected_arguments[index], arg) + return false unless equality_match(expected_arguments[index], arg) end true end def wildcard_match?(*arguments) - return false unless arguments.length == @expected_arguments.length + return false unless arguments.length == expected_arguments.length arguments.each_with_index do |arg, index| - expected_argument = @expected_arguments[index] + expected_argument = expected_arguments[index] if expected_argument.respond_to?(:wildcard_match?) return false unless expected_argument.wildcard_match?(arg) else @@ -29,7 +29,7 @@ def wildcard_match?(*arguments) end def ==(other) - @expected_arguments == other.expected_arguments + expected_arguments == other.expected_arguments end protected