Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

#with and stubbing #123

Closed
Spaceghost opened this Issue Apr 1, 2012 · 13 comments

Comments

Projects
None yet
6 participants

Why do you need to implicitly stub the tested method when using #with?

it "strangely complains about 'undefined method `bar' for #<UndefinedMethodOddity'" do
  subject.should_receive(:bar).with(1)
  subject.foo
end

This fails and is documented, but I'd like to understand if this is a feature or a currently unaddressed issue. If it's intentional, is there a way to make it more obvious that it's because the method wasn't stubbed?

https://gist.github.com/2274040

As an aside, the issue number is 123 which leads me to believe that this feature is elementary.
I'm in the middle of trudging along through the internals and coming up with some options. Sorry for the terrible humor, it's April Fools' day. Not that this is a troll.

Oh, thanks for filing my issue for me, Space.

https://gist.github.com/2273953

Yours?! He found it! Well, after I told him about it. But I'd have never filed a report.

Oh, so he found it and then waited til I independently found it before filing an issue. And he cited my gist, just for the hell of it. Right.

@BrokenLadder I owe you a great apology for my behaviour. As such, @rubypanther found the answer. You need to mock the method.

Oh no, I found it after you left, but Mr.Panther found the actual issue you were having. I delved through the rspec source to locate the missing feature, so to speak. I'm working on a pull request for automagic stubbing.

Apology accepted. But what do you mean I need to mock the method. I know how to make the spec work. My complaint is that, this bug causes RSpec to give an unhelpful/incorrect message when I don't set the spec up properly.

Right, it was definitely a rather ridiculous communication breakdown on my part. I want to see what the ruling is on the issue, and then finish this up and pull request. Whether that means just adjusting the exception message, or add full automagic stubbing when using #with.

radar commented Apr 1, 2012

And now back to the task at hand:

It would seem here that when you use the with method it's undefining the method completely, rather than keeping the hook around and then erroring out when the method is called a second time.

/me hugs it out with Spaceghost

@radar Yeah, with Apeiros' and @rubypanther's help to find the original source file for the issue, we got it tacked down to that. What @rubypanther suggested was to handle methods that need a stub by checking if the method is stubbed and then creating a stub for it if it doesn't exist. That way it doesn't break API, and maybe it could move forward to not require the stub at all.

Contributor

justinko commented Apr 1, 2012

Thanks for reporting, gents.

@justinko - I can get a pull request in to do the above.

Contributor

justinko commented Apr 6, 2012

Great, please do!

@Bodhisattva2-0 Bodhisattva2-0 pushed a commit to c42engineering/rspec-mocks that referenced this issue Jun 4, 2012

Neha Kumari Issue #123: Improved error message when user forgets to stub a method…
… with default behavior.
409955f

@dchelimsky dchelimsky added a commit that referenced this issue Jun 4, 2012

@dchelimsky dchelimsky Merge pull request #147 from c42engineering/issue123
Issue #123: Improved error message when user forgets to stub a method with a default.
1ebc698
Contributor

alindeman commented Jun 10, 2012

This appears to have been addressed with #147. Closing, but if I'm wrong, feel free to reopen :)

@alindeman alindeman closed this Jun 10, 2012

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