Class: BarkingIguana::Compound::TestSuite

Inherits:
Object
  • Object
show all
Includes:
Benchmark, Logging::Helper
Defined in:
lib/barking_iguana/compound/test_suite.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = nil, control_directory: nil) ⇒ TestSuite

Returns a new instance of TestSuite.



47
48
49
50
# File 'lib/barking_iguana/compound/test_suite.rb', line 47

def initialize(directory = nil, control_directory: nil)
  self.control_directory = control_directory || guess_directory
  self.directory = directory || File.expand_path("test/compound", control_directory)
end

Instance Attribute Details

#control_directoryObject

Returns the value of attribute control_directory.



41
42
43
# File 'lib/barking_iguana/compound/test_suite.rb', line 41

def control_directory
  @control_directory
end

#directoryObject

Returns the value of attribute directory.



44
45
46
# File 'lib/barking_iguana/compound/test_suite.rb', line 44

def directory
  @directory
end

Class Method Details

.define_rake_tasksObject



4
5
6
# File 'lib/barking_iguana/compound/test_suite.rb', line 4

def self.define_rake_tasks
  new.define_rake_tasks
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/barking_iguana/compound/test_suite.rb', line 37

def debug?
  ENV['DEBUG'].to_s != ''
end

#define_rake_tasksObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/barking_iguana/compound/test_suite.rb', line 8

def define_rake_tasks
  Rake::Task.define_task name do
    run
  end.add_description "Run #{name} suite"

  tests.each do |test|
    Rake::Task.define_task "#{name}:#{test.name}" do
      test.run
    end.add_description "Run #{test.name} test from #{name} suite"

    if debug?
      test.stages.each do |stage|
        Rake::Task.define_task "#{name}:#{test.name}:#{stage.name}" do
          stage.run
        end.add_description "Run #{stage.name} stage of the #{test.name} test from #{name} suite"
        stage.actions.each do |action|
          Rake::Task.define_task "#{name}:#{test.name}:#{stage.name}:#{action}" do
            stage.public_send action
          end.add_description "Run action #{action} for #{stage.name} stage of the #{test.name} test from #{name} suite"
        end
      end

      Rake::Task.define_task "#{name}:#{test.name}:destroy" do
        test.teardown
      end.add_description "Tear down #{test.name} test from #{name} suite"
    end
  end
end

#environmentObject



81
82
83
# File 'lib/barking_iguana/compound/test_suite.rb', line 81

def environment
  @environment ||= Environment.new(environment_file)
end

#environment_fileObject



77
78
79
# File 'lib/barking_iguana/compound/test_suite.rb', line 77

def environment_file
  File.join directory, 'env'
end

#guess_directoryObject



52
53
54
55
56
57
58
# File 'lib/barking_iguana/compound/test_suite.rb', line 52

def guess_directory
  caller.detect do |trace|
    path = trace.split(/:/, 2)[0]
    file = File.basename path
    break File.dirname path if file == 'Rakefile'
  end
end

#nameObject



64
65
66
# File 'lib/barking_iguana/compound/test_suite.rb', line 64

def name
  File.basename directory
end

#runObject



71
72
73
74
75
# File 'lib/barking_iguana/compound/test_suite.rb', line 71

def run
  benchmark name do
    tests.each &:run
  end
end

#testsObject



60
61
62
# File 'lib/barking_iguana/compound/test_suite.rb', line 60

def tests
  test_directories.map { |d| Test.new self, d }
end