Class: LimitedRed::Cucumber::Formatter::Stats

Inherits:
Cucumber::Formatter::Json
  • Object
show all
Defined in:
lib/limited_red/cucumber/formatter/stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, path_or_io, options) ⇒ Stats

Returns a new instance of Stats.



10
11
12
13
14
15
16
17
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 10

def initialize(step_mother, path_or_io, options)
  @t = Time.now
  @build_id = Time.now.to_i
  @step_mother = step_mother
  @client = LimitedRed::Client.new(LimitedRed::Config.load_and_validate_config('cucumber'))

  super
end

Instance Method Details

#after_feature(feature) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 19

def after_feature(feature)
  if supports_feature_hash?
    json = feature_hash.to_json
    @client.log_result(@build_id, :result => json, :uri => feature_hash['uri'])
  else
    puts "[limited_red]:Error: Having trouble working with your Gherkin version. Is it upto date? Report this to [email protected], its his fault.", ""
  end
end

#after_features(features) ⇒ Object



28
29
30
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 28

def after_features(features)
  print_summary
end

#failing_filesObject



39
40
41
42
43
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 39

def failing_files
  failures = @step_mother.scenarios(:failed).select { |s| s.is_a?(::Cucumber::Ast::Scenario) || s.is_a?(::Cucumber::Ast::OutlineTable::ExampleRow) }
  failures = failures.collect { |s| (s.is_a?(::Cucumber::Ast::OutlineTable::ExampleRow)) ? s.scenario_outline : s }
  failures.map{|fail| fail.file_colon_line}
end

#feature_hashObject



55
56
57
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 55

def feature_hash
  gherkin_formatter.instance_variable_get("@feature_hash") || gherkin_formatter.instance_variable_get(:@feature_hash)
end

#gherkin_formatterObject



59
60
61
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 59

def gherkin_formatter
  @gf
end

#passing_filesObject



45
46
47
48
49
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 45

def passing_files
  passing = @step_mother.scenarios(:passed).select { |s| s.is_a?(::Cucumber::Ast::Scenario) || s.is_a?(::Cucumber::Ast::OutlineTable::ExampleRow) }
  passing = passing.collect { |s| (s.is_a?(::Cucumber::Ast::OutlineTable::ExampleRow)) ? s.scenario_outline : s }
  passing.map{|pass| pass.file_colon_line}
end


32
33
34
35
36
37
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 32

def print_summary
   @client.log_build(@build_id, {:fails => failing_files, 
                                 :passes => passing_files})
                                           
  ThreadPool.wait_for_all_threads_to_finish
end

#supports_feature_hash?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/limited_red/cucumber/formatter/stats.rb', line 51

def supports_feature_hash?
  gherkin_formatter.instance_variables.include?(:@feature_hash) || gherkin_formatter.instance_variables.include?('@feature_hash')
end