Class: Hydra::TestTask
- Inherits:
-
Object
- Object
- Hydra::TestTask
- Defined in:
- lib/hydra/tasks.rb
Overview
Define a test task that uses hydra to test the files.
TODO: examples
Instance Attribute Summary collapse
-
#config ⇒ Object
Path to the hydra config file.
-
#files ⇒ Object
Files to test.
-
#name ⇒ Object
Name of the task.
-
#verbose ⇒ Object
True if you want to see Hydra’s message traces.
Instance Method Summary collapse
-
#add_files(pattern) ⇒ Object
Add files to test by passing in a string to be run through Dir.glob.
-
#define ⇒ Object
Create the rake task defined by this HydraTestTask.
-
#find_config_file ⇒ Object
Search for the hydra config file.
-
#initialize(name = :hydra) {|_self| ... } ⇒ TestTask
constructor
Create a new HydraTestTask.
Constructor Details
#initialize(name = :hydra) {|_self| ... } ⇒ TestTask
Create a new HydraTestTask
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hydra/tasks.rb', line 24 def initialize(name = :hydra) @name = name @files = [] @verbose = false yield self if block_given? @config = find_config_file @opts = { :verbose => @verbose, :files => @files } if @config @opts.merge!(:config => @config) else $stderr.write "Hydra: No configuration file found at 'hydra.yml' or 'config/hydra.yml'\n" $stderr.write "Hydra: Using default configuration for a single-core machine\n" @opts.merge!(:workers => [{:type => :local, :runners => 1}]) end define end |
Instance Attribute Details
#config ⇒ Object
Path to the hydra config file. If not set, it will check ‘hydra.yml’ and ‘config/hydra.yml’
21 22 23 |
# File 'lib/hydra/tasks.rb', line 21 def config @config end |
#files ⇒ Object
Files to test. You can add files manually via:
t.files << [file1, file2, etc]
Or you can use the add_files method
14 15 16 |
# File 'lib/hydra/tasks.rb', line 14 def files @files end |
#name ⇒ Object
Name of the task. Default ‘hydra’
7 8 9 |
# File 'lib/hydra/tasks.rb', line 7 def name @name end |
#verbose ⇒ Object
True if you want to see Hydra’s message traces
17 18 19 |
# File 'lib/hydra/tasks.rb', line 17 def verbose @verbose end |
Instance Method Details
#add_files(pattern) ⇒ Object
Add files to test by passing in a string to be run through Dir.glob. For example:
t.add_files 'test/units/*.rb'
63 64 65 |
# File 'lib/hydra/tasks.rb', line 63 def add_files(pattern) @files += Dir.glob(pattern) end |
#define ⇒ Object
Create the rake task defined by this HydraTestTask
49 50 51 52 53 54 55 56 57 |
# File 'lib/hydra/tasks.rb', line 49 def define desc "Hydra Tests" + (@name == :hydra ? "" : " for #{@name}") task @name do $stdout.write "Hydra Testing #{files.inspect}\n" Hydra::Master.new(@opts) $stdout.write "\nHydra Completed\n" exit(0) #bypass test on_exit output end end |
#find_config_file ⇒ Object
Search for the hydra config file
68 69 70 71 72 73 74 |
# File 'lib/hydra/tasks.rb', line 68 def find_config_file @config ||= 'hydra.yml' return @config if File.exists?(@config) @config = File.join('config', 'hydra.yml') return @config if File.exists?(@config) @config = nil end |