Skip to content

Commit

Permalink
Merge pull request #17 from usebutton/master
Browse files Browse the repository at this point in the history
Add support for ci_access_token and :travis_pro
  • Loading branch information
marklarr committed Jul 28, 2014
2 parents 5af4cf7 + 9db2be4 commit 3a2d9a1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
21 changes: 15 additions & 6 deletions lib/slather/coverage_service/coveralls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ def travis_job_id
private :travis_job_id

def coveralls_coverage_data
if ci_service == :travis_ci
if ci_service == :travis_ci || ci_service == :travis_pro
if travis_job_id
{
:service_job_id => travis_job_id,
:service_name => "travis-ci",
:source_files => coverage_files.map(&:as_json)
}.to_json
if ci_service == :travis_ci
{
:service_job_id => travis_job_id,
:service_name => "travis-ci",
:source_files => coverage_files.map(&:as_json)
}.to_json
elsif ci_service == :travis_pro
{
:service_job_id => travis_job_id,
:service_name => "travis-pro",
:repo_token => ci_access_token,
:source_files => coverage_files.map(&:as_json)
}.to_json
end
else
raise StandardError, "Environment variable `TRAVIS_JOB_ID` not set. Is this running on a travis build?"
end
Expand Down
7 changes: 6 additions & 1 deletion lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def slather_setup_for_coverage
module Slather
class Project < Xcodeproj::Project

attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :source_directory
attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :ci_access_token, :source_directory

alias_method :setup_for_coverage, :slather_setup_for_coverage

Expand Down Expand Up @@ -70,6 +70,7 @@ def configure_from_yml
configure_build_directory_from_yml
configure_ignore_list_from_yml
configure_ci_service_from_yml
configure_ci_access_token_from_yml
configure_coverage_service_from_yml
configure_source_directory_from_yml
end
Expand Down Expand Up @@ -98,6 +99,10 @@ def configure_coverage_service_from_yml
self.coverage_service ||= (self.class.yml["coverage_service"] || :terminal)
end

def configure_ci_access_token_from_yml
self.ci_access_token ||= (self.class.yml["ci_access_token"] || "")
end

def coverage_service=(service)
service = service && service.to_sym
if service == :coveralls
Expand Down
15 changes: 15 additions & 0 deletions spec/slather/coverage_service/coveralls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
end
end

context "coverage_service is :travis_pro" do
before(:each) { fixtures_project.ci_service = :travis_pro }

it "should return valid json for coveralls coverage data" do
fixtures_project.stub(:travis_job_id).and_return("9182")
fixtures_project.stub(:ci_access_token).and_return("abc123")
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]}]}")
end

it "should raise an error if there is no TRAVIS_JOB_ID" do
fixtures_project.stub(:travis_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end

it "should raise an error if it does not recognize the ci_service" do
fixtures_project.ci_service = :jenkins_ci
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
Expand Down
8 changes: 8 additions & 0 deletions spec/slather/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ class SpecCoverageFile < Slather::CoverageFile
end
end

describe "#configure_ci_access_token_from_yml" do
it "should set the ci_access_token if it has been provided by the yml" do
Slather::Project.stub(:yml).and_return({"ci_access_token" => "abc123"})
expect(fixtures_project).to receive(:ci_access_token=).with("abc123")
fixtures_project.configure_ci_access_token_from_yml
end
end

describe "#coverage_service=" do
it "should extend Slather::CoverageService::Coveralls and set coverage_service = :coveralls if given coveralls" do
expect(fixtures_project).to receive(:extend).with(Slather::CoverageService::Coveralls)
Expand Down

0 comments on commit 3a2d9a1

Please sign in to comment.