Skip to content

Commit

Permalink
support rspec versions 1.x and >= 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 28, 2011
1 parent 107589c commit c4a3819
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/spork/test_framework/rspec.rb
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
25 changes: 25 additions & 0 deletions spec/spork/test_framework/rspec_spec.rb
Expand Up @@ -3,4 +3,29 @@

describe Spork::TestFramework::RSpec do
it_behaves_like "a TestFramework"

it "supports rspec 1.x" do
begin
Object.const_set(:Spec, Module.new)
Spec.const_set(:Runner, Module.new)
Spec::Runner.const_set(:CommandLine, Module.new)
Spec::Runner.const_set(:OptionParser, Module.new)
Spec::Runner::OptionParser.stub(:parse)

framework = Spork::TestFramework::RSpec.new
framework.stub(:rspec1?).and_return(true)

Spec::Runner::CommandLine.should_receive(:run)

framework.run_tests([],StringIO.new,StringIO.new)
ensure
Object.__send__(:remove_const, :Spec)
end
end

it "supports rspec >= 2.0" do
RSpec::Core::CommandLine.any_instance.should_receive(:run)
framework = Spork::TestFramework::RSpec.new
framework.run_tests([],StringIO.new,StringIO.new)
end
end

0 comments on commit c4a3819

Please sign in to comment.