Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#with and stubbing #123

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

#with and stubbing #123

Spaceghost opened this issue Apr 1, 2012 · 13 comments

Comments

@Spaceghost
Copy link

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.

@ClayShentrup
Copy link

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

https://gist.github.com/2273953

@rubypanther
Copy link

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

@ClayShentrup
Copy link

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.

@Spaceghost
Copy link
Author

@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.

@ClayShentrup
Copy link

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.

@Spaceghost
Copy link
Author

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
Copy link

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.

@ClayShentrup
Copy link

/me hugs it out with Spaceghost

@Spaceghost
Copy link
Author

@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.

@justinko
Copy link
Contributor

justinko commented Apr 1, 2012

Thanks for reporting, gents.

@Spaceghost
Copy link
Author

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

@justinko
Copy link
Contributor

justinko commented Apr 6, 2012

Great, please do!

Bodhisattva2-0 pushed a commit to c42engineering/rspec-mocks that referenced this issue Jun 4, 2012
dchelimsky added a commit that referenced this issue Jun 4, 2012
Issue #123: Improved error message when user forgets to stub a method with a default.
dchelimsky added a commit that referenced this issue Jun 4, 2012
@alindeman
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants