slather 1.7.1 → 1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,7 +44,7 @@ describe Slather::CoverageService::Coveralls do
44
44
 
45
45
  it "should return valid json for coveralls coverage data" do
46
46
  fixtures_project.stub(:travis_job_id).and_return("9182")
47
- fixtures_project.stub(:ci_access_token).and_return("abc123")
47
+ fixtures_project.stub(:coverage_access_token).and_return("abc123")
48
48
  expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"travis-pro\",\"repo_token\":\"abc123\"}").excluding("source_files")
49
49
  expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql(fixtures_project.send(:coverage_files).map(&:as_json).to_json).at_path("source_files")
50
50
  end
@@ -54,25 +54,44 @@ describe Slather::CoverageService::Coveralls do
54
54
  expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
55
55
  end
56
56
  end
57
-
57
+
58
58
  context "coverage_service is :circleci" do
59
59
  before(:each) { fixtures_project.ci_service = :circleci }
60
-
60
+
61
61
  it "should return valid json for coveralls coverage data" do
62
62
  fixtures_project.stub(:circleci_job_id).and_return("9182")
63
- fixtures_project.stub(:ci_access_token).and_return("abc123")
63
+ fixtures_project.stub(:coverage_access_token).and_return("abc123")
64
64
  fixtures_project.stub(:circleci_pull_request).and_return("1")
65
+ fixtures_project.stub(:circleci_build_url).and_return("https://circleci.com/gh/Bruce/Wayne/1")
65
66
  fixtures_project.stub(:circleci_git_info).and_return({ :head => { :id => "ababa123", :author_name => "bwayne", :message => "hello" }, :branch => "master" })
66
- expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"circleci\",\"repo_token\":\"abc123\",\"service_pull_request\":\"1\",\"git\":{\"head\":{\"id\":\"ababa123\",\"author_name\":\"bwayne\",\"message\":\"hello\"},\"branch\":\"master\"}}").excluding("source_files")
67
+ expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"circleci\",\"repo_token\":\"abc123\",\"service_pull_request\":\"1\",\"service_build_url\":\"https://circleci.com/gh/Bruce/Wayne/1\",\"git\":{\"head\":{\"id\":\"ababa123\",\"author_name\":\"bwayne\",\"message\":\"hello\"},\"branch\":\"master\"}}").excluding("source_files")
67
68
  expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql(fixtures_project.send(:coverage_files).map(&:as_json).to_json).at_path("source_files")
68
69
  end
69
-
70
+
70
71
  it "should raise an error if there is no CIRCLE_BUILD_NUM" do
71
72
  fixtures_project.stub(:circleci_job_id).and_return(nil)
72
73
  expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
73
74
  end
74
75
  end
75
76
 
77
+ context "coverage_service is :jenkins" do
78
+ before(:each) { fixtures_project.ci_service = :jenkins }
79
+
80
+ it "should return valid json for coveralls coverage data" do
81
+ fixtures_project.stub(:jenkins_job_id).and_return("9182")
82
+ fixtures_project.stub(:coverage_access_token).and_return("abc123")
83
+ fixtures_project.stub(:jenkins_git_info).and_return({head: {id: "master", author_name: "author", message: "pull title" }, branch: "branch"})
84
+ fixtures_project.stub(:jenkins_branch_name).and_return('master')
85
+ expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"jenkins\",\"repo_token\":\"abc123\",\"git\":{\"head\":{\"id\":\"master\",\"author_name\":\"author\",\"message\":\"pull title\"},\"branch\":\"branch\"}}").excluding("source_files")
86
+ expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql(fixtures_project.send(:coverage_files).map(&:as_json).to_json).at_path("source_files")
87
+ end
88
+
89
+ it "should raise an error if there is no BUILD_ID" do
90
+ fixtures_project.stub(:jenkins_job_id).and_return(nil)
91
+ expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
92
+ end
93
+ end
94
+
76
95
  it "should raise an error if it does not recognize the ci_service" do
77
96
  fixtures_project.ci_service = :jenkins_ci
78
97
  expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ describe Slather::CoverageService::Hardcover do
