Class: Hydra::TestTask

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/tasks.rb

Overview

Define a test task that uses hydra to test the files.

TODO: examples

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :hydra) {|_self| ... } ⇒ TestTask

Create a new HydraTestTask

Yields:

  • (_self)

Yield Parameters:



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

#configObject

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

#filesObject

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

#nameObject

Name of the task. Default ‘hydra’



7
8
9
# File 'lib/hydra/tasks.rb', line 7

def name
  @name
end

#verboseObject

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

#defineObject

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_fileObject

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