first burst on rspec support. not done yet.

hard part is done, but it needs some fine-tuning to
run files properly. stay tuned!
This commit is contained in:
Nick Gauthier 2010-04-03 17:27:27 -04:00
parent 282742c0ee
commit c1c44f89d2
5 changed files with 63 additions and 6 deletions

View File

@ -77,7 +77,11 @@ module Hydra #:nodoc:
# Run a ruby file (ending in .rb)
def run_ruby_file(file)
run_test_unit_file(file) + run_rspec_file(file)
if file =~ /_spec.rb$/
return run_rspec_file(file)
else
return run_test_unit_file(file)
end
end
# Run all the Test::Unit Suites in a ruby file
@ -106,11 +110,31 @@ module Hydra #:nodoc:
# run all the Specs in an RSpec file (NOT IMPLEMENTED)
def run_rspec_file(file)
#TODO
# Given the file
# return "" if all the tests passed
# or return the error messages for the entire file
return ""
# TODO:
# 1. do some of this only once, like the requires and stuff
# 2. fork the file loading so that it doesn't get re-run
# 3. test that running two files doesn't re-run the first
# to test 2. above. Like for cucumber
# 4. try this on a real rspec project
begin
require 'spec/autorun'
rescue LoadError => ex
return ex.to_s
end
options = Spec::Runner.options
require 'spec/runner/formatter/progress_bar_formatter'
require 'hydra/spec/hydra_formatter'
hydra_output = StringIO.new
options.formatters = [Spec::Runner::Formatter::HydraFormatter.new(options.formatter_options, hydra_output)]
require file
options.run_examples
hydra_output.rewind
output = hydra_output.read.chomp
output = "" if output == "."
return output
#return `spec #{File.expand_path(file)}`
end
# run all the scenarios in a cucumber feature file

View File

@ -0,0 +1,14 @@
module Spec
module Runner
class Options
attr_accessor :formatters
end
module Formatter
class HydraFormatter < ProgressBarFormatter
def dump_summary(duration, example, failure, pending)
end
end
end
end
end

8
test/fixtures/write_file_spec.rb vendored Normal file
View File

@ -0,0 +1,8 @@
require 'tmpdir'
context "file writing" do
it "writes to a file" do
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
f.write "HYDRA"
end
end
end

View File

@ -55,6 +55,13 @@ class RunnerTest < Test::Unit::TestCase
puts "END IGNORABLE OUTPUT"
end
should "run an rspec test" do
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
runner.run_file(rspec_file)
assert File.exists?(target_file)
assert_equal "HYDRA", File.read(target_file)
end
should "be able to run a runner over ssh" do
ssh = Hydra::SSH.new(
'localhost',

View File

@ -23,6 +23,10 @@ class Test::Unit::TestCase
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file.rb'))
end
def rspec_file
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file_spec.rb'))
end
def cucumber_feature_file
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'features', 'write_file.feature'))
end