xcpretty 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc82776a1b5b7af57ec1112e3272f12a6942513b
4
- data.tar.gz: 521c086a0311bf369acd88e7edf6ca3730ae6389
3
+ metadata.gz: b331eae2bee45d93e2fa2f33485126e2f64bdbbd
4
+ data.tar.gz: b017362f2060e5a0b0f9e84b231bc9ab47e4e46e
5
5
  SHA512:
6
- metadata.gz: c9e3c17930e218fea3f34d5d8ea42b279d269c3869616c039ce84f356bdb9ac9528a3800d1fc25fcba975776036edc3ef0fb27894d0edbf0ea9a415603865d5a
7
- data.tar.gz: 6d1274dbbf1824d65e07cf802d4f5795276e850778e24c2f82d07a47fb822d37761eebba5b2286a71ddcfae6c8b46f058160077bc96211c1c3a1dd3c65028af6
6
+ metadata.gz: 5754797a03a00904e8959a8cb7803bb30a7faaea12413e966c176a5f0157d16254afb5dfebe5b0053d5d4672c2ac52ceebd7d51175533c416544128bb999d614
7
+ data.tar.gz: 603f9a32654dea4a174b11a81ff26c783da32d3aee6e4174d4ffa8528d927c5312bbc807be1d7eb4676f9d537b247b8c1cd01dfd168d05b8f587c06ae7585c8e
@@ -35,6 +35,10 @@
35
35
  .test .title { float: left; font-size: 0.9em; margin-top: 8px; font-family: Menlo, Monaco, monospace;}
36
36
  .test .time { float: left;margin: 4px 10px 0 20px;}
37
37
  .test-detail { font-family:Menlo, Monaco, monospace; font-size: 0.9em; margin: 5px 0 5px 0px;}
38
+ .screenshots { height: auto; overflow: hidden; padding: 4px 4px 0 4px; background-color: #B8E986; border: #A1D761; border-width: 0 1px; border-style: solid; }
39
+ .screenshots.failing { border-color: #C84F5E; background-color: #E58591; }
40
+ .screenshot { max-height: 60px; float: left; transition: max-height 0.2s; margin: 0 4px 4px 0 }
41
+ .screenshot.selected { max-height: 568px; }
38
42
  #test-suites { display: inline-block; width: 100%;margin-top:100px;}
39
43
  #segment-bar { margin-top: 10px;margin-left: 14px;float:right;}
40
44
  #segment-bar a:first-child { border-radius: 9px 0 0 9px; border-right: none;}
@@ -92,6 +96,10 @@
92
96
  showAll(document.querySelectorAll('.test-suite.passing'));
93
97
  }
94
98
  }
99
+ var toggleScreenshot = function(suiteName, index) {
100
+ var screenshot = document.getElementById("screenshot-" + suiteName + "-" + index);
101
+ isSelected(screenshot) ? deselect(screenshot) : select(screenshot);
102
+ }
95
103
  </script>
96
104
  </head>
97
105
  <body>
@@ -119,6 +127,15 @@
119
127
  <h3 class="title"><%= name %></h3>
120
128
  </section>
121
129
  <section class="tests">
130
+ <% unless info[:screenshots].empty? %>
131
+ <div class="screenshots <%= info[:failing] ? 'failing' : 'passing'%>">
132
+ <% info[:screenshots].each_with_index do |screenshot, index| %>
133
+ <a href="javascript:toggleScreenshot('<%=name %>', <%=index %>)">
134
+ <img class="screenshot" id="screenshot-<%=name %>-<%=index %>" src="<%=screenshot %>" />
135
+ </a>
136
+ <% end %>
137
+ </div>
138
+ <% end %>
122
139
  <table>
123
140
  <% info[:tests].each_with_index do |test, index| %>
124
141
  <% detail_class = test[:name].gsub(/\s/,'') %>
@@ -152,4 +169,4 @@
152
169
  </section>
153
170
  <footer>Report generated with <a href="https://github.com/mneorr/xcpretty">xcpretty</a></footer>
154
171
  </body>
155
- </html>
172
+ </html>
data/bin/xcpretty CHANGED
@@ -54,10 +54,16 @@ OptionParser.new do |opts|
54
54
  end
55
55
  opts.on('-o', '--output PATH', 'Write report output to PATH') do |path|
