Skip to content

Commit

Permalink
VCR
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Pires authored and Jackson Pires committed Nov 19, 2017
1 parent ecc3db8 commit 675787a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
1 change: 1 addition & 0 deletions test_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ group :development, :test do
gem 'faker'
gem 'httparty'
gem 'webmock'
gem 'vcr'
end

group :development do
Expand Down
2 changes: 2 additions & 0 deletions test_app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ GEM
thread_safe (~> 0.1)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)
vcr (3.0.3)
web-console (3.5.1)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -229,6 +230,7 @@ DEPENDENCIES
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
vcr
web-console (>= 3.3.0)
webmock

Expand Down
67 changes: 67 additions & 0 deletions test_app/spec/fixtures/vcr_cassettes/jsonplaceholder/posts.yml

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

12 changes: 7 additions & 5 deletions test_app/spec/httparty/httparty_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
describe 'HTTParty' do
it 'content-type' do
stub_request(:get, "https://jsonplaceholder.typicode.com/posts/2").
to_return(status: 200, body: "", headers: { 'content-type': 'application/json'})
#stub_request(:get, "https://jsonplaceholder.typicode.com/posts/2").
# to_return(status: 200, body: "", headers: { 'content-type': 'application/json'})

response = HTTParty.get('https://jsonplaceholder.typicode.com/posts/2')
content_type = response.headers['content-type']
expect(content_type).to match(/application\/json/)
VCR.use_cassette("jsonplaceholder/posts") do
response = HTTParty.get('https://jsonplaceholder.typicode.com/posts/2')
content_type = response.headers['content-type']
expect(content_type).to match(/application\/json/)
end
end
end
5 changes: 5 additions & 0 deletions test_app/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Webmock gem
require 'webmock/rspec'

VCR.configure do |config|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
config.hook_into :webmock
end

# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
Expand Down

0 comments on commit 675787a

Please sign in to comment.