Class: Attest::TestParser

Inherits:
Object show all
Defined in:
lib/attest/test_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(description, block) ⇒ TestParser

Returns a new instance of TestParser.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/attest/test_parser.rb', line 8

def initialize(description, block)
  @description = description
  @block = block
  @before_all = nil
  @after_all = nil
  @before = nil
  @after = nil
  @tests = {}
  @nosetup_tests = {}
  @disabled_tests = {}
  @freestyle_tests = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



65
66
67
68
69
70
# File 'lib/attest/test_parser.rb', line 65

def method_missing(name, *args, &block)
  unless Attest::ExecutionContext.assertions.include? name
    super
  end
  @freestyle_tests << {:method_name => name, :args => args, :block => block}
end

Instance Method Details

#after_all(&block) ⇒ Object



33
34
35
# File 'lib/attest/test_parser.rb', line 33

def after_all(&block)
  @after_all = block
end

#after_each(&block) ⇒ Object



41
42
43
# File 'lib/attest/test_parser.rb', line 41

def after_each(&block)
  @after = block
end

#before_all(&block) ⇒ Object



29
30
31
# File 'lib/attest/test_parser.rb', line 29

def before_all(&block)
  @before_all = block
end

#before_each(&block) ⇒ Object



37
38
39
# File 'lib/attest/test_parser.rb', line 37

def before_each(&block)
  @before = block 
end

#disabledObject



61
62
63
# File 'lib/attest/test_parser.rb', line 61

def disabled
  @next_test_disabled = true
end

#nosetupObject



57
58
59
# File 'lib/attest/test_parser.rb', line 57

def nosetup
  @next_test_without_setup = true
end

#parseObject



21
22
23
24
25
26
27
# File 'lib/attest/test_parser.rb', line 21

def parse
  self.instance_eval(&@block)
  test_container = Attest::TestContainer.new(@description)
  build_test_objects_and_add_to_container test_container
  build_freestyle_test_objects_and_add_to test_container
  test_container
end

#test(description, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/attest/test_parser.rb', line 45

def test(description, &block)
  if @next_test_without_setup
    @nosetup_tests[description] = true
  end
  if @next_test_disabled
    @disabled_tests[description] = true
  end
  @tests[description] = block
  @next_test_without_setup = false
  @next_test_disabled = false
end