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

Mocking HTTP requests #18

Open
andreareginato opened this issue Oct 3, 2012 · 23 comments
Open

Mocking HTTP requests #18

andreareginato opened this issue Oct 3, 2012 · 23 comments
Labels

Comments

@andreareginato
Copy link
Collaborator

Write your thoughts about the "mocking HTTP requests " best practice.

@mattvanhorn
Copy link

VCR is a nice library for both mocking the request, and occasionally sanity-checking the API.
Docs are here

@marnen
Copy link

marnen commented Oct 3, 2012

I wrote a brief presentation on testing with Webmock and VCR; it's at http://marnen.github.com/webmock-presentation/webmock.html . Feel free to include a link if it's useful.

@pawel2105
Copy link

Any suggestions for Rails 2 apps?

@marnen
Copy link

marnen commented Oct 4, 2012

@pawel2105 I've used Webmock and FakeWeb with Rails 2.

@dchelimsky
Copy link

I'd recommend changing the name of the topic to "stubbing HTTP requests" since what you're describing is stubbing (defining controlled responses to messages), not mocking (expecting that messages are received and failing when they are not).

@marnen
Copy link

marnen commented Oct 6, 2012

@dchelimsky The terminology is kind of unfortunate. "Mock object" really should have meant any test double, IMHO, but the term got appropriated for one particular type. You're right that a lot of HTTP mocking is more like stubbing.

However...as I think about it, I realize that WebMock may be more like a true mock. If you use record_mode :once (which I always do), then the test fails if a request is made that's not in the cassette. At that point the WebMock cassette really starts to behave like a self-verifying mock object in the Martin Fowler sense, or so it seems to me.

None of this really has any bearing on the test practice itself. But the argument is interesting. :)

@andreareginato
Copy link
Collaborator Author

@dchelimsky I agree with the change on the strict meaning of stub and mock.
I'll also add the VCR link about site and presentation. Thanks for sharing.

@makaroni4
Copy link

@andreareginato fix topic name: #43

@andreareginato
Copy link
Collaborator Author

Thanks a lot. I'll take a day off to merge all needed changes, so keep little patience.

@makaroni4
Copy link

You are welcome)

@andreareginato what do you think of http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax? I think we should add this to betterspecs.

@pepe
Copy link

pepe commented Nov 26, 2012

@makaroni4 👍 for expect

@andreareginato
Copy link
Collaborator Author

The pull request is on master. I've updated Mocking to Stubbing.
@makaroni4 As far as the new expectation syntax will be used more and more I would love a pull request for it.

Any correction and comment to the updated guideline is appreciated.

@passion8
Copy link

passion8 commented Apr 7, 2013

I think you should also change the description from "Sometimes you need to access external services. In these cases you can't rely on the real service but you should mock it with solutions like webmock." to "Sometimes you need to access external services. In these cases you can't rely on the real service but you should stub it with solutions like webmock."

@andreareginato
Copy link
Collaborator Author

@Passionate, you are right. Send me a pull request and I'll merge the docs.

@passion8
Copy link

passion8 commented Apr 8, 2013

@andreareginato , sent .

@onebree
Copy link
Contributor

onebree commented Mar 16, 2015

This page needs to be updated. Webmock is no longer maintained for RSpec 3, as per their README. As a suggestion, how about using RSpec's Mocks library? I am not familiar with it myself enough to write example code for it, though

@marnen
Copy link

marnen commented Mar 16, 2015

@onebree Apparently Webmock does work with RSpec 3: see the resolved issue at bblimke/webmock#396. I haven't tried it myself yet, though.

I'd be surprised if it weren't compatible with RSpec 3, given that that's what Webmock's own tests use. :)

@onebree
Copy link
Contributor

onebree commented Mar 16, 2015

I am using RSpec 3.1. At this point, I am just going to use the RSpec Mocks library that RSpec provides. I am also not comfortable using a gem that seems to not be maintained anymore... Given their badges that say failed build and out-of-date dependencies

@andreareginato
Copy link
Collaborator Author

Right now I'm working on different project and would be great if you could
send us a pull request solving the issue, where we can discuss the use the
RSpec mock library together with the changed code examples.

Thanks a lot Hunter.

On Mon, Mar 16, 2015 at 6:12 PM, Hunter Stevens notifications@github.com
wrote:

I am using RSpec 3.1. At this point, I am just going to use the RSpec
Mocks library that RSpec provides. I am also not comfortable using a gem
that seems to not be maintained anymore... Given their badges that say
failed build and out-of-date dependencies


Reply to this email directly or view it on GitHub
#18 (comment)
.

Andrea Reginato
Lelylan | reThink your house
http://lelylan.com

@marnen
Copy link

marnen commented Mar 16, 2015

@onebree Where do you get the impression that Webmock isn't maintained anymore? Last release (v.1.20.4) was November 2014, about 4 months ago, and last commit to master was 22 days ago.

Webmock does a lot of good stuff. Don't reinvent it if you don't have to.

@onebree
Copy link
Contributor

onebree commented Mar 16, 2015

On its README, it says it is only supporting up to RSpec 2.x, and its badges stated failed builds and out-of-date dependencies.

Although I did contact someone on the Google Group -- they said they are updating the README as it does support RSpec 3.

@marnen
Copy link

marnen commented Mar 16, 2015

FWIW, I've never had any issues with Webmock; I suspect the failed build is more likely to mean that they never set up Travis properly. :)

@onebree
Copy link
Contributor

onebree commented Mar 16, 2015

As I told the owner in the google group forum:

Thank you... My spec or related MVC files may not be up to date fully with Rails 4, causing something to break during the tests.

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

No branches or pull requests

9 participants