Class: Buildr::TestFramework::TestResult::YamlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/buildr/java/test_result.rb

Overview

An Rspec formatter used by buildr

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, where) ⇒ YamlFormatter

Returns a new instance of YamlFormatter.



60
61
62
63
64
65
66
# File 'lib/buildr/java/test_result.rb', line 60

def initialize(options, where)
  @options = options
  @where = where
  @result = Hash.new
  @result[:succeeded] = []
  @result[:failed] = []
end

Instance Attribute Details

#example_groupObject

Returns the value of attribute example_group.



58
59
60
# File 'lib/buildr/java/test_result.rb', line 58

def example_group
  @example_group
end

#optionsObject

Returns the value of attribute options.



58
59
60
# File 'lib/buildr/java/test_result.rb', line 58

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



56
57
58
# File 'lib/buildr/java/test_result.rb', line 56

def result
  @result
end

#whereObject

Returns the value of attribute where.



58
59
60
# File 'lib/buildr/java/test_result.rb', line 58

def where
  @where
end

Instance Method Details

#add_example_group(example_group) ⇒ Object



73
74
75
# File 'lib/buildr/java/test_result.rb', line 73

def add_example_group(example_group)
  @example_group = example_group
end

#closeObject



106
107
108
109
110
111
112
# File 'lib/buildr/java/test_result.rb', line 106

def close
  files = options.files
  result.succeeded = files - result.failed
  
  FileUtils.mkdir_p(File.dirname(where))
  File.open(where, 'w') { |f| f.puts YAML.dump(result) }
end

#example_failed(example, counter, failure) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/buildr/java/test_result.rb', line 83

def example_failed(example, counter, failure)
  if example_group.respond_to?(:spec_path)
    result.failed << example_group.spec_path.gsub(/:\d+$/, '')
  else
    path = path_from_bt(failure.exception.backtrace)
    result.failed << path if path
  end
end

#example_passed(example) ⇒ Object



77
78
# File 'lib/buildr/java/test_result.rb', line 77

def example_passed(example)
end

#example_pending(example, counter, failure) ⇒ Object



80
81
# File 'lib/buildr/java/test_result.rb', line 80

def example_pending(example, counter, failure)
end

#path_from_bt(ary) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/buildr/java/test_result.rb', line 96

def path_from_bt(ary)
  files = options.files
  test = nil
  ary.find do |bt|
    bt = bt.split(':').first.strip
    test = bt if files.include?(bt)
  end
  test
end

#start(example_count) ⇒ Object



92
93
94
# File 'lib/buildr/java/test_result.rb', line 92

def start(example_count)
  @result = TestResult.new
end