4
+
5
+ let(:fixtures_project) do
6
+ proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
7
+ proj.extend(Slather::CoverageService::Hardcover)
8
+ end
9
+
10
+ let(:fixture_yaml) do
11
+ yaml_text = <<-EOF
12
+ hardcover_repo_token: "27dd855e706b22126ec6daaaf7bb40b5"
13
+ hardcover_base_url: "http://api.hardcover.io"
14
+ EOF
15
+ yaml = YAML.load(yaml_text)
16
+ end
17
+
18
+ describe "#coverage_file_class" do
19
+ it "should return CoverallsCoverageFile" do
20
+ expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverallsCoverageFile)
21
+ end
22
+ end
23
+
24
+ describe "#job_id" do
25
+ it "should return the Jenkins JOB_NAME and BUILD_NUMBER environment variables" do
26
+ ENV['BUILD_NUMBER'] = "9182"
27
+ ENV['JOB_NAME'] = "slather-master"
28
+ expect(fixtures_project.send(:jenkins_job_id)).to eq("slather-master/9182")
29
+ end
30
+ end
31
+
32
+ describe '#hardcover_coverage_data' do
33
+
34
+ context "coverage_service is :jenkins_ci" do
35
+ before(:each) do
36
+ fixtures_project.ci_service = :jenkins_ci
37
+ Slather::Project.stub(:yml).and_return(fixture_yaml)
38
+ end
39
+
40
+ it "should return a valid json" do
41
+ json = JSON(fixtures_project.send(:hardcover_coverage_data))
42
+ expect(json["service_job_id"]).to eq("slather-master/9182")
43
+ expect(json["service_name"]).to eq("jenkins-ci")
44
+ expect(json["repo_token"]).to eq("27dd855e706b22126ec6daaaf7bb40b5")
45
+ expect(json["source_files"]).to_not be_empty
46
+ end
47
+
48
+ it "should raise an error if there is no BUILD_NUMBER or JOB_NAME" do
49
+ fixtures_project.stub(:jenkins_job_id).and_return(nil)
50
+ expect { fixtures_project.send(:hardcover_coverage_data) }.to raise_error(StandardError)
51
+ end
52
+ end
53
+
54
+ it "should raise an error if it does not recognize the ci_service" do
55
+ fixtures_project.ci_service = :non_existing_ci
56
+ expect { fixtures_project.send(:hardcover_coverage_data) }.to raise_error(StandardError)
57
+ end
58
+ end
59
+
60
+ describe '#post' do
61
+ before(:each) do
62
+ Slather::Project.stub(:yml).and_return(fixture_yaml)
63
+ fixtures_project.ci_service = :jenkins_ci
64
+ end
65
+
66
+ it "should save the hardcover_coverage_data to a file and post it to hardcover" do
67
+ fixtures_project.stub(:jenkins_job_id).and_return("slather-master/9182")
68
+ fixtures_project.stub(:coverage_service_url).and_return("http://api.hardcover.io")
69
+ expect(fixtures_project).to receive(:`) do |cmd|
70
+ expect(cmd).to eq("curl --form json_file=@hardcover_json_file http://api.hardcover.io/v1/jobs")
71
+ end.once
72
+ fixtures_project.post
73
+ end
74
+
75
+ it "should always remove the hardcover_json_file after it's done" do
76
+ fixtures_project.stub(:`)
77
+
78
+ fixtures_project.stub(:jenkins_job_id).and_return("slather-master/9182")
79
+ fixtures_project.stub(:coverage_service_url).and_return("http://api.hardcover.io")
80
+ fixtures_project.post
81
+ expect(File.exist?("hardcover_json_file")).to be_falsy
82
+ fixtures_project.stub(:jenkins_job_id).and_return(nil)
83
+ expect { fixtures_project.post }.to raise_error
84
+ expect(File.exist?("hardcover_json_file")).to be_falsy
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,179 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+ require 'nokogiri'
3
+
4
+ describe Slather::CoverageService::HtmlOutput do
5
+
6
+ OUTPUT_DIR_PATH = "html"
7
+
8
+ let(:fixture_html_files) do
9
+ ["index",
10
+ "fixtures.m",
11
+ "peekaview.m",
12
+ "fixtures_cpp.cpp",
13
+ "fixtures_mm.mm",
14
+ "fixtures_m.m",
15
+ "Branches.m",
16
+ "Empty.m",
17
+ "fixturesTests.m",
18
+ "peekaviewTests.m",
19
+ "BranchesTests.m"].map { |file| "#{file}.html"}
20
+ end
21
+
22
+ let(:fixtures_project) do
23
+ proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
24
+ proj.extend(Slather::CoverageService::HtmlOutput)
25
+ end
26
+
27
+ describe '#coverage_file_class' do
28
+ it "should return CoverageFile" do
29
+ expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverageFile)
30
+ end
31
+ end
32
+
33
+ describe '#post' do
34
+ before(:each) {
35
+ fixtures_project.stub(:print_path_coverage)
36
+ }
37
+
38
+ after(:each) {
39
+ FileUtils.rm_rf(OUTPUT_DIR_PATH) if Dir.exist?(OUTPUT_DIR_PATH)
40
+ }
41
+
42
+ def extract_header_title(doc)
43
+ doc.at_css('title').text
44
+ end
45
+
46
+ it "should create all coverage as static html files" do
47
+ fixtures_project.post
48
+
49
+ fixture_html_files.map { |filename|
50
+ File.join(OUTPUT_DIR_PATH, filename)
51
+ }.each { |filepath|
52
+ expect(File.exist?(filepath)).to be_truthy
53
+ }
54
+ end
55
+
56
+ it "should print out the path of the html folder by default" do
57
+ fixtures_project.post
58
+
59
+ expect(fixtures_project).to have_received(:print_path_coverage).with("html/index.html")
60
+ end
61
+
62
+ it "should open the index.html automatically if --show is flagged" do
63
+ fixtures_project.stub(:open_coverage)
64
+
65
+ fixtures_project.show_html = true
66
+ fixtures_project.post
67
+
68
+ expect(fixtures_project).to have_received(:open_coverage).with("html/index.html")
69
+ end
70
+
71
+ it "should create index html with correct coverage information" do
72
+ def extract_title(doc)
73
+ doc.at_css('#reports > h2').text
74
+ end
75
+
76
+ def extract_coverage_text(doc)
77
+ doc.at_css('#total_coverage').text
78
+ end
79
+
80
+ def extract_coverage_class(doc)
81
+ doc.at_css('#total_coverage').attribute("class").to_s
82
+ end
83
+
84
+ def extract_cov_header(doc)
85
+ doc.css("table.coverage_list > thead > tr > th").map { |header|
86
+ [header.text, header.attribute("data-sort")].join(", ")
87
+ }.join("; ")
88
+ end
89
+
90
+ def extract_cov_index(doc)
91
+ coverages = doc.css("table.coverage_list > tbody > tr").map { |tr|
92
+ tr.css("td").map { |td|
93
+ if td.attribute("class")
94
+ td.attribute("class").to_s.split.join(", ") + ", #{td.text}"
95
+ elsif span = td.at_css("span")
96
+ span.attribute("class").to_s.split.join(", ") + ", #{td.text}"
97
+ else
98
+ td.text
99
+ end
100
+ }.join("; ")
101
+ }
102
+
103
+ list = doc.css("table.coverage_list > tbody").attribute("class")
104
+ coverages.append(list.to_s)
105
+ end
106
+
107
+ fixtures_project.post
108
+
109
+ file = File.open(File.join(FIXTURES_HTML_FOLDER_PATH, "index.html"))
110
+ fixture_doc = Nokogiri::HTML(file)
111
+ file.close
112
+
113
+ file = File.open(File.join(OUTPUT_DIR_PATH, "index.html"))
114
+ current_doc = Nokogiri::HTML(file)
115
+ file.close
116
+
117
+ expect(extract_header_title(current_doc)).to eq(extract_header_title(fixture_doc))
118
+ expect(extract_title(current_doc)).to eq(extract_title(fixture_doc))
119
+ expect(extract_coverage_text(current_doc)).to eq(extract_coverage_text(fixture_doc))
120
+ expect(extract_coverage_class(current_doc)).to eq(extract_coverage_class(fixture_doc))
121
+ expect(extract_cov_header(current_doc)).to eq(extract_cov_header(fixture_doc))
122
+ expect(extract_cov_index(current_doc)).to eq(extract_cov_index(fixture_doc))
123
+ end
124
+
125
+ it "should create html coverage for each file with correct coverage" do
126
+ def extract_title(doc)
127
+ doc.css('#coverage > h2 > span').map{ |x| x.text.strip }.join(", ")
128
+ end
129
+
130
+ def extract_subtitle(doc)
131
+ (sub = doc.at_css('h4.cov_subtitle')) ? sub.text : ""
132
+ end
133
+
134
+ def extract_filepath(doc)
135
+ (path = doc.at_css('h4.cov_filepath'))? path.text : ""
136
+ end
137
+
138
+ def extract_cov_data(doc)
139
+ doc.css("table.source_code > tr").map { |tr|
140
+ ([tr.attribute("class")] + tr.css('td').map(&:text)).join(",")
141
+ }
142
+ end
143
+
144
+ fixtures_project.post
145
+
146
+ fixture_html_files.each { |filename|
147
+ file = File.open(File.join(FIXTURES_HTML_FOLDER_PATH, filename))
148
+ fixture_doc = Nokogiri::HTML(file)
149
+ file.close
150
+
151
+ file = File.open(File.join(OUTPUT_DIR_PATH, filename))
152
+ current_doc = Nokogiri::HTML(file)
153
+ file.close
154
+
155
+ expect(extract_title(fixture_doc)).to eq(extract_title(current_doc))
156
+ expect(extract_subtitle(fixture_doc)).to eq(extract_subtitle(current_doc))
157
+ expect(extract_filepath(fixture_doc)).to eq(extract_filepath(current_doc))
158
+ expect(extract_cov_data(fixture_doc)).to eq(extract_cov_data(current_doc))
159
+ }
160
+ end
161
+
162
+ it "should create an HTML report directory in the given output directory" do
163
+ fixtures_project.output_directory = "./output"
164
+ fixtures_project.post
165
+
166
+ expect(Dir.exist?(fixtures_project.output_directory)).to be_truthy
167
+
168
+ FileUtils.rm_rf(fixtures_project.output_directory) if Dir.exist?(fixtures_project.output_directory)
169
+ end
170
+
171
+ it "should create the default directory (html) if output directory is faulty" do
172
+ fixtures_project.output_directory = " "
173
+ fixtures_project.post
174
+
175
+ expect(Dir.exist?(OUTPUT_DIR_PATH)).to be_truthy
176
+ end
177
+
178
+ end
179
+ end
@@ -243,12 +243,19 @@ describe Slather::Project do
243
243
  end
