Class: Crew::Tester

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/crew/tester.rb,
lib/crew/tester/dsl.rb,
lib/crew/tester/preparer.rb,
lib/crew/tester/preparer/dsl.rb

Defined Under Namespace

Classes: DSL, Preparer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#assert, #escape, #logger, #poll, #retryable

Constructor Details

#initialize(home, name, &blk) ⇒ Tester

Returns a new instance of Tester.



7
8
9
10
11
12
13
# File 'lib/crew/tester.rb', line 7

def initialize(home, name, &blk)
  @name = name
  @home = home
  @context_name = "#{@name}_test"
  @preparers = {}
  DSL.new(self).load(&blk)
end

Instance Attribute Details

#hintsObject

Returns the value of attribute hints.



5
6
7
# File 'lib/crew/tester.rb', line 5

def hints
  @hints
end

Instance Method Details

#add_preparer(name, &blk) ⇒ Object



48
49
50
51
# File 'lib/crew/tester.rb', line 48

def add_preparer(name, &blk)
  @preparers[name] = Preparer.new(name)
  @preparers[name].load(&blk)
end

#context(name, &blk) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/crew/tester.rb', line 15

def context(name, &blk)
  if name
    @context_name = name
  else
    @home.add_context @context_name, &blk
  end
end

#run(opts) ⇒ Object



23
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/crew/tester.rb', line 23

def run(opts)
  return if opts[:context_name] && @name != opts[:context_name]

  prepare(opts[:force_prepare])

  task_count = 0
  test_results = {}

  @home.each_task do |task|
    next unless opts[:test_name].nil? or opts[:test_name] == task.name

    preparer = @preparers.values.find {|p| p.match?(task.name)}
    raise "couldn't find preparer for task `#{task.name}'" unless preparer

    @home.in_context(@context_name) do
      @home.setup_mode = true
      @home.context.snapshot_name = preparer.name
      task.context = @home.context
      task.test!(self, opts) do |result|
        display_result result
      end
    end
  end
end