Attempting to solve - An HTTP request has been made that VCR does not know how to handle:

1,857 views
Skip to first unread message

lovell....@gmail.com

unread,
Nov 21, 2014, 1:59:29 PM11/21/14
to vcr-...@googlegroups.com
Hello all,

I am new to VCR and I am having trouble understanding what I am doing wrong. Right now I am getting the following error in 2 different places ( I will focus on 1 for now).

Failure/Error: expect(wrapper.current_weather).to be_instance_of Hash
     VCR::Errors::UnhandledHTTPRequestError:


       ================================================================================
       An HTTP request has been made that VCR does not know how to handle:
         GET http://api.openweathermap.org/data/2.5/weather?q=Silver%20Spring,MD

I am not sure how to fix this problem or what is exactly wrong. I did read the rest of the error that talks about the different ways to handle this but I really don't know which one of those is right for me. Can anyone tell me how can figure out what is going on? The end result is that I just want the cassette to be created and reused for future tests.

Currently this is my setup:

Gemfile:
group :test do
  gem
'vcr'
  gem
'webmock'
end


spec/rails_helper
VCR.configure do |c|
  c
.cassette_library_dir = 'spec/vcr_cassettes'
  c
.hook_into :webmock # or :fakeweb
end

spec/apis/open_weather_map_wrapper_spec.rb
require 'rails_helper'


describe
OpenWeatherMapWrapper do
  it
'sets @location' do
    location
= Fabricate :location
    wrapper
= OpenWeatherMapWrapper.new(location)
    expect
(wrapper.location).to eq location
 
end
 
  describe
'#current_weather', :vcr do
    it
'should return a hash' do
      location
= Fabricate(:location, name: 'Silver Spring,MD')
      wrapper
= OpenWeatherMapWrapper.new(location)
      expect
(wrapper.current_weather).to be_instance_of Hash
   
end
 
end
end

app/apis/open_weather_map_wrapper.rb
class OpenWeatherMapWrapper
  include
HTTParty
  attr_reader
:location
 
def initialize(location)
   
@location = location
 
end

 
def current_weather
    JSON
.parse(
     
HTTParty.get(
     
'http://api.openweathermap.org/data/2.5/weather', query: { q: @location.name }).body)
 
end
end

Any help is appreciated,

Thanks,

Myron Marston

unread,
Nov 21, 2014, 5:09:53 PM11/21/14
to vcr-...@googlegroups.com
A cassette needs to be inserted while an HTTP request is made.  The general API for this (that works with any test framework or no test framework) is `VCR.use_cassette`:


So, within your RSpec examples (the `it` blocks), you can wrap the code with `VCR.use_cassette`.  Alternately, since you're using RSpec, you can use VCR's RSpec integration based on metadata:


HTH,
Myron


--
You received this message because you are subscribed to the Google Groups "VCR Rubygem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vcr-ruby+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vell

unread,
Nov 23, 2014, 1:17:43 AM11/23/14
to vcr-...@googlegroups.com
Thanks for the reply. I will try again and let you know if I have any other troubles.

Vell

unread,
Nov 24, 2014, 8:04:58 AM11/24/14
to vcr-...@googlegroups.com
Thanks Myron

After reading the documentation, I was simply missing

c.configure_rspec_metadata!

Once I added that and ran my test all worked as expected.
Reply all
Reply to author
Forward
0 new messages