any_instance doesn't work with stub! alias #57

Closed
benedikt opened this Issue May 11, 2011 · 4 comments

4 participants

@benedikt

Defining stubs on any instance of an object doesn't work when using the stub! method. This scenario fails:

  Scenario: simple any_instance stub with a single return value using the stub! alias
    Given a file named "example_spec.rb" with:
      """
      describe "any_instance.stub!" do
        it "returns the specified value on any instance of the class" do
          Object.any_instance.stub!(:foo).and_return(:return_value)

          o = Object.new
          o.foo.should eq(:return_value)
        end
      end
      """
    When I run `rspec example_spec.rb`
    Then the examples should all pass
@dchelimsky
RSpec member

The stub! method is conceptually (but not formally) deprecated, and is only in place for backward compatibility. I haven't deprecated it with a formal warning yet (mostly to avoid noise - it exists in a lot of places), but this request makes me want to as I'd prefer not to see new code written using it. If I do add it, it would be with a deprecation warning, which seems like a silly thing to do.

Thoughts?

@benedikt

I think a warning would be a nice thing. At least when used with any_instance. It was just out of pure luck that I tried it without the bang. It's confusiong because the stub! method still works in any other case...

@lanej

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment