Permalink
Browse files

Upgrade to rspec-2.

  • Loading branch information...
myronmarston committed Jul 23, 2010
1 parent afaf807 commit f05cc59abc16b711e345bab2994ad2ebfdce7170
View
@@ -16,6 +16,7 @@ tags
## PROJECT::GENERAL
coverage
+coverage.data
rdoc
pkg
View
@@ -1,7 +1,7 @@
source :rubygems
group :development do
- gem 'rspec', '~> 1.3.0'
+ gem 'rspec', '>= 2.0.0.beta.19'
gem 'cucumber', '>= 0.8.5'
gem 'fakeweb', '~> 1.2.8'
gem 'webmock', '~> 1.3.0'
@@ -16,7 +16,11 @@ group :development do
end
end
-group :test do
+# Additional gems that are useful, but not required for development.
+# These will not be added to the gemspec as development dependencies.
+group :extras do
+ gem 'rcov'
+
platforms :ruby_18 do
gem 'ruby-debug'
end
View
@@ -26,9 +26,9 @@ GEM
eventmachine (>= 0.12.9)
eventmachine (0.12.10)
fakeweb (1.2.8)
- ffi (0.6.3-java)
ffi (0.6.3)
rake (>= 0.8.7)
+ ffi (0.6.3-java)
gherkin (2.1.5-java)
trollop (~> 1.16.2)
gherkin (2.1.5)
@@ -39,15 +39,24 @@ GEM
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
mime-types (1.16)
+ nokogiri (1.4.2)
nokogiri (1.4.2-java)
weakling (>= 0.0.3)
- nokogiri (1.4.2)
patron (0.4.6)
rack (1.2.0)
rack-test (0.5.4)
rack (>= 1.0)
rake (0.8.7)
- rspec (1.3.0)
+ rcov (0.9.8-java)
+ rcov (0.9.8)
+ rspec (2.0.0.beta.19)
+ rspec-core (= 2.0.0.beta.19)
+ rspec-expectations (= 2.0.0.beta.19)
+ rspec-mocks (= 2.0.0.beta.19)
+ rspec-core (2.0.0.beta.19)
+ rspec-expectations (2.0.0.beta.19)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.19)
ruby-debug (0.10.3)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.3.0)
@@ -71,7 +80,7 @@ GEM
term-ansicolor (1.0.5)
trollop (1.16.2)
weakling (0.0.4-java)
- webmock (1.3.1)
+ webmock (1.3.2)
addressable (>= 2.1.1)
crack (>= 0.1.7)
@@ -88,7 +97,8 @@ DEPENDENCIES
patron (~> 0.4.6)
rack (= 1.2.0)
rake (~> 0.8.7)
- rspec (~> 1.3.0)
+ rcov
+ rspec (>= 2.0.0.beta.19)
ruby-debug
ruby-debug19
webmock (~> 1.3.0)
View
@@ -1,25 +1,17 @@
require 'rubygems'
require 'rake'
+require "rspec/core/rake_task"
-begin
- require 'spec/rake/spectask'
- Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
- spec.spec_opts = ['--color', '--format', 'progress']
- spec.spec_opts << '--debugger' unless RUBY_PLATFORM == 'java'
- end
+RSpec::Core::RakeTask.new(:spec)
- Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
- spec.rcov_opts = ['--exclude', '.rvm']
- end
-rescue LoadError
- task :spec do
- abort "Rspec is not available. In order to run specs, you must: sudo gem install rspec"
- end
+desc "Run all examples using rcov"
+RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
+ t.rcov = true
+ t.rcov_opts = %[-Ilib -Ispec --exclude "spec/*,gems/*" --text-report --sort coverage --aggregate coverage.data]
+end
+
+task :cleanup_rcov_files do
+ rm_rf 'coverage.data'
end
begin
@@ -1,5 +1,51 @@
require 'tmpdir'
+RSpec::Matchers.define :have_expected_response do |url, regex_str|
+ def responses_for_url(responses, url)
+ selector = case url
+ when String then lambda { |r| URI.parse(r.uri) == URI.parse(url) }
+ when Regexp then lambda { |r| r.uri == url }
+ else raise ArgumentError.new("Unexpected url: #{url.class.to_s}: #{url.inspect}")
+ end
+
+ responses.select(&selector)
+ end
+
+ match do |responses|
+ regex = /#{regex_str}/i
+ responses_for_url(responses, url).detect { |r| get_body_string(r.response) =~ regex }
+ end
+
+ failure_message_for_should do |responses|
+ responses = responses_for_url(responses, url)
+ response_bodies = responses.map { |r| get_body_string(r.response) }
+ "expected a response for #{url.inspect} to match /#{regex_str}/. Responses for #{url.inspect}:\n\n #{response_bodies.join("\n\n")}"
+ end
+end
+
+RSpec::Matchers.define :be_tagged_with do |tag|
+ match do |scenario|
+ scenario.source_tag_names.include?(tag)
+ end
+
+ failure_message_for_should do |scenario|
+ "expected scenario to be tagged with #{tag}. Tags: #{scenario.source_tag_names.inspect}"
+ end
+end
+
+RSpec::Matchers.define :have_normalized_headers do
+ match do |object|
+ headers = object.headers
+ headers.is_a?(Hash) &&
+ headers.keys.map { |k| k.downcase } == headers.keys &&
+ headers.values.all? { |val| val.is_a?(Array) }
+ end
+
+ failure_message_for_should do |object|
+ "expected headers to be normalized to have lower cased keys and arrays as values. Actual headers: #{object.headers.inspect}"
+ end
+end
+
module VCRHelpers
def static_rack_server(response_string)
orig_ignore_localhost = VCR.http_stubbing_adapter.ignore_localhost?
@@ -12,31 +58,6 @@ def static_rack_server(response_string)
end
end
- def have_expected_response(url, regex_str)
- simple_matcher("a response from #{url} that matches /#{regex_str}/") do |responses|
- selector = case url
- when String then lambda { |r| URI.parse(r.uri) == URI.parse(url) }
- when Regexp then lambda { |r| r.uri == url }
- else raise ArgumentError.new("Unexpected url: #{url.class.to_s}: #{url.inspect}")
- end
-
- responses = responses.select(&selector)
- regex = /#{regex_str}/i
- responses.detect { |r| get_body_string(r.response) =~ regex }
- end
- end
-
- def have_normalized_headers
- simple_matcher("should have normalized headers") do |object, matcher|
- headers = object.headers
- headers.should be_instance_of(Hash)
- headers.keys.map { |k| k.downcase }.should == headers.keys
- headers.values.each do |val|
- val.should be_instance_of(Array)
- end
- end
- end
-
def recorded_interactions_for(cassette_name)
yaml_file = File.join(VCR::Config.cassette_library_dir, "#{cassette_name}.yml")
yaml = File.open(yaml_file, 'r') { |f| f.read }
@@ -55,11 +76,6 @@ def capture_response(url)
@http_requests[url] += [result]
end
- def be_tagged_with(tag)
- simple_matcher("be tagged with #{tag}") do |object|
- object.source_tag_names.include?(tag)
- end
- end
end
World(VCRHelpers)
View
@@ -32,8 +32,6 @@
# ruby-debug wasn't available so neither can the debugging be
end
-require 'spec'
-
# Ruby 1.9.1 has a different yaml serialization format.
YAML_SERIALIZATION_VERSION = RUBY_VERSION == '1.9.1' ? '1.9.1' : 'not_1.9.1'
@@ -5,58 +5,58 @@
it_should_behave_like 'an http stubbing adapter that supports Net::HTTP'
context "using patron" do
- def get_body_string(response); response.body; end
+ it_should_behave_like 'an http stubbing adapter that supports some HTTP library' do
+ def get_body_string(response); response.body; end
- def make_http_request(method, url, body = {})
- uri = URI.parse(url)
- sess = Patron::Session.new
- sess.base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
+ def make_http_request(method, url, body = {})
+ uri = URI.parse(url)
+ sess = Patron::Session.new
+ sess.base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}"
- case method
- when :get
- sess.get(uri.path)
- when :post
- sess.post(uri.path, body)
+ case method
+ when :get
+ sess.get(uri.path)
+ when :post
+ sess.post(uri.path, body)
+ end
end
end
-
- it_should_behave_like 'an http stubbing adapter that supports some HTTP library'
end unless RUBY_PLATFORM =~ /java/
context "using httpclient" do
- def get_body_string(response)
- response.body.content
- end
+ it_should_behave_like 'an http stubbing adapter that supports some HTTP library' do
+ def get_body_string(response)
+ response.body.content
+ end
- def make_http_request(method, url, body = {})
- case method
- when :get
- HTTPClient.new.get(url)
- when :post
- HTTPClient.new.post(url, body)
+ def make_http_request(method, url, body = {})
+ case method
+ when :get
+ HTTPClient.new.get(url)
+ when :post
+ HTTPClient.new.post(url, body)
+ end
end
end
-
- it_should_behave_like 'an http stubbing adapter that supports some HTTP library'
end
context "using em-http-request" do
- def get_body_string(response)
- response.response
- end
+ it_should_behave_like 'an http stubbing adapter that supports some HTTP library' do
+ def get_body_string(response)
+ response.response
+ end
- def make_http_request(method, url, body = {})
- EventMachine.run do
- http = case method
- when :get then EventMachine::HttpRequest.new(url).get
- when :post then EventMachine::HttpRequest.new(url).post :body => body
- end
+ def make_http_request(method, url, body = {})
+ EventMachine.run do
+ http = case method
+ when :get then EventMachine::HttpRequest.new(url).get
+ when :post then EventMachine::HttpRequest.new(url).post :body => body
+ end
- http.callback { EventMachine.stop; return http }
+ http.callback { EventMachine.stop; return http }
+ end
end
end
-
- it_should_behave_like 'an http stubbing adapter that supports some HTTP library'
end unless RUBY_PLATFORM =~ /java/
describe '#check_version!' do
View
@@ -1,3 +0,0 @@
---color
---format nested
---debugger
View
@@ -10,8 +10,7 @@
require 'vcr'
require 'vcr/http_stubbing_adapters/fakeweb'
require 'vcr/http_stubbing_adapters/webmock'
-require 'spec'
-require 'spec/autorun'
+require 'rspec'
# Ruby 1.9.1 has a different yaml serialization format.
YAML_SERIALIZATION_VERSION = RUBY_VERSION == '1.9.1' ? '1.9.1' : 'not_1.9.1'
@@ -20,10 +19,12 @@
# in ./support/ and its subdirectories.
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
-Spec::Runner.configure do |config|
+RSpec.configure do |config|
config.extend TempCassetteLibraryDir
config.extend DisableWarnings
+ config.color_enabled = true
+
config.before(:each) do
VCR::Config.default_cassette_options = { :record => :new_episodes }
VCR::Config.http_stubbing_library = :fakeweb
@@ -54,18 +54,18 @@
shared_examples_for "an http stubbing adapter that supports Net::HTTP" do
context "using Net::HTTP" do
- def get_body_string(response); response.body; end
-
- def make_http_request(method, url, body = {})
- case method
- when :get
- Net::HTTP.get_response(URI.parse(url))
- when :post
- Net::HTTP.post_form(URI.parse(url), body)
+ it_should_behave_like 'an http stubbing adapter that supports some HTTP library' do
+ def get_body_string(response); response.body; end
+
+ def make_http_request(method, url, body = {})
+ case method
+ when :get
+ Net::HTTP.get_response(URI.parse(url))
+ when :post
+ Net::HTTP.post_form(URI.parse(url), body)
+ end
end
end
-
- it_should_behave_like 'an http stubbing adapter that supports some HTTP library'
end
end

0 comments on commit f05cc59

Please sign in to comment.