56
56
  unless opts = report_options.last
57
- XCPretty.exit_with_error('Expected report format to be specified before before output path')
57
+ XCPretty.exit_with_error('Expected report format to be specified before output path')
58
58
  end
59
59
  opts[:path] = path
60
60
  end
61
+ opts.on('--screenshots', 'Collect screenshots in the HTML report') do
62
+ unless opts = report_options.last
63
+ XCPretty.exit_with_error('Expected screenshot argument to be specified after report format')
64
+ end
65
+ opts[:screenshots] = true
66
+ end
61
67
  opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit }
62
68
  opts.on_tail("-v", "--version", "Show version") { puts XCPretty::VERSION; exit }
63
69
  opts.parse!
Binary file
@@ -38,3 +38,17 @@ Feature: Creating a HTML test report
38
38
  Scenario: Writing to multiple custom file paths
39
39
  When I pipe to xcpretty with two custom "html" report paths
40
40
  Then I should have test reports in two custom paths
41
+
42
+ Scenario: Showing screenshots
43
+ Given I have a passing test in my suite
44
+ And the test suite has finished
45
+ And I have a screenshot in the output folder
46
+ When I pipe to xcpretty with "--report html --screenshots"
47
+ Then I should see a screenshot in HTML
48
+
49
+ Scenario: Preventing unrelated images to be included in final report
50
+ Given I have a passing test in my suite
51
+ And the test suite has finished
52
+ And I have an unrelated image in the output folder
53
+ When I pipe to xcpretty with "--report html --screenshots"
54
+ Then I should not see a screenshot in HTML
@@ -92,6 +92,14 @@ Given(/^I have a file to touch$/) do
92
92
  add_run_input SAMPLE_TOUCH
93
93
  end
94
94
 
95
+ Given(/^I have a screenshot in the output folder/) do
96
+ copy_file_to_screenshot_dir(SAMPLE_SCREENSHOT_FILE)
97
+ end
98
+
99
+ Given(/^I have an unrelated image in the output folder/) do
100
+ copy_file_to_screenshot_dir(SAMPLE_UNRELATED_IMAGE_FILE)
101
+ end
102
+
95
103
  Then(/^I should see text beginning with "(.*?)"$/) do |text|
96
104
  run_output.lines.to_a.detect {|line| line.start_with? text }.should_not be_nil
97
105
  end
@@ -21,3 +21,11 @@ end
21
21
  Then(/^I should see (\d+) test suite sections? in HTML$/) do |section_count|
22
22
  html_test_suites.size.should == section_count.to_i
23
23
  end
24
+
25
+ Then(/^I should see a screenshot in HTML$/) do
26
+ html_report_body.get_elements("//*[contains(@class, 'screenshot')]/").to_a.size.should_not == 0
27
+ end
28
+
29
+ Then(/^I should not see a screenshot in HTML$/) do
30
+ html_report_body.get_elements("//*[contains(@class, 'screenshot')]/").to_a.size.should == 0
31
+ end
@@ -11,6 +11,7 @@ require 'lib/xcpretty/formatters/formatter'
11
11
  require 'lib/xcpretty/reporters/junit'
12
12
  require 'lib/xcpretty/reporters/html'
13
13
  require 'lib/xcpretty/reporters/json_compilation_database'
14
+
14
15
  begin
15
16
  require 'json'
16
17
  rescue LoadError
@@ -91,6 +92,11 @@ def other_custom_report_path
91
92
  end
92
93
  end
93
94
 
95
+ def copy_file_to_screenshot_dir(screenshot_file)
96
+ @screenshot_file_path = "#{XCPretty::HTML::SCREENSHOT_DIR}/#{screenshot_file}"
97
+ FileUtils.cp("features/assets/#{screenshot_file}", @screenshot_file_path)
98
+ end
99
+
94
100
  Before do
95
101
  self.colorize = true
96
102
  end
@@ -105,4 +111,5 @@ After do
105
111
  FileUtils.rm_rf(XCPretty::JUnit::FILEPATH)
106
112
  FileUtils.rm_rf(XCPretty::HTML::FILEPATH)
107
113
  FileUtils.rm_rf(XCPretty::JSONCompilationDatabase::FILEPATH)
