[rspec-devel] [ rspec-Bugs-8302 ] Strange side effect when mocking a class method

noreply at rubyforge.org noreply at rubyforge.org
Mon Jan 29 21:35:12 EST 2007


Bugs item #8302, was opened at 2007-01-30 02:35
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=8302&group_id=797

Category: mock module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Tobias Grimm (e-tobi)
Assigned to: Nobody (None)
Summary: Strange side effect when mocking a class method

Initial Comment:
Hi!

This one is really driving me mad:

    class Foo
        def Foo.bar(arg)
        end
    end

    context "Context" do
        specify "spec 1" do
            Foo.should_not_receive(:bar).with(Array.new)
        end

        specify "spec 2" do
            Foo.bar(Array.new)
        end
    end

Running these specs results in this failure:

    ArgumentError in 'Context 1 spec 1.2'
    wrong number of arguments (0 for 1)
    ./xxx_controller_spec.rb:14:in `bar'
    ./xxx_controller_spec.rb:14:in `bar'
    ./xxx_controller_spec.rb:12:

    Finished in 0.002342 seconds


If I comment out the mocking of bar() in spec 1 it works. If I pass a string instead of an empty array in spec 1.2 it works too. I also can add a default value for the arg parameter in bar() and it will work. But in the above constellation, it doesn't work.

Maybe there's something going wrong with the define_method() call in the MockHandler class, that puts the original method of the mocked class back in place. This might also be a Ruby bug - I'm not sure.

Any ideas?

bye,

Tobias


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=8302&group_id=797


More information about the rspec-devel mailing list