2010-01-20 16:58:56 +00:00
|
|
|
require 'rubygems'
|
2011-08-31 15:42:56 +00:00
|
|
|
gem 'test-unit'
|
2010-01-20 16:58:56 +00:00
|
|
|
require 'test/unit'
|
|
|
|
require 'shoulda'
|
2010-01-27 22:19:32 +00:00
|
|
|
require 'tmpdir'
|
2011-06-01 21:29:45 +00:00
|
|
|
require "stringio"
|
2010-01-20 16:58:56 +00:00
|
|
|
|
|
|
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
|
require 'hydra'
|
|
|
|
|
2010-02-10 19:02:19 +00:00
|
|
|
# Since Hydra turns off testing, we have to turn it back on
|
2011-08-05 19:40:39 +00:00
|
|
|
#Test::Unit.run = false
|
2010-02-10 19:02:19 +00:00
|
|
|
|
2010-01-20 16:58:56 +00:00
|
|
|
class Test::Unit::TestCase
|
2010-01-29 19:56:02 +00:00
|
|
|
def target_file
|
2010-06-09 18:24:32 +00:00
|
|
|
File.expand_path(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'))
|
2010-01-29 19:56:02 +00:00
|
|
|
end
|
2010-03-31 15:05:42 +00:00
|
|
|
|
|
|
|
def alternate_target_file
|
2010-06-09 18:24:32 +00:00
|
|
|
File.expand_path(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'))
|
2010-03-31 15:05:42 +00:00
|
|
|
end
|
2010-01-27 20:19:48 +00:00
|
|
|
|
2010-01-29 19:56:02 +00:00
|
|
|
def test_file
|
2010-02-03 21:03:16 +00:00
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file.rb'))
|
2010-01-29 19:56:02 +00:00
|
|
|
end
|
2010-03-30 17:45:10 +00:00
|
|
|
|
2010-04-03 21:27:27 +00:00
|
|
|
def rspec_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file_spec.rb'))
|
|
|
|
end
|
|
|
|
|
2010-04-04 00:32:00 +00:00
|
|
|
def alternate_rspec_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file_alternate_spec.rb'))
|
|
|
|
end
|
|
|
|
|
2010-04-20 10:33:28 +00:00
|
|
|
def rspec_file_with_pending
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'write_file_with_pending_spec.rb'))
|
|
|
|
end
|
|
|
|
|
2010-03-30 17:45:10 +00:00
|
|
|
def cucumber_feature_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'features', 'write_file.feature'))
|
|
|
|
end
|
2010-03-31 15:05:42 +00:00
|
|
|
|
|
|
|
def alternate_cucumber_feature_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'features', 'write_alternate_file.feature'))
|
|
|
|
end
|
2010-05-28 14:38:58 +00:00
|
|
|
|
|
|
|
def javascript_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'js_file.js'))
|
|
|
|
end
|
2010-05-28 14:42:17 +00:00
|
|
|
|
|
|
|
def json_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'json_data.json'))
|
|
|
|
end
|
2010-08-28 02:35:11 +00:00
|
|
|
|
|
|
|
def conflicting_test_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'conflicting.rb'))
|
|
|
|
end
|
2011-05-30 17:40:44 +00:00
|
|
|
|
|
|
|
def remote_dir_path
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
end
|
2011-06-01 16:45:43 +00:00
|
|
|
|
|
|
|
def hydra_worker_init_file
|
|
|
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'hydra_worker_init.rb'))
|
|
|
|
end
|
|
|
|
|
2011-06-01 21:29:45 +00:00
|
|
|
def capture_stderr
|
|
|
|
# The output stream must be an IO-like object. In this case we capture it in
|
|
|
|
# an in-memory IO object so we can return the string value. You can assign any
|
|
|
|
# IO object here.
|
|
|
|
previous_stderr, $stderr = $stderr, StringIO.new
|
|
|
|
yield
|
|
|
|
$stderr.string
|
|
|
|
ensure
|
|
|
|
# Restore the previous value of stderr (typically equal to STDERR).
|
|
|
|
$stderr = previous_stderr
|
|
|
|
end
|
|
|
|
|
2011-06-01 16:45:43 +00:00
|
|
|
#this method allow us to wait for a file for a maximum number of time, so the
|
|
|
|
#test can pass in slower machines. This helps to speed up the tests
|
2011-06-02 19:02:58 +00:00
|
|
|
def assert_file_exists file, time_to_wait = 2
|
2011-06-01 16:45:43 +00:00
|
|
|
time_begin = Time.now
|
|
|
|
|
|
|
|
until Time.now - time_begin >= time_to_wait or File.exists?( file ) do
|
|
|
|
sleep 0.01
|
|
|
|
end
|
2011-06-02 19:02:58 +00:00
|
|
|
|
|
|
|
assert File.exists?( file )
|
2011-06-01 16:45:43 +00:00
|
|
|
end
|
2010-01-29 19:56:02 +00:00
|
|
|
end
|
2010-01-29 18:01:53 +00:00
|
|
|
|
2010-01-27 20:19:48 +00:00
|
|
|
module Hydra #:nodoc:
|
|
|
|
module Messages #:nodoc:
|
|
|
|
class TestMessage < Hydra::Message
|
|
|
|
attr_accessor :text
|
|
|
|
def initialize(opts = {})
|
|
|
|
@text = opts.fetch(:text){ "test" }
|
|
|
|
end
|
|
|
|
def serialize
|
|
|
|
super(:text => @text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|