From 107589c02d343fd3fae2ce5f0e5e652fe2eb0c0a Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sat, 28 May 2011 07:42:09 -0500 Subject: [PATCH] upgrade to rspec-2.6 and update specs to newer conventions - RSpec adds lib and spec to load path, so require 'spec_helper' works and you don't need to add lib yourself - this also means spec_helper need not be wrapped in a condittional - it won't be loaded more than once - take advantage of the described class in the shared groups - use new be_within matcher instead of deprecated be_close matcher --- Gemfile | 2 +- Gemfile.lock | 37 ++-- Rakefile | 2 +- spec/spec_helper.rb | 176 +++++++++---------- spec/spork/app_framework/rails_spec.rb | 2 +- spec/spork/app_framework/unknown_spec.rb | 2 +- spec/spork/app_framework_spec.rb | 2 +- spec/spork/diagnoser_spec.rb | 2 +- spec/spork/forker_spec.rb | 4 +- spec/spork/run_strategy/forking_spec.rb | 2 +- spec/spork/runner_spec.rb | 2 +- spec/spork/server_spec.rb | 2 +- spec/spork/test_framework/cucumber_spec.rb | 11 +- spec/spork/test_framework/rspec_spec.rb | 10 +- spec/spork/test_framework_shared_examples.rb | 10 +- spec/spork/test_framework_spec.rb | 2 +- spec/spork_spec.rb | 2 +- 17 files changed, 131 insertions(+), 139 deletions(-) diff --git a/Gemfile b/Gemfile index 86246e0..4d63f5b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source :gemcutter gem 'cucumber', '0.10.2' -gem "rspec", "2.5.0" +gem 'rspec', '~> 2.6' gem 'rake' if RUBY_VERSION =~ /^1\.9/ diff --git a/Gemfile.lock b/Gemfile.lock index 84f57fa..42cc693 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: http://rubygems.org/ specs: + archive-tar-minitar (0.5.2) builder (3.0.0) columnize (0.3.2) cucumber (0.10.2) @@ -13,21 +14,27 @@ GEM gherkin (2.3.7) json (>= 1.4.6) json (1.5.1) - linecache (0.43) + linecache19 (0.5.12) + ruby_core_source (>= 0.1.4) rake (0.8.7) - rspec (2.5.0) - rspec-core (~> 2.5.0) - rspec-expectations (~> 2.5.0) - rspec-mocks (~> 2.5.0) - rspec-core (2.5.1) - rspec-expectations (2.5.0) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.3) + rspec-expectations (2.6.0) diff-lcs (~> 1.1.2) - rspec-mocks (2.5.0) - ruby-debug (0.10.4) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.4.0) - ruby-debug-base (0.10.4) - linecache (>= 0.3) + rspec-mocks (2.6.0) + ruby-debug-base19 (0.11.25) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby_core_source (>= 0.1.4) + ruby-debug19 (0.11.6) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby-debug-base19 (>= 0.11.19) + ruby_core_source (0.1.5) + archive-tar-minitar (>= 0.5.2) term-ansicolor (1.0.5) PLATFORMS @@ -36,5 +43,5 @@ PLATFORMS DEPENDENCIES cucumber (= 0.10.2) rake - rspec (= 2.5.0) - ruby-debug + rspec (~> 2.6) + ruby-debug19 diff --git a/Rakefile b/Rakefile index 9016e7d..c6e30aa 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ require 'rubygems' require 'bundler' Bundler.setup -require 'rake' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) + begin require 'cucumber/rake/task' Cucumber::Rake::Task.new(:features) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9d40a9d..4361c74 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,113 +1,107 @@ require 'rubygems' -unless $spec_helper_loaded - $spec_helper_loaded = true - - $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__))) - SPEC_TMP_DIR = File.expand_path('tmp', File.dirname(__FILE__)) - require 'spork' - require 'stringio' - require 'fileutils' - require 'rspec' - - RSpec.configure do |config| - config.before(:each) do - $test_stdout = StringIO.new - $test_stderr = StringIO.new - @current_dir = nil - end - - config.after(:each) do - FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR) - - end - - def create_file(filename, contents) - FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR) - - in_current_dir do - FileUtils.mkdir_p(File.dirname(filename)) - File.open(filename, 'wb') { |f| f << contents } - end - end +SPEC_TMP_DIR = File.expand_path('tmp', File.dirname(__FILE__)) +require 'spork' +require 'stringio' +require 'fileutils' +require 'rspec' - def create_helper_file(test_framework = FakeFramework) - create_file(test_framework.helper_file, "# stub spec helper file") - end +RSpec.configure do |config| + config.before(:each) do + $test_stdout = StringIO.new + $test_stderr = StringIO.new + @current_dir = nil + end - def in_current_dir(&block) - Dir.chdir(current_dir, &block) - end - - def current_dir - @current_dir ||= SPEC_TMP_DIR - end - - def change_current_dir(sub_path) - @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR) - end - - def windows? - ENV['OS'] == 'Windows_NT' - end + config.after(:each) do + FileUtils.rm_rf(SPEC_TMP_DIR) if File.directory?(SPEC_TMP_DIR) + end +end + +def create_file(filename, contents) + FileUtils.mkdir_p(SPEC_TMP_DIR) unless File.directory?(SPEC_TMP_DIR) + + in_current_dir do + FileUtils.mkdir_p(File.dirname(filename)) + File.open(filename, 'wb') { |f| f << contents } end +end +def create_helper_file(test_framework = FakeFramework) + create_file(test_framework.helper_file, "# stub spec helper file") +end - module RSpec - module Matchers - class IncludeAStringLike - def initialize(substring_or_regex) - case substring_or_regex - when String - @regex = Regexp.new(Regexp.escape(substring_or_regex)) - when Regexp - @regex = substring_or_regex - else - raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided" - end - end +def in_current_dir(&block) + Dir.chdir(current_dir, &block) +end - def matches?(list_of_strings) - @list_of_strings = list_of_strings - @list_of_strings.any? { |s| s =~ @regex } - end - def failure_message - "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}" - end - def negative_failure_message - "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did" +def current_dir + @current_dir ||= SPEC_TMP_DIR +end + +def change_current_dir(sub_path) + @current_dir = File.expand_path(sub_path, SPEC_TMP_DIR) +end + +def windows? + ENV['OS'] == 'Windows_NT' +end + + +module RSpec + module Matchers + class IncludeAStringLike + def initialize(substring_or_regex) + case substring_or_regex + when String + @regex = Regexp.new(Regexp.escape(substring_or_regex)) + when Regexp + @regex = substring_or_regex + else + raise ArgumentError, "don't know what to do with the #{substring_or_regex.class} you provided" end end - def include_a_string_like(substring_or_regex) - IncludeAStringLike.new(substring_or_regex) + def matches?(list_of_strings) + @list_of_strings = list_of_strings + @list_of_strings.any? { |s| s =~ @regex } + end + def failure_message + "#{@list_of_strings.inspect} expected to include a string like #{@regex.inspect}" + end + def negative_failure_message + "#{@list_of_strings.inspect} expected to not include a string like #{@regex.inspect}, but did" end end - end - module Spork::TestIOStreams - def self.included(klass) - klass.send(:extend, ::Spork::TestIOStreams::ClassMethods) + def include_a_string_like(substring_or_regex) + IncludeAStringLike.new(substring_or_regex) end - + end +end + +module Spork::TestIOStreams + def self.included(klass) + klass.send(:extend, ::Spork::TestIOStreams::ClassMethods) + end + + def stderr + self.class.stderr + end + + def stdout + self.class.stdout + end + + module ClassMethods def stderr - self.class.stderr + $test_stderr end def stdout - self.class.stdout - end - - module ClassMethods - def stderr - $test_stderr - end - - def stdout - $test_stdout - end + $test_stdout end end - - Dir.glob(File.dirname(__FILE__) + "/support/*.rb").each { |f| require(f) } end + +Dir.glob(File.dirname(__FILE__) + "/support/*.rb").each { |f| require(f) } diff --git a/spec/spork/app_framework/rails_spec.rb b/spec/spork/app_framework/rails_spec.rb index bdd4eee..6258417 100644 --- a/spec/spork/app_framework/rails_spec.rb +++ b/spec/spork/app_framework/rails_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require 'spec_helper' describe Spork::AppFramework::Rails do describe ".deprecated_version" do diff --git a/spec/spork/app_framework/unknown_spec.rb b/spec/spork/app_framework/unknown_spec.rb index 2838c41..67ecac3 100644 --- a/spec/spork/app_framework/unknown_spec.rb +++ b/spec/spork/app_framework/unknown_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require 'spec_helper' describe Spork::AppFramework::Unknown do it "requires bootstrapping" do diff --git a/spec/spork/app_framework_spec.rb b/spec/spork/app_framework_spec.rb index ba2aad2..855eb23 100644 --- a/spec/spork/app_framework_spec.rb +++ b/spec/spork/app_framework_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::AppFramework do describe ".detect_framework" do diff --git a/spec/spork/diagnoser_spec.rb b/spec/spork/diagnoser_spec.rb index daf62cc..f37a10a 100644 --- a/spec/spork/diagnoser_spec.rb +++ b/spec/spork/diagnoser_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::Diagnoser do diff --git a/spec/spork/forker_spec.rb b/spec/spork/forker_spec.rb index c2a2f33..2de7669 100644 --- a/spec/spork/forker_spec.rb +++ b/spec/spork/forker_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::Forker do describe ".new" do @@ -37,7 +37,7 @@ sleep 0.5 forker.abort sleep 0.1 - (ended_at - started_at).should be_close(0.5, 0.1) + (ended_at - started_at).should be_within(0.1).of(0.5) forker.running?.should == false end end diff --git a/spec/spork/run_strategy/forking_spec.rb b/spec/spork/run_strategy/forking_spec.rb index baa9396..f7950a7 100644 --- a/spec/spork/run_strategy/forking_spec.rb +++ b/spec/spork/run_strategy/forking_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require 'spec_helper' describe Spork::RunStrategy::Forking do before(:each) do diff --git a/spec/spork/runner_spec.rb b/spec/spork/runner_spec.rb index 05c09e9..8e44e3c 100644 --- a/spec/spork/runner_spec.rb +++ b/spec/spork/runner_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::Runner do def use_test_server(klass = Spork::TestFramework::RSpec) diff --git a/spec/spork/server_spec.rb b/spec/spork/server_spec.rb index f330620..1ddac04 100644 --- a/spec/spork/server_spec.rb +++ b/spec/spork/server_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::Server do describe "a fake server" do diff --git a/spec/spork/test_framework/cucumber_spec.rb b/spec/spork/test_framework/cucumber_spec.rb index 928b05e..eeec335 100644 --- a/spec/spork/test_framework/cucumber_spec.rb +++ b/spec/spork/test_framework/cucumber_spec.rb @@ -1,11 +1,6 @@ -require File.dirname(__FILE__) + '/../../spec_helper' -require File.dirname(__FILE__) + "/../test_framework_shared_examples" +require 'spec_helper' +require 'spork/test_framework_shared_examples' describe Spork::TestFramework::Cucumber do - before(:each) do - @klass = Spork::TestFramework::Cucumber - @server = @klass.new - end - - it_should_behave_like "a TestFramework" + it_behaves_like "a TestFramework" end diff --git a/spec/spork/test_framework/rspec_spec.rb b/spec/spork/test_framework/rspec_spec.rb index c957593..de00b52 100644 --- a/spec/spork/test_framework/rspec_spec.rb +++ b/spec/spork/test_framework/rspec_spec.rb @@ -1,10 +1,6 @@ -require File.dirname(__FILE__) + '/../../spec_helper' -require File.dirname(__FILE__) + "/../test_framework_shared_examples" +require 'spec_helper' +require 'spork/test_framework_shared_examples' describe Spork::TestFramework::RSpec do - before(:each) do - @klass = Spork::TestFramework::RSpec - end - - it_should_behave_like "a TestFramework" + it_behaves_like "a TestFramework" end diff --git a/spec/spork/test_framework_shared_examples.rb b/spec/spork/test_framework_shared_examples.rb index 2880d0c..1872b45 100644 --- a/spec/spork/test_framework_shared_examples.rb +++ b/spec/spork/test_framework_shared_examples.rb @@ -1,14 +1,14 @@ -shared_examples_for "a TestFramework" do +shared_examples "a TestFramework" do describe ".default_port" do it "uses the DEFAULT_PORT when the environment variable is not set" do - @klass.default_port.should == @klass::DEFAULT_PORT + described_class.default_port.should == described_class::DEFAULT_PORT end it 'uses ENV["#{short_name.upcase}_DRB"] as port if present' do - env_name = "#{@klass.short_name.upcase}_DRB" + env_name = "#{described_class.short_name.upcase}_DRB" orig, ENV[env_name] = ENV[env_name], "9000" begin - @klass.default_port.should == 9000 + described_class.default_port.should == 9000 ensure ENV[env_name] = orig end @@ -17,7 +17,7 @@ describe ".helper_file" do it "returns ::HELPER_FILE for the TestFramework" do - @klass.helper_file.should == @klass::HELPER_FILE + described_class.helper_file.should == described_class::HELPER_FILE end end end diff --git a/spec/spork/test_framework_spec.rb b/spec/spork/test_framework_spec.rb index d89044b..896a780 100644 --- a/spec/spork/test_framework_spec.rb +++ b/spec/spork/test_framework_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spork::TestFramework do diff --git a/spec/spork_spec.rb b/spec/spork_spec.rb index 9a1b534..e082673 100644 --- a/spec/spork_spec.rb +++ b/spec/spork_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') +require 'spec_helper' Spork.class_eval do def self.reset!