slather 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,18 @@ describe Slather::CoverageFile do
22
22
  expect(coverage_file.source_file_pathname).to eq(fixtures_project["fixtures/fixtures.m"].real_path)
23
23
  end
24
24
 
25
+ it "should look in the source_directory if it has been set on the project" do
26
+ coverage_file = Slather::CoverageFile.new(fixtures_project, "fixtures.m")
27
+ fixtures_project.source_directory = Pathname(File.join(File.dirname(__FILE__), '../fixtures/')).realpath.to_s
28
+ expect(coverage_file.source_file_pathname).to eq(fixtures_project["fixtures/fixtures.m"].real_path)
29
+ end
30
+
31
+ it "should look in the source_directory if it has been set on the project" do
32
+ coverage_file = Slather::CoverageFile.new(fixtures_project, "fixtures.m")
33
+ fixtures_project.source_directory = Pathname(File.join(File.dirname(__FILE__), '../fixtures/fixturesTests')).realpath.to_s
34
+ expect(coverage_file.source_file_pathname).to be_nil
35
+ end
36
+
25
37
  it "should return nil if it couldn't find the coverage files's source implementation file in the project" do
26
38
  whoami_file = Slather::CoverageFile.new(fixtures_project, "/some/path/whoami.gcno")
27
39
  expect(whoami_file.source_file_pathname).to be_nil
@@ -102,5 +114,23 @@ OBJC
102
114
  end
103
115
  end
104
116
 
117
+ describe "num_lines_tested" do
118
+ it "should return the correct number of lines tested" do
119
+ expect(coverage_file.num_lines_tested).to eq(2)
120
+ end
121
+ end
122
+
123
+ describe "num_lines_testable" do
124
+ it "should return the correct number of lines that are testable" do
125
+ expect(coverage_file.num_lines_testable).to eq(4)
126
+ end
127
+ end
128
+
129
+ describe "percentage_lines_tested" do
130
+ it "should return the correct percentage of lines that are tested" do
131
+ expect(coverage_file.percentage_lines_tested).to eq(50)
132
+ end
133
+ end
134
+
105
135
  end
106
- end
136
+ end
@@ -36,6 +36,21 @@ describe Slather::CoverageService::Coveralls do
36
36
  end
37
37
  end
38
38
 
39
+ context "coverage_service is :travis_pro" do
40
+ before(:each) { fixtures_project.ci_service = :travis_pro }
41
+
42
+ it "should return valid json for coveralls coverage data" do
43
+ fixtures_project.stub(:travis_job_id).and_return("9182")
44
+ fixtures_project.stub(:ci_access_token).and_return("abc123")
45
+ expect(fixtures_project.send(:coveralls_coverage_data)).to eq("{\"service_job_id\":\"9182\",\"service_name\":\"travis-pro\",\"repo_token\":\"abc123\",\"source_files\":[{\"name\":\"spec/fixtures/fixtures/fixtures.m\",\"source\":\"//\\n// fixtures.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"fixtures.h\\\"\\n\\n@implementation fixtures\\n\\n- (void)testedMethod\\n{\\n NSLog(@\\\"tested\\\");\\n}\\n\\n- (void)untestedMethod\\n{\\n NSLog(@\\\"untested\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,1,null,null,null,0,0,null,null]},{\"name\":\"spec/fixtures/fixtures/more_files/peekaview.m\",\"source\":\"//\\n// peekaview.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import \\\"peekaview.h\\\"\\n\\n@implementation peekaview\\n\\n- (id)initWithFrame:(CGRect)frame\\n{\\n self = [super initWithFrame:frame];\\n if (self) {\\n // Initialization code\\n }\\n return self;\\n}\\n\\n/*\\n// Only override drawRect: if you perform custom drawing.\\n// An empty implementation adversely affects performance during animation.\\n- (void)drawRect:(CGRect)rect\\n{\\n // Drawing code\\n}\\n*/\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,0,null,0,0,null,0,0,0,null,null,null,null,null,null,null,null,null,null,null]},{\"name\":\"spec/fixtures/fixturesTests/fixturesTests.m\",\"source\":\"//\\n// fixturesTests.m\\n// fixturesTests\\n//\\n// Created by Mark Larsen on 6/24/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n#import \\\"fixtures.h\\\"\\n\\n@interface fixturesTests : XCTestCase\\n\\n@end\\n\\n@implementation fixturesTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n fixtures *f = [[fixtures alloc] init];\\n [f testedMethod];\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,1,1,1,null,null]},{\"name\":\"spec/fixtures/fixturesTests/peekaviewTests.m\",\"source\":\"//\\n// peekaviewTests.m\\n// fixtures\\n//\\n// Created by Mark Larsen on 6/25/14.\\n// Copyright (c) 2014 marklarr. All rights reserved.\\n//\\n\\n#import <XCTest/XCTest.h>\\n\\n@interface peekaviewTests : XCTestCase\\n\\n@end\\n\\n@implementation peekaviewTests\\n\\n- (void)setUp\\n{\\n [super setUp];\\n // Put setup code here. This method is called before the invocation of each test method in the class.\\n}\\n\\n- (void)tearDown\\n{\\n // Put teardown code here. This method is called after the invocation of each test method in the class.\\n [super tearDown];\\n}\\n\\n- (void)testExample\\n{\\n XCTAssert(YES, @\\\"woot\\\");\\n}\\n\\n@end\\n\",\"coverage\":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,1,null,null,null,null,1,1,null,null,null,2,1,null,null]}]}")
46
+ end
47
+
48
+ it "should raise an error if there is no TRAVIS_JOB_ID" do
49
+ fixtures_project.stub(:travis_job_id).and_return(nil)
50
+ expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
51
+ end
52
+ end
53
+
39
54
  it "should raise an error if it does not recognize the ci_service" do
