Class: ActiveGuide::Test

Inherits:
Item
  • Object
show all
Defined in:
lib/active_guide/test.rb

Instance Attribute Summary collapse

Attributes inherited from Item

#accept_block, #after_block, #before_block, #name, #parent

Instance Method Summary collapse

Methods inherited from Item

#accept, #after, #before, #guide, #unique_name

Constructor Details

#initialize(parent, name, options = {}, &block) ⇒ Test

Returns a new instance of Test.


5
6
7
8
9
10
# File 'lib/active_guide/test.rb', line 5

def initialize(parent, name, options = {}, &block)
  super parent, name, options
  @subtests = []
  validate(&options.delete(:validate)) if options[:validate].respond_to?(:call)
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#subtestsObject (readonly)

Returns the value of attribute subtests


3
4
5
# File 'lib/active_guide/test.rb', line 3

def subtests
  @subtests
end

#validate_blockObject (readonly)

Returns the value of attribute validate_block


3
4
5
# File 'lib/active_guide/test.rb', line 3

def validate_block
  @validate_block
end

Instance Method Details

#subtest(name, *args, &block) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_guide/test.rb', line 20

def subtest(name, *args, &block)
  if @validate_block.present?
    raise "Validation has been already defined in #{@name}"
  end
  options = args.extract_options!
  test = nil
  if block_given?
    test = Test.new(self, name, options, &block)
  elsif (proc = args.shift) && proc.respond_to?(:call)
    test = Test.new(self, name, options.merge(validate: proc))
  else
    raise "Cannot do anything with test #{name}"
  end
  @subtests << test
end

#subtest?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/active_guide/test.rb', line 12

def subtest?
  @subtests.any?
end

#validate(&block) ⇒ Object


36
37
38
39
# File 'lib/active_guide/test.rb', line 36

def validate(&block)
  raise "Sub-test has been already defined in #{@name}" if @subtests.any?
  @validate_block = block
end

#validate?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/active_guide/test.rb', line 16

def validate?
  !subtest?
end