Skip to content

Commit

Permalink
upgrade to rspec-2.6 and update specs to newer conventions
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dchelimsky committed May 28, 2011
1 parent d8a9a42 commit 107589c
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 139 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
37 changes: 22 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -36,5 +43,5 @@ PLATFORMS
DEPENDENCIES
cucumber (= 0.10.2)
rake
rspec (= 2.5.0)
ruby-debug
rspec (~> 2.6)
ruby-debug19
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
176 changes: 85 additions & 91 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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) }
2 changes: 1 addition & 1 deletion spec/spork/app_framework/rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'spec_helper'

describe Spork::AppFramework::Rails do
describe ".deprecated_version" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/app_framework/unknown_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'spec_helper'

describe Spork::AppFramework::Unknown do
it "requires bootstrapping" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/app_framework_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'spec_helper'

describe Spork::AppFramework do
describe ".detect_framework" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/diagnoser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'spec_helper'


describe Spork::Diagnoser do
Expand Down
4 changes: 2 additions & 2 deletions spec/spork/forker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'spec_helper'

describe Spork::Forker do
describe ".new" do
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/run_strategy/forking_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'spec_helper'

describe Spork::RunStrategy::Forking do
before(:each) do
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/spork/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'spec_helper'

describe Spork::Server do
describe "a fake server" do
Expand Down
11 changes: 3 additions & 8 deletions spec/spork/test_framework/cucumber_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions spec/spork/test_framework/rspec_spec.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions spec/spork/test_framework_shared_examples.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/spork/test_framework_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'spec_helper'

describe Spork::TestFramework do

Expand Down
Loading

0 comments on commit 107589c

Please sign in to comment.