40
55
  fixtures_project.ci_service = :jenkins_ci
41
56
  expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
@@ -8,8 +8,8 @@ describe Slather::CoverageService::SimpleOutput do
8
8
  end
9
9
 
10
10
  describe '#coverage_file_class' do
11
- it "should return CoverallsCoverageFile" do
12
- expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverallsCoverageFile)
11
+ it "should return CoverageFile" do
12
+ expect(fixtures_project.send(:coverage_file_class)).to eq(Slather::CoverageFile)
13
13
  end
14
14
  end
15
15
 
@@ -23,4 +23,4 @@ describe Slather::CoverageService::SimpleOutput do
23
23
  fixtures_project.post
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -70,6 +70,7 @@ describe Slather::Project do
70
70
 
71
71
  it "should return coverage file objects of type coverage_file_class for unignored project files" do
72
72
  fixtures_project.ignore_list = ["*fixturesTests*"]
73
+ fixtures_project.stub(:dedupe) { |coverage_files| coverage_files }
73
74
  coverage_files = fixtures_project.send(:coverage_files)
74
75
  coverage_files.each { |cf| expect(cf.kind_of?(SpecCoverageFile)).to be_truthy }
75
76
  expect(coverage_files.map { |cf| cf.source_file_pathname.basename.to_s }).to eq(["fixtures.m", "peekaview.m"])
@@ -81,10 +82,33 @@ describe Slather::Project do
81
82
  end
82
83
  end
83
84
 
85
+ describe "#dedupe" do
86
+ it "should return a deduplicated list of coverage files, favoring the file with higher coverage" do
87
+ coverage_file_1 = double(Slather::CoverageFile)
88
+ coverage_file_1.stub(:source_file_pathname).and_return("some/path/class1.m")
89
+ coverage_file_1.stub(:percentage_lines_tested).and_return(100)
90
+
91
+ coverage_file_2 = double(Slather::CoverageFile)
92
+ coverage_file_2.stub(:source_file_pathname).and_return("some/path/class2.m")
93
+ coverage_file_2.stub(:percentage_lines_tested).and_return(100)
94
+
95
+ coverage_file_2b = double(Slather::CoverageFile)
96
+ coverage_file_2b.stub(:source_file_pathname).and_return("some/path/class2.m")
97
+ coverage_file_2b.stub(:percentage_lines_tested).and_return(0)
98
+
99
+ coverage_files = [coverage_file_1, coverage_file_2, coverage_file_2b]
100
+ deduped_coverage_files = fixtures_project.send(:dedupe, coverage_files)
101
+ expect(deduped_coverage_files.size).to eq(2)
102
+ expect(deduped_coverage_files).to include(coverage_file_1)
103
+ expect(deduped_coverage_files).to include(coverage_file_2)
104
+ end
105
+ end
106
+
84
107
  describe "#configure_from_yml" do
85
108
  it "should configure all properties from the yml" do
86
109
  unstubbed_project = Slather::Project.open(FIXTURES_PROJECT_PATH)
87
110
  expect(unstubbed_project).to receive(:configure_build_directory_from_yml)
111
+ expect(unstubbed_project).to receive(:configure_source_directory_from_yml)
88
112
  expect(unstubbed_project).to receive(:configure_ignore_list_from_yml)
89
113
  expect(unstubbed_project).to receive(:configure_ci_service_from_yml)
90
114
  expect(unstubbed_project).to receive(:configure_coverage_service_from_yml)