114
+ File.delete(@screenshot_file_path) if @screenshot_file_path
108
115
  end
@@ -114,7 +114,7 @@ module XCPretty
114
114
  # @regex Captured groups
115
115
  # $1 = suite
116
116
  # $2 = time
117
- TESTS_RUN_COMPLETION_MATCHER = /^\s*Test Suite '(?:.*\/)?(.*[ox]ctest.*)' finished at (.*)/
117
+ TESTS_RUN_COMPLETION_MATCHER = /^\s*Test Suite '(?:.*\/)?(.*[ox]ctest.*)' (finished|passed|failed) at (.*)/
118
118
 
119
119
  # @regex Captured groups
120
120
  # $1 = suite
@@ -267,7 +267,7 @@ module XCPretty
267
267
  when PBXCP_MATCHER
268
268
  formatter.format_pbxcp($1)
269
269
  when TESTS_RUN_COMPLETION_MATCHER
270
- formatter.format_test_run_finished($1, $2)
270
+ formatter.format_test_run_finished($1, $3)
271
271
  when TESTS_RUN_START_MATCHER
272
272
  formatter.format_test_run_started($1)
273
273
  when TEST_SUITE_START_MATCHER
@@ -4,6 +4,7 @@ module XCPretty
4
4
  include XCPretty::FormatMethods
5
5
  FILEPATH = 'build/reports/tests.html'
6
6
  TEMPLATE = File.expand_path('../../../../assets/report.html.erb', __FILE__)
7
+ SCREENSHOT_DIR = 'build/reports'
7
8
 
8
9
  def load_dependencies
9
10
  unless @@loaded ||= false
@@ -21,6 +22,7 @@ module XCPretty
21
22
  @parser = Parser.new(self)
22
23
  @test_count = 0
23
24
  @fail_count = 0
25
+ @collect_screenshots = options[:screenshots]
24
26
  end
25
27
 
26
28
  def handle(line)
@@ -51,7 +53,7 @@ module XCPretty
51
53
 
52
54
  def add_test(suite_name, data)
53
55
  @test_count += 1
54
- @test_suites[suite_name] ||= {:tests => []}
56
+ @test_suites[suite_name] ||= {:tests => [], :screenshots => []}
55
57
  @test_suites[suite_name][:tests] << data
56
58
  if data[:failing]
57
59
  @test_suites[suite_name][:failing] = true
@@ -60,6 +62,9 @@ module XCPretty
60
62
  end
61
63
 
62
64
  def write_report
65
+ if @collect_screenshots
66
+ load_screenshots
67
+ end
63
68
  File.open(@filepath, 'w') do |f|
64
69
  # WAT: get rid of these locals. BTW Cucumber fails if you remove them
65
70
  test_suites = @test_suites
@@ -69,5 +74,23 @@ module XCPretty
69
74
  f.write erb.result(binding)
70
75
  end
71
76
  end
77
+
78
+ def load_screenshots
79
+ Dir.foreach(SCREENSHOT_DIR) do |item|
80
+ next if item == '.' || item == '..' || File.extname(item) != '.png'
81
+
82
+ suite_name = find_test_suite(item)
83
+ next if suite_name.nil?
84
+
85
+ @test_suites[suite_name][:screenshots] << item
86
+ end
87
+ end
88
+
89
+ def find_test_suite(image_name)
90
+ @test_suites.each do |key, value|
91
+ return key if image_name.start_with?(key)
92
+ end
93
+ nil
94
+ end
72
95
  end
73
96
  end
@@ -1,3 +1,3 @@
1
1
  module XCPretty
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -6,6 +6,8 @@ SAMPLE_OCUNIT_TEST_RUN_BEGINNING = "Test Suite '/Users/musalj/Library/Developer/
6
6
  SAMPLE_KIWI_TEST_RUN_BEGINNING = "Test Suite 'ObjectiveRecordTests.xctest' started at 2013-12-10 06:15:39 +0000"
7
7
  SAMPLE_SPECTA_TEST_RUN_BEGINNING = " Test Suite 'KIFTests.xctest' started at 2014-02-28 15:43:42 +0000"
8
8
  SAMPLE_OCUNIT_TEST_RUN_COMPLETION = "Test Suite '/Users/musalj/Library/Developer/Xcode/DerivedData/ReactiveCocoa-eznxkbqvgfsnrvetemqloysuwagb/Build/Products/Test/ReactiveCocoaTests.octest(Tests)' finished at 2013-12-10 07:03:03 +0000."
