Open om-nishu-trantor opened 8 years ago
@om-nishu-trantor I don't have enough information to help you.
Can you provide a sample code using boxr gem that reproduces the issue?
What version of WebMock?
Is webmock definitely loaded and enabled?
webmock 1.24.5
before(:all) do
WebMock.disable_net_connect!(:allow_localhost => true)
end
I am conditionally blocking web requests in this particular spec. Yes it is loaded, because I have 2 specs, 1 for gdrive and another for box. Gdrive spec works fine, but Box hits the real request and says the following :-
Boxr::BoxrError:
401: Bearer realm="Service", error="invalid_token", error_description="The access token provided is invalid."
Snippets :-
require 'rails_helper'
RSpec.describe MyImportModel, type: :model do
before(:all) do
WebMock.disable_net_connect!(:allow_localhost => true)
end
after(:all) do
WebMock.allow_net_connect!
end
describe '#mymethod' do
it 'should block check the response manipulation' do
stub_request(:get, Regexp.new('https://api.box.com/2.0/search')).
to_return(:status => 200, :body => {}.to_json)
expect do
described_class.mymethod
end.to change {
MyImportModel.count
}.by(2)
end
end
end
I just had the same issue. It looks like the Boxr::BOX_CLIENT is declared globally before Webmock injects itself: https://github.com/cburnette/boxr/blob/c35eafcd44474e853d0f3cbe108e7e4385afa1d8/lib/boxr.rb#L57
As a quick hack, I just force re-create the client in my spec
before :all do
Boxr::BOX_CLIENT = HTTPClient.new
end
@skalb this answer just helped me figure out why the VCR gem wasn't creating cassettes for my specs that hit the Box API using Boxr - thanks!
@skalb I was saved. Thanks!
I have been using Boxr gem for fetching data from BOX Apis. But somehow Webmock does not seems to be blocking the requests. Here is the file responsible for making web requests in the Boxr gem.
Getting 401(Always will, if hits the real api) want to mock the response and check if responses are handled correctly. Any pointers ?