@@ -140,6 +164,21 @@ describe Slather::Project do
140
164
  end
141
165
  end
142
166
 
167
+ describe "#configure_source_directory_from_yml" do
168
+ it "should set the source_directory if it has been provided in the yml and has not already been set" do
169
+ Slather::Project.stub(:yml).and_return({"source_directory" => "/some/path"})
170
+ fixtures_project.configure_source_directory_from_yml
171
+ expect(fixtures_project.source_directory).to eq("/some/path")
172
+ end
173
+
174
+ it "should not set the source_directory if it has already been set" do
175
+ Slather::Project.stub(:yml).and_return({"source_directory" => "/some/path"})
176
+ fixtures_project.source_directory = "/already/set"
177
+ fixtures_project.configure_source_directory_from_yml
178
+ expect(fixtures_project.source_directory).to eq("/already/set")
179
+ end
180
+ end
181
+
143
182
  describe "#configure_ci_service_from_yml" do
144
183
  it "should set the ci_service if it has been provided in the yml and has not already been set" do
145
184
  Slather::Project.stub(:yml).and_return({"ci_service" => "some_service"})
@@ -189,6 +228,14 @@ describe Slather::Project do
189
228
  end
190
229
  end
191
230
 
231
+ describe "#configure_ci_access_token_from_yml" do
232
+ it "should set the ci_access_token if it has been provided by the yml" do
233
+ Slather::Project.stub(:yml).and_return({"ci_access_token" => "abc123"})
234
+ expect(fixtures_project).to receive(:ci_access_token=).with("abc123")
235
+ fixtures_project.configure_ci_access_token_from_yml
236
+ end
237
+ end
238
+
192
239
  describe "#coverage_service=" do
193
240
  it "should extend Slather::CoverageService::Coveralls and set coverage_service = :coveralls if given coveralls" do
194
241
  expect(fixtures_project).to receive(:extend).with(Slather::CoverageService::Coveralls)
@@ -207,13 +254,13 @@ describe Slather::Project do
207
254
  end
208
255
  end
209
256
 
210
- describe "#setup_for_coverage" do
257
+ describe "#slather_setup_for_coverage" do
211
258
  it "should enable the correct flags to generate test coverage on all of the build_configurations build settings" do
212
- fixtures_project.setup_for_coverage
259
+ fixtures_project.slather_setup_for_coverage
213
260
  fixtures_project.build_configurations.each do |build_configuration|
214
261
  expect(build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"]).to eq("YES")
215
262
  expect(build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"]).to eq("YES")
216
263
  end
217
264
  end
218
265
  end
219
- end
266
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Slather do
4
+
5
+ describe "::prepare_pods" do
6
+ it "should setup the pods project for coverage" do
7
+ pods_mock = double(Object)
8
+
9
+ installer_mock = double(Object)
10
+ project_mock = double(Xcodeproj::Project)
11
+ installer_mock.stub(:project).and_return(project_mock)
12
+ expect(project_mock).to receive(:slather_setup_for_coverage)
13
+
14
+ expect(pods_mock).to receive(:post_install).and_yield(installer_mock)
15
+
16
+ Slather.prepare_pods(pods_mock)
17
+ end
18
+ end
19
+ end
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,6 @@ files:
132
132
  - lib/slather/coveralls_coverage_file.rb
133
133
  - lib/slather/project.rb
134
134
  - lib/slather/version.rb
135
- - scripts/travis.sh
136
135
  - slather.gemspec
137
136
  - spec/fixtures/fixtures.xcodeproj/project.pbxproj
138
137
  - spec/fixtures/fixtures.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -151,6 +150,7 @@ files:
151
150
  - spec/slather/coverage_service/simple_output_spec.rb
152
151
  - spec/slather/fixtures.gcno
153
152
  - spec/slather/project_spec.rb
153
+ - spec/slather/slather_spec.rb
154
154
  - spec/spec_helper.rb
155
155
  homepage: https://github.com/marklarr/slather
156
156
  licenses:
@@ -194,5 +194,6 @@ test_files:
194
194
  - spec/slather/coverage_service/simple_output_spec.rb
195
195
  - spec/slather/fixtures.gcno
196
196
  - spec/slather/project_spec.rb
197
+ - spec/slather/slather_spec.rb
197
198
  - spec/spec_helper.rb
198
199
  has_rdoc:
data/scripts/travis.sh DELETED
@@ -1,2 +0,0 @@
1
- xcodebuild -project spec/fixtures/fixtures.xcodeproj/ -scheme fixtures -configuration Debug test
2
- bundle exec rspec