Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New cuke: basic_usage.feature.

  • Loading branch information...
commit 15d027e69ed2f475eb5c76af24778e94522f9a9d 1 parent b0334d1
@myronmarston authored
View
5 Gemfile.lock
@@ -82,8 +82,12 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
term-ansicolor (1.0.5)
thor (0.14.4)
+ tilt (1.1)
timecop (0.3.5)
typhoeus (0.2.0)
webmock (1.6.0)
@@ -113,6 +117,7 @@ DEPENDENCIES
ruby-debug
ruby-debug-base19 (= 0.11.23)
ruby-debug19
+ sinatra (~> 1.1.0)
timecop (~> 0.3.5)
typhoeus (~> 0.2.0)
vcr!
View
60 features/basic_usage.feature
@@ -0,0 +1,60 @@
+Feature: basic usage
+
+ VCR makes it easy to record HTTP interactions and replay them. Simply wrap
+ a block of code in `VCR.use_cassette`. The first time you run the code,
+ a real HTTP request will be made, and VCR will record it to a cassette YAML file.
+ Subsequent runs will replay the response recorded to the cassette.
+
+ VCR currently uses 3 different HTTP stubbing libraries to support 6 different
+ HTTP libraries:
+
+ * FakeWeb can be used to stub Net::HTTP.
+ * WebMock can be used to stub:
+ * Net::HTTP
+ * HTTPClient
+ * Patron
+ * Curb
+ * EM HTTP Request
+ * Typhoeus can be used to stub itself.
+
+ Scenario Outline: Record and replay an HTTP interaction
+ Given a file named "vcr_example.rb" with:
+ """
+ require 'vcr_cucumber_helpers'
+
+ sinatra_app(:port => 7777) do
+ get('/') { ARGV[0] }
+ end
+
+ include_http_adapter_for("<http_lib>")
+
+ require 'vcr'
+
+ VCR.config do |c|
+ c.stub_with :<stub_with>
+ c.cassette_library_dir = 'vcr_cassettes'
+ end
+
+ VCR.use_cassette('example', :record => :new_episodes) do
+ response = make_http_request(:get, "http://localhost:7777/")
+ puts "The response body was: #{get_body_string(response)}"
+ end
+ """
+ When I run "ruby vcr_example.rb 'Hello World'"
+ Then the output should contain "The response body was: Hello World"
+ And the file "vcr_cassettes/example.yml" should contain "body: Hello World"
+
+ When I run "ruby vcr_example.rb 'Goodbye World'"
+ Then the output should contain "The response body was: Hello World"
+ And the file "vcr_cassettes/example.yml" should contain "body: Hello World"
+
+ Examples:
+ | stub_with | http_lib |
+ | fakeweb | net/http |
+ | webmock | net/http |
+ | webmock | httpclient |
+ | webmock | patron |
+ | webmock | curb |
+ | webmock | em-http-request |
+ | typhoeus | typhoeus |
+
View
28 features/support/env.rb
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'bundler'
+Bundler.setup
+
+require 'aruba'
+
+Before do
+ create_file("vcr_cucumber_helpers.rb", <<-EOF)
+ $LOAD_PATH.unshift '../../spec' unless $LOAD_PATH.include?('../../spec')
+
+ def include_http_adapter_for(lib)
+ require 'support/http_library_adapters'
+ require lib
+ include HTTP_LIBRARY_ADAPTERS[lib]
+ end
+
+ def sinatra_app(options, &block)
+ raise ArgumentError.new("You must pass a port") unless options[:port]
+
+ require 'sinatra'
+ require 'support/vcr_localhost_server'
+ klass = Class.new(Sinatra::Base)
+ klass.class_eval(&block)
+
+ VCR::LocalhostServer.new(klass.new, options[:port])
+ end
+ EOF
+end
View
4 spec/support/vcr_localhost_server.rb
@@ -22,8 +22,8 @@ def call(env)
attr_reader :port
- def initialize(rack_app)
- @port = find_available_port
+ def initialize(rack_app, port = nil)
+ @port = port || find_available_port
@rack_app = rack_app
concurrently { boot }
wait_until(10, "Boot failed.") { booted? }
View
3  vcr.gemspec
@@ -32,7 +32,8 @@ Gem::Specification.new do |s|
'httpclient' => '~> 2.1.5.2',
'timecop' => '~> 0.3.5',
- 'rack' => '1.1.0'
+ 'rack' => '1.1.0',
+ 'sinatra' => '~> 1.1.0'
}.each do |lib, version|
s.add_development_dependency lib, version
end
Please sign in to comment.
Something went wrong with that request. Please try again.