From b831522a47e6785cf5e2054058f2e92a18fcefc8 Mon Sep 17 00:00:00 2001 From: Nick Gauthier Date: Sat, 3 Apr 2010 21:43:35 -0400 Subject: [PATCH] almost done with rspec integration. rspec is still running its at_exit --- hydra.gemspec | 21 +++++++++++++-------- lib/hydra/message/runner_messages.rb | 3 +++ lib/hydra/runner.rb | 10 ++++++---- lib/hydra/safe_fork.rb | 8 ++++++++ lib/hydra/spec/hydra_formatter.rb | 1 + lib/hydra/tasks.rb | 1 + 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/hydra.gemspec b/hydra.gemspec index 4c7c7f7..135818c 100644 --- a/hydra.gemspec +++ b/hydra.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Nick Gauthier"] - s.date = %q{2010-03-31} + s.date = %q{2010-04-03} s.description = %q{Spread your tests over multiple machines to test your code faster.} s.email = %q{nick@smartlogicsolutions.com} s.extra_rdoc_files = [ @@ -46,6 +46,7 @@ Gem::Specification.new do |s| "lib/hydra/pipe.rb", "lib/hydra/runner.rb", "lib/hydra/safe_fork.rb", + "lib/hydra/spec/hydra_formatter.rb", "lib/hydra/ssh.rb", "lib/hydra/stdio.rb", "lib/hydra/tasks.rb", @@ -60,6 +61,8 @@ Gem::Specification.new do |s| "test/fixtures/slow.rb", "test/fixtures/sync_test.rb", "test/fixtures/write_file.rb", + "test/fixtures/write_file_alternate_spec.rb", + "test/fixtures/write_file_spec.rb", "test/master_test.rb", "test/message_test.rb", "test/pipe_test.rb", @@ -71,22 +74,24 @@ Gem::Specification.new do |s| s.homepage = %q{http://github.com/ngauthier/hydra} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.5} + s.rubygems_version = %q{1.3.6} s.summary = %q{Distributed testing toolkit} s.test_files = [ - "test/message_test.rb", + "test/pipe_test.rb", "test/test_helper.rb", "test/ssh_test.rb", + "test/message_test.rb", + "test/master_test.rb", "test/fixtures/write_file.rb", "test/fixtures/slow.rb", + "test/fixtures/write_file_spec.rb", + "test/fixtures/features/step_definitions.rb", + "test/fixtures/hello_world.rb", + "test/fixtures/write_file_alternate_spec.rb", "test/fixtures/sync_test.rb", "test/fixtures/assert_true.rb", - "test/fixtures/hello_world.rb", - "test/fixtures/features/step_definitions.rb", - "test/master_test.rb", - "test/worker_test.rb", "test/runner_test.rb", - "test/pipe_test.rb" + "test/worker_test.rb" ] if s.respond_to? :specification_version then diff --git a/lib/hydra/message/runner_messages.rb b/lib/hydra/message/runner_messages.rb index 4010ed1..119447c 100644 --- a/lib/hydra/message/runner_messages.rb +++ b/lib/hydra/message/runner_messages.rb @@ -37,6 +37,9 @@ module Hydra #:nodoc: class RSpecResult < Hydra::Message # the output of the spec attr_accessor :output + def serialize #:nodoc: + super(:output => @output) + end end end end diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb index 187cf66..0ec2861 100644 --- a/lib/hydra/runner.rb +++ b/lib/hydra/runner.rb @@ -103,9 +103,10 @@ module Hydra #:nodoc: # run all the Specs in an RSpec file (NOT IMPLEMENTED) def run_rspec_file(file) + puts "RUNNING: #{file}" # pull in rspec begin - require 'spec/autorun' + require 'spec' require 'hydra/spec/hydra_formatter' rescue LoadError => ex return ex.to_s @@ -121,17 +122,18 @@ module Hydra #:nodoc: hydra_output = StringIO.new options.formatters = [Spec::Runner::Formatter::HydraFormatter.new(options.formatter_options, hydra_output)] require file + options.files = [file] options.run_examples hydra_output.rewind output = hydra_output.read.chomp - output = "" if output == "." + output = "" if output =~ /^\.*$/ pipe.write RSpecResult.new(:output => output) pipe.close end pipe.identify_as_parent - output = pipe.gets + output_message = pipe.gets Process.wait pid - return output + return output_message.output end # run all the scenarios in a cucumber feature file diff --git a/lib/hydra/safe_fork.rb b/lib/hydra/safe_fork.rb index f98aecb..71cc83b 100644 --- a/lib/hydra/safe_fork.rb +++ b/lib/hydra/safe_fork.rb @@ -7,7 +7,11 @@ class SafeFork child = Process.fork do begin # create a new connection and perform the action + begin ActiveRecord::Base.establish_connection if defined?(ActiveRecord) + rescue ActiveRecord::AdapterNotSpecified + # AR was defined but we didn't have a connection + end yield ensure # make sure we remove the connection before we're done @@ -16,7 +20,11 @@ class SafeFork end ensure # make sure we re-establish the connection before returning to the main instance + begin ActiveRecord::Base.establish_connection if defined?(ActiveRecord) + rescue ActiveRecord::AdapterNotSpecified + # AR was defined but we didn't have a connection + end end return child end diff --git a/lib/hydra/spec/hydra_formatter.rb b/lib/hydra/spec/hydra_formatter.rb index a19a2e4..f9004fa 100644 --- a/lib/hydra/spec/hydra_formatter.rb +++ b/lib/hydra/spec/hydra_formatter.rb @@ -4,6 +4,7 @@ module Spec module Runner class Options attr_accessor :formatters + attr_accessor :files end module Formatter class HydraFormatter < ProgressBarFormatter diff --git a/lib/hydra/tasks.rb b/lib/hydra/tasks.rb index 295749b..276a2b5 100644 --- a/lib/hydra/tasks.rb +++ b/lib/hydra/tasks.rb @@ -95,6 +95,7 @@ module Hydra #:nodoc: desc "Hydra Tests" + (@name == :hydra ? "" : " for #{@name}") task @name do Hydra::Master.new(@opts) + puts "OK AND QUIT" exit(0) #bypass test on_exit output end end