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

Comments

Projects
None yet
9 participants
@andreareginato
Collaborator

andreareginato commented Oct 3, 2012

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

@mattvanhorn

This comment has been minimized.

Show comment
Hide comment
@mattvanhorn

mattvanhorn Oct 3, 2012

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

mattvanhorn commented Oct 3, 2012

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

@marnen

This comment has been minimized.

Show comment
Hide comment
@marnen

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

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

This comment has been minimized.

Show comment
Hide comment
@pawel2105

pawel2105 Oct 4, 2012

Any suggestions for Rails 2 apps?

pawel2105 commented Oct 4, 2012

Any suggestions for Rails 2 apps?

@marnen

This comment has been minimized.

Show comment
Hide comment
@marnen

marnen Oct 4, 2012

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

marnen commented Oct 4, 2012

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

@dchelimsky

This comment has been minimized.

Show comment
Hide comment
@dchelimsky

dchelimsky Oct 6, 2012

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

dchelimsky commented Oct 6, 2012

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

This comment has been minimized.

Show comment
Hide comment
@marnen

marnen 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. :)

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

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Oct 6, 2012

Collaborator

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

Collaborator

andreareginato commented Oct 6, 2012

@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

This comment has been minimized.

Show comment
Hide comment
@makaroni4

makaroni4 commented Nov 25, 2012

@andreareginato fix topic name: #43

@andreareginato

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Nov 26, 2012

Collaborator

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

Collaborator

andreareginato commented Nov 26, 2012

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

@makaroni4

This comment has been minimized.

Show comment
Hide comment
@makaroni4

makaroni4 Nov 26, 2012

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.

makaroni4 commented Nov 26, 2012

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

This comment has been minimized.

Show comment
Hide comment
@pepe

pepe Nov 26, 2012

@makaroni4 👍 for expect

pepe commented Nov 26, 2012

@makaroni4 👍 for expect

@andreareginato

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Mar 9, 2013

Collaborator

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.

Collaborator

andreareginato commented Mar 9, 2013

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

This comment has been minimized.

Show comment
Hide comment
@passion8

passion8 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."

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

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Apr 8, 2013

Collaborator

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

Collaborator

andreareginato commented Apr 8, 2013

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

@passion8

This comment has been minimized.

Show comment
Hide comment
@passion8

passion8 commented Apr 8, 2013

@andreareginato , sent .

@onebree

This comment has been minimized.

Show comment
Hide comment
@onebree

onebree Mar 16, 2015

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@marnen

marnen 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. :)

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

This comment has been minimized.

Show comment
Hide comment
@onebree

onebree Mar 16, 2015

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Mar 16, 2015

Collaborator

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

Collaborator

andreareginato commented Mar 16, 2015

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

This comment has been minimized.

Show comment
Hide comment
@marnen

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

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

This comment has been minimized.

Show comment
Hide comment
@onebree

onebree Mar 16, 2015

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@marnen

marnen 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. :)

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

This comment has been minimized.

Show comment
Hide comment
@onebree

onebree Mar 16, 2015

Contributor

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.

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