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,