244
244
  end
245
245
 
246
- describe "#configure_ci_access_token_from_yml" do
247
- it "should set the ci_access_token if it has been provided by the yml" do
248
- Slather::Project.stub(:yml).and_return({"ci_access_token" => "abc123"})
249
- expect(fixtures_project).to receive(:ci_access_token=).with("abc123")
250
- fixtures_project.configure_ci_access_token_from_yml
251
- end
246
+ describe "#configure_coverage_access_token" do
247
+ it "should set the coverage_access_token if it has been provided by the yml" do
248
+ Slather::Project.stub(:yml).and_return({"coverage_access_token" => "abc123"})
249
+ expect(fixtures_project).to receive(:coverage_access_token=).with("abc123")
250
+ fixtures_project.configure_coverage_access_token_from_yml
251
+ end
252
+
253
+ it "should set the coverage_access_token if it is in the ENV" do
254
+ stub_const('ENV', ENV.to_hash.merge('COVERAGE_ACCESS_TOKEN' => 'asdf456'))
255
+ expect(fixtures_project).to receive(:coverage_access_token=).with("asdf456")
256
+ fixtures_project.configure_coverage_access_token_from_yml
257
+ end
258
+
252
259
  end
253
260
 
254
261
  describe "#coverage_service=" do
data/spec/spec_helper.rb CHANGED
@@ -9,11 +9,12 @@ require 'equivalent-xml'
9
9
 
10
10
  FIXTURES_XML_PATH = File.join(File.dirname(__FILE__), 'fixtures/cobertura.xml')
11
11
  FIXTURES_JSON_PATH = File.join(File.dirname(__FILE__), 'fixtures/gutter.json')
12
+ FIXTURES_HTML_FOLDER_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures_html')
12
13
  FIXTURES_PROJECT_PATH = File.join(File.dirname(__FILE__), 'fixtures/fixtures.xcodeproj')
13
14
 
14
15
  RSpec.configure do |config|
15
16
  config.before(:suite) do
16
- `xcodebuild -project #{FIXTURES_PROJECT_PATH} -scheme fixtures -configuration Debug test`
17
+ `xcodebuild -project "#{FIXTURES_PROJECT_PATH}" -scheme fixtures -configuration Debug test`
17
18
  end
18
19
 
19
20
  config.after(:suite) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slather
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: '1.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-04 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,6 +180,9 @@ files:
180
180
  - LICENSE.txt
181
181
  - README.md
182
182
  - Rakefile
183
+ - assets/highlight.pack.js
184
+ - assets/list.min.js
185
+ - assets/slather.css
183
186
  - bin/slather
184
187
  - docs/logo.jpg
185
188
  - lib/cocoapods_plugin.rb
@@ -188,6 +191,8 @@ files:
188
191
  - lib/slather/coverage_service/cobertura_xml_output.rb
189
192
  - lib/slather/coverage_service/coveralls.rb
190
193
  - lib/slather/coverage_service/gutter_json_output.rb
194
+ - lib/slather/coverage_service/hardcover.rb
195
+ - lib/slather/coverage_service/html_output.rb
191
196
  - lib/slather/coverage_service/simple_output.rb
192
197
  - lib/slather/coveralls_coverage_file.rb
193
198
  - lib/slather/project.rb
@@ -217,12 +222,25 @@ files:
217
222
  - spec/fixtures/fixturesTests/Supporting Files/fixturesTests-Info.plist
218
223
  - spec/fixtures/fixturesTests/fixturesTests.m
219
224
  - spec/fixtures/fixturesTests/peekaviewTests.m
225
+ - spec/fixtures/fixtures_html/Branches.m.html
226
+ - spec/fixtures/fixtures_html/BranchesTests.m.html
227
+ - spec/fixtures/fixtures_html/Empty.m.html
228
+ - spec/fixtures/fixtures_html/fixtures.m.html
229
+ - spec/fixtures/fixtures_html/fixturesTests.m.html
230
+ - spec/fixtures/fixtures_html/fixtures_cpp.cpp.html
231
+ - spec/fixtures/fixtures_html/fixtures_m.m.html
232
+ - spec/fixtures/fixtures_html/fixtures_mm.mm.html
233
+ - spec/fixtures/fixtures_html/index.html
234
+ - spec/fixtures/fixtures_html/peekaview.m.html
235
+ - spec/fixtures/fixtures_html/peekaviewTests.m.html
220
236
  - spec/fixtures/gutter.json
221
237
  - spec/slather/cocoapods_plugin_spec.rb
222
238
  - spec/slather/coverage_file_spec.rb
223
239
  - spec/slather/coverage_service/cobertura_xml_spec.rb
224
240
  - spec/slather/coverage_service/coveralls_spec.rb
225
241
  - spec/slather/coverage_service/gutter_json_spec.rb
242
+ - spec/slather/coverage_service/hardcover_spec.rb
243
+ - spec/slather/coverage_service/html_output_spec.rb
226
244
  - spec/slather/coverage_service/simple_output_spec.rb
227
245
  - spec/slather/fixtures.gcno
228
246
  - spec/slather/project_spec.rb
@@ -276,12 +294,25 @@ test_files:
276
294
  - spec/fixtures/fixturesTests/Supporting Files/fixturesTests-Info.plist
277
295
  - spec/fixtures/fixturesTests/fixturesTests.m
278
296
  - spec/fixtures/fixturesTests/peekaviewTests.m
297
+ - spec/fixtures/fixtures_html/Branches.m.html
298
+ - spec/fixtures/fixtures_html/BranchesTests.m.html
299
+ - spec/fixtures/fixtures_html/Empty.m.html
300
+ - spec/fixtures/fixtures_html/fixtures.m.html
301
+ - spec/fixtures/fixtures_html/fixturesTests.m.html
302
+ - spec/fixtures/fixtures_html/fixtures_cpp.cpp.html
303
+ - spec/fixtures/fixtures_html/fixtures_m.m.html
304
+ - spec/fixtures/fixtures_html/fixtures_mm.mm.html
305
+ - spec/fixtures/fixtures_html/index.html
306
+ - spec/fixtures/fixtures_html/peekaview.m.html
307
+ - spec/fixtures/fixtures_html/peekaviewTests.m.html
279
308
  - spec/fixtures/gutter.json
280
309
  - spec/slather/cocoapods_plugin_spec.rb
281
310
  - spec/slather/coverage_file_spec.rb
282
311
  - spec/slather/coverage_service/cobertura_xml_spec.rb
283
312
  - spec/slather/coverage_service/coveralls_spec.rb
284
313
  - spec/slather/coverage_service/gutter_json_spec.rb
314
+ - spec/slather/coverage_service/hardcover_spec.rb
315
+ - spec/slather/coverage_service/html_output_spec.rb
285
316
  - spec/slather/coverage_service/simple_output_spec.rb
286
317
  - spec/slather/fixtures.gcno
287
318
  - spec/slather/project_spec.rb