From 870ad85705393be8d76e4caf0ec111608e2472fd Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 26 Jul 2010 21:54:34 -0700 Subject: Get Bundler tests running on RSpec 2 --- Rakefile | 13 +++++-------- spec/lock/flex_spec.rb | 14 ++++++++------ spec/other/show_spec.rb | 2 +- spec/quality_spec.rb | 11 +++++++---- spec/spec_helper.rb | 4 ++-- spec/support/matchers.rb | 23 ++++++++++++----------- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/Rakefile b/Rakefile index dccbb12e64..0d01295fd9 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ def gemspec end begin - require 'spec/rake/spectask' + require 'rspec/core/rake_task' rescue LoadError raise 'Run `gem install rspec` to be able to run specs' else @@ -22,8 +22,7 @@ else end desc "Run specs" - Spec::Rake::SpecTask.new do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] + RSpec::Core::RakeTask.new do |t| t.spec_opts = %w(-fs --color) t.warning = true end @@ -35,8 +34,7 @@ end rubyopt = ENV["RUBYOPT"] %w(master REL_1_3_5 REL_1_3_6).each do |rg| desc "Run specs with Rubygems #{rg}" - Spec::Rake::SpecTask.new("spec_gems_#{rg}") do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] + RSpec::Core::RakeTask.new("spec_gems_#{rg}") do |t| t.spec_opts = %w(-fs --color) t.warning = true end @@ -62,11 +60,10 @@ end ruby_cmd = File.expand_path("~/.rvm/bin/ruby-#{ruby}") desc "Run specs on Ruby #{ruby}" - Spec::Rake::SpecTask.new("spec_ruby_#{ruby}") do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] + RSpec::Core::RakeTask.new("spec_ruby_#{ruby}") do |t| t.spec_opts = %w(-fs --color) t.warning = true - t.ruby_cmd = ruby_cmd + #t.ruby_cmd = ruby_cmd end task "ensure_ruby_#{ruby}" do diff --git a/spec/lock/flex_spec.rb b/spec/lock/flex_spec.rb index 70a01edb6e..dbe08f944c 100644 --- a/spec/lock/flex_spec.rb +++ b/spec/lock/flex_spec.rb @@ -3,15 +3,17 @@ require "spec_helper" describe "the lockfile format" do include Bundler::GemHelpers - def be_with_diff(expected) - # Trim the leading spaces + RSpec::Matchers.define :be_with_diff do |expected| spaces = expected[/\A\s+/, 0] || "" expected.gsub!(/^#{spaces}/, '') - simple_matcher "should be" do |given, m| - m.failure_message = "The lockfile did not match.\n=== Expected:\n" << - expected << "\n=== Got:\n" << given << "\n===========\n" - expected == given + failure_message_for_should do |actual| + "The lockfile did not match.\n=== Expected:\n" << + expected << "\n=== Got:\n" << actual << "\n===========\n" + end + + match do |actual| + expected == actual end end diff --git a/spec/other/show_spec.rb b/spec/other/show_spec.rb index 352b607f09..4655d4fc43 100644 --- a/spec/other/show_spec.rb +++ b/spec/other/show_spec.rb @@ -31,7 +31,7 @@ describe "bundle show" do it "prints the path to the running bundler" do bundle "show bundler" - out.should == File.expand_path('../../../../../', __FILE__) + out.should == File.expand_path('../../../', __FILE__) end it "complains if gem not in bundle" do diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index 32dcaafbbf..087d9ea086 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -22,10 +22,13 @@ describe "The library itself" do end end - def be_well_formed - simple_matcher("be well formed") do |given, matcher| - matcher.failure_message = given.join("\n") - given.empty? + RSpec::Matchers.define :be_well_formed do + failure_message_for_should do |actual| + actual.join("\n") + end + + match do |actual| + actual.empty? end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 677e75637a..666e2b62a4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ $:.unshift File.expand_path('../../lib', __FILE__) require 'fileutils' require 'rubygems' require 'bundler' -require 'spec' +require 'rspec' Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file| require file @@ -17,7 +17,7 @@ Spec::Rubygems.setup FileUtils.rm_rf(Spec::Path.gem_repo1) ENV['RUBYOPT'] = "-I#{Spec::Path.root}/spec/support/rubygems_hax" -Spec::Runner.configure do |config| +RSpec.configure do |config| config.include Spec::Builders config.include Spec::Helpers config.include Spec::Indexes diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 19c9b0f197..16916dedd2 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,25 +1,26 @@ module Spec module Matchers - def have_dep(*args) - simple_matcher "have dependency" do |given, matcher| - dep = Bundler::Dependency.new(*args) + RSpec::Matchers.define :have_dep do |*args| + dep = Bundler::Dependency.new(*args) - # given.length == args.length / 2 - given.length == 1 && given.all? { |d| d == dep } + match do |actual| + actual.length == 1 && actual.all? { |d| d == dep } end end - def have_gem(*args) - simple_matcher "have gem" do |given, matcher| - given.length == args.length && given.all? { |g| args.include?(g.full_name) } + RSpec::Matchers.define :have_gem do |*args| + match do |actual| + actual.length == args.length && actual.all? { |a| args.include?(a.full_name) } end end - def have_rubyopts(*args) + RSpec::Matchers.define :have_rubyopts do |*args| args = args.flatten args = args.first.split(/\s+/) if args.size == 1 - simple_matcher "have options #{args.join(' ')}" do |actual| + #failure_message_for_should "Expected RUBYOPT to have options #{args.join(" ")}. It was #{ENV["RUBYOPT"]}" + + match do |actual| actual = actual.split(/\s+/) if actual.is_a?(String) args.all? {|arg| actual.include?(arg) } && actual.uniq.size == actual.size end @@ -66,4 +67,4 @@ module Spec bundled_app("Gemfile.lock").should exist end end -end \ No newline at end of file +end -- cgit v1.2.1