9
+ SAMPLE_OCUNIT_FAILED_TEST_RUN_COMPLETION = "Test Suite '/Users/dm/someplace/Macadamia.octest' failed at 2014-09-24 23:09:20 +0000."
10
+ SAMPLE_OCUNIT_PASSED_TEST_RUN_COMPLETION = "Test Suite 'Hazelnuts.xctest' passed at 2014-09-24 23:09:20 +0000."
9
11
  SAMPLE_KIWI_TEST_RUN_COMPLETION = "Test Suite 'ObjectiveRecordTests.xctest' finished at 2013-12-10 06:15:42 +0000."
10
12
  SAMPLE_SPECTA_TEST_RUN_COMPLETION = " Test Suite 'KIFTests.xctest' finished at 2014-02-28 15:44:32 +0000."
11
13
 
@@ -544,3 +546,5 @@ SAMPLE_LD_LIBRARY_ERROR = 'ld: library not found for -lPods-Yammer'
544
546
 
545
547
  SAMPLE_CLANG_ERROR = 'clang: error: linker command failed with exit code 1 (use -v to see invocation)'
546
548
 
549
+ SAMPLE_SCREENSHOT_FILE = 'RACCommandSpec, line 80, hello xcpretty.png'
550
+ SAMPLE_UNRELATED_IMAGE_FILE = 'apple_raw.png'
@@ -211,13 +211,21 @@ module XCPretty
211
211
  end
212
212
  end
213
213
 
214
-
215
-
216
214
  it "parses ocunit test run finished" do
217
215
  @formatter.should receive(:format_test_run_finished).with('ReactiveCocoaTests.octest(Tests)', '2013-12-10 07:03:03 +0000.')
218
216
  @parser.parse(SAMPLE_OCUNIT_TEST_RUN_COMPLETION)
219
217
  end
220
218
 
219
+ it "parses ocunit test run passed" do
220
+ @formatter.should receive(:format_test_run_finished).with('Hazelnuts.xctest', '2014-09-24 23:09:20 +0000.')
221
+ @parser.parse(SAMPLE_OCUNIT_PASSED_TEST_RUN_COMPLETION)
222
+ end
223
+
224
+ it "parses ocunit test run failed" do
225
+ @formatter.should receive(:format_test_run_finished).with('Macadamia.octest', '2014-09-24 23:09:20 +0000.')
226
+ @parser.parse(SAMPLE_OCUNIT_FAILED_TEST_RUN_COMPLETION)
227
+ end
228
+
221
229
  it "parses specta test run finished" do
222
230
  @formatter.should receive(:format_test_run_finished).with('KIFTests.xctest', '2014-02-28 15:44:32 +0000.')
223
231
  @parser.parse(SAMPLE_SPECTA_TEST_RUN_COMPLETION)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcpretty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marin Usalj
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,6 +89,8 @@ files:
89
89
  - Rakefile
90
90
  - assets/report.html.erb
91
91
  - bin/xcpretty
92
+ - features/assets/RACCommandSpec, line 80, hello xcpretty.png
93
+ - features/assets/apple_raw.png
92
94
  - features/custom_formatter.feature
93
95
  - features/fixtures/xcodebuild.log
94
96
  - features/html_report.feature
@@ -163,11 +165,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
165
  version: '0'
164
166
  requirements: []
165
167
  rubyforge_project:
166
- rubygems_version: 2.2.0
168
+ rubygems_version: 2.2.2
167
169
  signing_key:
168
170
  specification_version: 4
169
171
  summary: xcodebuild formatter done right
170
172
  test_files:
173
+ - features/assets/RACCommandSpec, line 80, hello xcpretty.png
174
+ - features/assets/apple_raw.png
171
175
  - features/custom_formatter.feature
172
176
  - features/fixtures/xcodebuild.log
173
177
  - features/html_report.feature
@@ -202,4 +206,3 @@ test_files:
202
206
  - spec/xcpretty/printer_spec.rb
203
207
  - spec/xcpretty/snippet_spec.rb
204
208
  - spec/xcpretty/syntax_spec.rb
205
- has_rdoc: