Skip to content

Commit

Permalink
Merge pull request sporkrb#121 from dchelimsky/support-rspec2
Browse files Browse the repository at this point in the history
Support rspec2
  • Loading branch information
timcharper committed May 28, 2011
2 parents d8a9a42 + c4a3819 commit b15cfd2
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 143 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
16 changes: 10 additions & 6 deletions lib/spork/test_framework/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ class Spork::TestFramework::RSpec < Spork::TestFramework
HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")

def run_tests(argv, stderr, stdout)
::Spec::Runner::CommandLine.run(
::Spec::Runner::OptionParser.parse(
argv,
stderr,
stdout
if rspec1?
::Spec::Runner::CommandLine.run(
::Spec::Runner::OptionParser.parse(argv, stderr, stdout)
)
)
else
::RSpec::Core::CommandLine.new(argv).run(stderr, stdout)
end
end

def rspec1?
defined?(Spec) && !defined?(RSpec)
end
end
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
Loading

0 comments on commit b15cfd2

Please sign in to comment.