Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#270619 Setup vcr to log all external API calls in development mode.

  • Loading branch information...
commit 277fcf7e8ce308baae439f21888ea79d2ff2b3a3 1 parent b6c6c57
@lucassus authored
View
5 Gemfile
@@ -56,6 +56,11 @@ group :development, :test do
gem 'factory_girl_rails'
gem 'faker'
+
+ # Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
+ gem 'vcr'
+ # Library for stubbing and setting expectations on HTTP requests in Ruby. (required by vcr)
+ gem 'webmock'
end
group :development do
View
7 Gemfile.lock
@@ -66,6 +66,7 @@ GEM
coffee-script-source (1.3.3)
columnize (0.3.6)
commonjs (0.2.6)
+ crack (0.3.1)
daemons (1.1.8)
database_cleaner (0.7.2)
debugger (1.1.3)
@@ -306,8 +307,12 @@ GEM
unf (0.0.5)
unf_ext
unf_ext (0.0.4)
+ vcr (2.1.1)
warden (1.1.1)
rack (>= 1.0)
+ webmock (1.8.7)
+ addressable (>= 2.2.7)
+ crack (>= 0.1.7)
webrobots (0.0.13)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -362,4 +367,6 @@ DEPENDENCIES
thin
twitter-bootstrap-rails
uglifier (>= 1.0.3)
+ vcr
+ webmock
yard
View
11 config/environments/development.rb
@@ -36,4 +36,15 @@
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
+
+ # Configure VCR to log all HTTP requests
+ # See also /config/initializers/vcr_logging.rb
+ if ENV['VCR_LOGGING'].present?
+ require 'vcr'
+
+ config.middleware.use VCR::Middleware::Rack do |cassette|
+ cassette.name 'vcr.log'
+ cassette.options :record => :all
+ end
+ end
end
View
12 config/initializers/vcr_logging.rb
@@ -0,0 +1,12 @@
+if Rails.env.development? and ENV['VCR_LOGGING'].present?
+ # Configure VCR to log all HTTP requests
+ # In this configuration VCR will never replay previously recorded interactions
+ # In order to enable VCR logging run the server with the following command: VCR_LOGGING=1 rails server
+ # See also /config/environments/development.rb
+ require 'vcr'
+
+ VCR.configure do |c|
+ c.cassette_library_dir = File.expand_path('log', Rails.root)
+ c.hook_into :webmock
+ end
+end
View
7 doc/testing.md
@@ -153,3 +153,10 @@ TODO
[Blog post about spork](http://ablogaboutcode.com/2011/05/18/spork-rspec-sham-and-caching-classes)
+## Vcr
+
+Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
+
+You could use this library in development mode in order to debug interactions with external APIs:
+
+ VCR_LOGGING=1 rails server
Please sign in to comment.
Something went wrong with that request. Please try again.