Skip to content
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

Add VCR for mocking of API response #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ PATH
GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
Expand All @@ -16,6 +19,7 @@ GEM
dotenv-deployment (0.0.2)
faker (1.4.2)
i18n (~> 0.5)
hashdiff (0.3.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.6.11)
Expand All @@ -38,9 +42,15 @@ GEM
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
safe_yaml (1.0.4)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
vcr (3.0.3)
webmock (2.1.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff

PLATFORMS
ruby
Expand All @@ -50,6 +60,8 @@ DEPENDENCIES
faker (~> 1.4)
routific!
rspec (~> 3.0)
vcr
webmock

BUNDLED WITH
1.11.2
1.12.5
2 changes: 2 additions & 0 deletions routific.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('json', '~> 1.8')
s.add_development_dependency('rspec', '~> 3.0')
s.add_development_dependency('faker', '~> 1.4')
s.add_development_dependency('vcr')
s.add_development_dependency('webmock')
s.add_development_dependency('dotenv', '~> 0.11')
s.summary = 'routific API'
s.description = 'Gem to use Routific API'
Expand Down
62 changes: 62 additions & 0 deletions spec/fixtures/vcr_cassettes/routific/api_response.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions spec/fixtures/vcr_cassettes/routific/api_response/get_route.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions spec/helper/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
require 'bundler/setup'
Bundler.setup

require 'dotenv'
require 'faker'
require 'routific'
require 'webmock'
require 'vcr'

require 'dotenv'
require_relative './factory'

Bundler.setup
Dotenv.load

require 'routific'
RSpec.configure do |c|
WebMock.enable!

require_relative './factory'
VCR.configure do |vcr_config|
vcr_config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
vcr_config.hook_into :webmock # or :fakeweb
vcr_config.extend VCR::RSpec::Macros

RSpec.configure do |config|
vcr_config.default_cassette_options = {
:match_requests_on => [:method, :uri, :headers]
}
end
end
24 changes: 17 additions & 7 deletions spec/routific_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@
end

it "returns a Route instance" do
route = routific.getRoute()
expect(route).to be_instance_of(RoutificApi::Route)
VCR.use_cassette 'routific/api_response/get_route' do
route = routific.getRoute()
expect(route).to be_instance_of(RoutificApi::Route)
end
end

it "attaches optional data hash" do
Expand All @@ -121,8 +123,10 @@
options: routific.options
}

route = routific.getRoute()
expect(route).to be_instance_of(RoutificApi::Route)
VCR.use_cassette 'routific/api_response/with_data_hash' do
route = routific.getRoute()
expect(route).to be_instance_of(RoutificApi::Route)
end
end
end
end
Expand Down Expand Up @@ -187,7 +191,9 @@
end

it "returns a Route instance" do
expect(Routific.getRoute(@data)).to be_instance_of(RoutificApi::Route)
VCR.use_cassette 'routific/api_response' do
expect(Routific.getRoute(@data)).to be_instance_of(RoutificApi::Route)
end
end
end

Expand All @@ -197,13 +203,17 @@
end

it "returns a Route instance" do
expect(Routific.getRoute(@data, ENV["API_KEY"])).to be_instance_of(RoutificApi::Route)
VCR.use_cassette 'routific/api_response' do
expect(Routific.getRoute(@data, ENV["API_KEY"])).to be_instance_of(RoutificApi::Route)
end
end

it "still successful even if missing prefix 'bearer ' in key" do
key = ENV["API_KEY"].sub /bearer /, ''
expect(/bearer /.match(key).nil?).to be true
expect(Routific.getRoute(@data, key)).to be_instance_of(RoutificApi::Route)
VCR.use_cassette 'routific/api_response' do
expect(Routific.getRoute(@data, key)).to be_instance_of(RoutificApi::Route)
end
end
end
end
Expand Down