Beginner Problems with WebMock and Cucumber

974 views
Skip to first unread message

Doug Reeder (CAS)

unread,
Jul 3, 2013, 11:51:55 AM7/3/13
to webmoc...@googlegroups.com
I'm trying to add WebMock to our existing Cucumber tests. We only need to mock selected requests; most should pass through to the real server.  So for my first Scenario, I've added the tag @webmock_search and the following code to hooks.rb.  The LOGGER lines are executed when I expect them to.

Before do
  LOGGER.info 'WebMock: allowing outside connections'
  WebMock.allow_net_connect!
end

Before('@webmock_search') do
  LOGGER.info 'WebMock: mocking searches'
  stub_request(:post, "ourhost.org:81").to_return(:status => 400)
end


Without WebMock.allow_net_connect!, all requests are mocked. But now, my stub request doesn't appear to function - the request is just passed to our external server.  I've been over https://github.com/bblimke/webmock#real-requests-to-network-can-be-allowed-or-disabled many times - is there something else I need to do to allow most requests to be passed to our external server, but mock selected ones?

Bartosz Blimke

unread,
Jul 3, 2013, 12:00:42 PM7/3/13
to webmoc...@googlegroups.com
It seems that the stub_request(:post, "ourhost.org:81") doesn't match.

Can you confirm that this stub matches your request correctly and returns 400 when allow_net_connect! is removed?

allow_net_connect! only matters if request was not matched by a stub first.

Bartosz


2013/7/3 Doug Reeder (CAS) <pre...@cas.org>

--
 
---
You received this message because you are subscribed to the Google Groups "webmock-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webmock-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Doug Reeder (CAS)

unread,
Jul 3, 2013, 2:42:45 PM7/3/13
to webmoc...@googlegroups.com
When I remove allow_net_connect!, our app can't get into the state where it can issue the request in question.

As far as I can tell, the request should match the stub. What tools can I use to check, other than simply inspecting the code?

Bartosz Blimke

unread,
Jul 3, 2013, 3:02:10 PM7/3/13
to webmoc...@googlegroups.com
You can use disable_net_connect! with selective 'allow' pattern instead of using allow_net_connect.

You can stay with allow_net_connect and put diable_net_connect! directly in your code for debugging purposes,just before the place where the request is issued.

Doug Reeder (CAS)

unread,
Jul 3, 2013, 4:31:26 PM7/3/13
to webmoc...@googlegroups.com
Do stub_request and stub_http_request take different arguments?  The docs seem to use them interchangeably.

Bartosz Blimke

unread,
Jul 4, 2013, 5:31:32 AM7/4/13
to webmoc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages