Module: XCPretty::Printer

Includes:
ANSI, Matchers
Included in:
RSpec, Simple
Defined in:
lib/xcpretty/printer.rb,
lib/xcpretty/printers/rspec.rb,
lib/xcpretty/printers/simple.rb

Defined Under Namespace

Modules: Matchers Classes: RSpec, Simple

Constant Summary

Constants included from Matchers

Matchers::EXECUTED_MATCHER, Matchers::FAILING_TEST_MATCHER, Matchers::PASSING_TEST_MATCHER, Matchers::TESTS_RUN_COMPLETION_MATCHER, Matchers::TESTS_RUN_START_MATCHER, Matchers::TEST_SUITE_START_MATCHER

Constants included from ANSI

ANSI::COLORS, ANSI::EFFECT, ANSI::FORMATTED_MATCHER

Instance Attribute Summary

Attributes included from ANSI

#colorize

Instance Method Summary collapse

Methods included from ANSI

#ansi_parse, #applied_effects, #colorize?, #cyan, #green, #red, #strip, #white, #yellow

Instance Method Details

#failures_per_suiteObject



111
112
113
# File 'lib/xcpretty/printer.rb', line 111

def failures_per_suite
  @failures ||= {}
end

#format_test_summary(text) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/xcpretty/printer.rb', line 68

def format_test_summary(text)
  if text =~ EXECUTED_MATCHER && @tests_done && !@printed_summary
    @printed_summary = true
    test_summary(text)
  else
    ""
  end
end

#optional_newlineObject



77
78
79
# File 'lib/xcpretty/printer.rb', line 77

def optional_newline
  ""
end

#pretty_print(text) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/xcpretty/printer.rb', line 47

def pretty_print(text)
  update_test_state(text)
  formatted_text = pretty_format(text)
  formatted_text = format_test_summary(text) if formatted_text.empty?

  STDOUT.print(formatted_text + optional_newline) unless formatted_text.empty?
end

#project_build_info(text) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xcpretty/printer.rb', line 81

def project_build_info(text)
  target = text.split('TARGET').last.split('OF PROJECT').first
  clean_target = target.split('-').last.strip
  project = text.split('OF PROJECT').last.split('WITH').first.strip
  configuration = text.split('CONFIGURATION').last.split('===').first.strip
  {
    :target => clean_target,
    :project => project,
    :configuration => configuration
  }
end

#store_failure(file, test_suite, test_case, reason) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/xcpretty/printer.rb', line 115

def store_failure(file, test_suite, test_case, reason)
  failures_per_suite[test_suite] ||= []
  failures_per_suite[test_suite] << {
    :file => cyan(file),
    :reason => red(reason),
    :test_case => test_case,
  }
end

#test_summary(executed_message) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/xcpretty/printer.rb', line 93

def test_summary(executed_message)
  formatted_suites = failures_per_suite.map do |suite, failures|
    formatted_failures = failures.map do |f|
      "  #{f[:test_case]}, #{f[:reason]}\n  #{f[:file]}"
    end.join("\n\n")

    "#{suite}\n#{formatted_failures}"
  end

  final_message = if colorize?
                    formatted_suites.any? ? red(executed_message) : green(executed_message)
                  else
                    executed_message
                  end
  text = [formatted_suites, final_message].join("\n\n\n").strip
  "\n\n#{text}"
end

#update_test_state(text) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/xcpretty/printer.rb', line 55

def update_test_state(text)
  case text
  when TESTS_RUN_START_MATCHER
    @tests_done = false
    @printed_summary = false
    @failures = {}
  when TESTS_RUN_COMPLETION_MATCHER
    @tests_done = true
  when FAILING_TEST_MATCHER
    store_failure($1, $2, $3, $4)
  end
end

#use_unicode=(bool) ⇒ Object



39
40
41
# File 'lib/xcpretty/printer.rb', line 39

def use_unicode=(bool)
  @use_unicode = !!bool
end

#use_unicode?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/xcpretty/printer.rb', line 43

def use_unicode?
  !!@use_unicode
end