Skip to content

Commit

Permalink
Update RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
dlackty committed Feb 5, 2016
1 parent 5edcd6f commit b516b95
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
script: bundle exec rspec
script: bundle exec rake
osx_image: xcode7

# Sets Travis to run the Ruby specs on OS X machines which are required to
Expand Down
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

desc 'Execute tests'
task :spec do
sh 'bundle exec rspec spec'
end
RSpec::Core::RakeTask.new(:spec)

task default: :spec
13 changes: 7 additions & 6 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,18 @@ def configure_coverage_access_token

def coverage_service=(service)
service = service && service.to_sym
if service == :coveralls
case service
when :coveralls
extend(Slather::CoverageService::Coveralls)
elsif service == :hardcover
when :hardcover
extend(Slather::CoverageService::Hardcover)
elsif service == :terminal
when :terminal
extend(Slather::CoverageService::SimpleOutput)
elsif service == :gutter_json
when :gutter_json
extend(Slather::CoverageService::GutterJsonOutput)
elsif service == :cobertura_xml
when :cobertura_xml
extend(Slather::CoverageService::CoberturaXmlOutput)
elsif service == :html
when :html
extend(Slather::CoverageService::HtmlOutput)
else
raise ArgumentError, "`#{coverage_service}` is not a valid coverage service. Try `terminal`, `coveralls`, `gutter_json`, `cobertura_xml` or `html`"
Expand Down
4 changes: 2 additions & 2 deletions slather.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency "rspec", "~> 3.3"
spec.add_development_dependency "rake", "~> 10.4"
spec.add_development_dependency "rspec", "~> 3.4"
spec.add_development_dependency "pry", "~> 0.9"
spec.add_development_dependency "cocoapods", ">= 0.39.0", "< 1.1.0"
spec.add_development_dependency "json_spec", "~> 1.1.4"
Expand Down
6 changes: 3 additions & 3 deletions spec/slather/coverage_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
project = Slather::Project.open(FIXTURES_PROJECT_PATH)
project.build_directory = TEMP_DERIVED_DATA_PATH
project.send(:configure)
project.stub(:input_format).and_return("gcov")
allow(project).to receive(:input_format).and_return("gcov")
project
end

Expand Down Expand Up @@ -120,7 +120,7 @@
describe "line coverage" do

before(:each) {
fixtures_project.stub(:input_format).and_return("gcov")
allow(fixtures_project).to receive(:input_format).and_return("gcov")
}

let(:line_coverage_file) do
Expand Down Expand Up @@ -157,7 +157,7 @@
end

it "should return 100 if no testable lines" do
line_coverage_file.stub(:num_lines_testable).and_return(0)
allow(line_coverage_file).to receive(:num_lines_testable).and_return(0)
expect(line_coverage_file.percentage_lines_tested).to eq(100)
end
end
Expand Down
44 changes: 22 additions & 22 deletions spec/slather/coverage_service/coveralls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
before(:each) { fixtures_project.ci_service = :travis_ci }

it "should return valid json for coveralls coverage gcov data" do
fixtures_project.stub(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"travis-ci\"}").excluding("source_files")
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")
end

it "should raise an error if there is no TRAVIS_JOB_ID" do
fixtures_project.stub(:travis_job_id).and_return(nil)
allow(fixtures_project).to receive(:travis_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end
Expand All @@ -47,14 +47,14 @@
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(:coverage_access_token).and_return("abc123")
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:coverage_access_token).and_return("abc123")
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")
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")
end

it "should raise an error if there is no TRAVIS_JOB_ID" do
fixtures_project.stub(:travis_job_id).and_return(nil)
allow(fixtures_project).to receive(:travis_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end
Expand All @@ -63,17 +63,17 @@
before(:each) { fixtures_project.ci_service = :circleci }

it "should return valid json for coveralls coverage data" do
fixtures_project.stub(:circleci_job_id).and_return("9182")
fixtures_project.stub(:coverage_access_token).and_return("abc123")
fixtures_project.stub(:circleci_pull_request).and_return("1")
fixtures_project.stub(:circleci_build_url).and_return("https://circleci.com/gh/Bruce/Wayne/1")
fixtures_project.stub(:circleci_git_info).and_return({ :head => { :id => "ababa123", :author_name => "bwayne", :message => "hello" }, :branch => "master" })
allow(fixtures_project).to receive(:circleci_job_id).and_return("9182")
allow(fixtures_project).to receive(:coverage_access_token).and_return("abc123")
allow(fixtures_project).to receive(:circleci_pull_request).and_return("1")
allow(fixtures_project).to receive(:circleci_build_url).and_return("https://circleci.com/gh/Bruce/Wayne/1")
allow(fixtures_project).to receive(:circleci_git_info).and_return({ :head => { :id => "ababa123", :author_name => "bwayne", :message => "hello" }, :branch => "master" })
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")
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")
end

it "should raise an error if there is no CIRCLE_BUILD_NUM" do
fixtures_project.stub(:circleci_job_id).and_return(nil)
allow(fixtures_project).to receive(:circleci_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end
Expand All @@ -82,16 +82,16 @@
before(:each) { fixtures_project.ci_service = :jenkins }

it "should return valid json for coveralls coverage data" do
fixtures_project.stub(:jenkins_job_id).and_return("9182")
fixtures_project.stub(:coverage_access_token).and_return("abc123")
fixtures_project.stub(:jenkins_git_info).and_return({head: {id: "master", author_name: "author", message: "pull title" }, branch: "branch"})
fixtures_project.stub(:jenkins_branch_name).and_return('master')
allow(fixtures_project).to receive(:jenkins_job_id).and_return("9182")
allow(fixtures_project).to receive(:coverage_access_token).and_return("abc123")
allow(fixtures_project).to receive(:jenkins_git_info).and_return({head: {id: "master", author_name: "author", message: "pull title" }, branch: "branch"})
allow(fixtures_project).to receive(:jenkins_branch_name).and_return('master')
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")
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")
end

it "should raise an error if there is no BUILD_ID" do
fixtures_project.stub(:jenkins_job_id).and_return(nil)
allow(fixtures_project).to receive(:jenkins_job_id).and_return(nil)
expect { fixtures_project.send(:coveralls_coverage_data) }.to raise_error(StandardError)
end
end
Expand All @@ -107,7 +107,7 @@
before(:each) {
fixtures_project.ci_service = :travis_ci
project_root = Pathname("./").realpath
fixtures_project.stub(:profdata_llvm_cov_output).and_return("#{project_root}/spec/fixtures/fixtures/fixtures.m:
allow(fixtures_project).to receive(:profdata_llvm_cov_output).and_return("#{project_root}/spec/fixtures/fixtures/fixtures.m:
| 1|//
| 2|// fixtures.m
| 3|// fixtures
Expand Down Expand Up @@ -135,7 +135,7 @@
}

it "should save the coveralls_coverage_data to a file and post it to coveralls" do
fixtures_project.stub(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
expect(fixtures_project).to receive(:`) do |cmd|
expect(cmd).to eq("curl -s --form json_file=@coveralls_json_file https://coveralls.io/api/v1/jobs")
expect(File.read('coveralls_json_file')).to be_json_eql(fixtures_project.send(:coveralls_coverage_data))
Expand All @@ -144,17 +144,17 @@
end

it "should always remove the coveralls_json_file after it's done" do
fixtures_project.stub(:`)
fixtures_project.stub(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:`)
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
fixtures_project.post
expect(File.exist?("coveralls_json_file")).to be_falsy
fixtures_project.stub(:travis_job_id).and_return(nil)
allow(fixtures_project).to receive(:travis_job_id).and_return(nil)
expect { fixtures_project.post }.to raise_error(StandardError)
expect(File.exist?("coveralls_json_file")).to be_falsy
end

it "should return valid json for coveralls coverage profdata data" do
fixtures_project.stub(:travis_job_id).and_return("9182")
allow(fixtures_project).to receive(:travis_job_id).and_return("9182")
expect(fixtures_project.send(:coveralls_coverage_data)).to be_json_eql("{\"service_job_id\":\"9182\",\"service_name\":\"travis-ci\"}").excluding("source_files")
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")
end
Expand Down
20 changes: 10 additions & 10 deletions spec/slather/coverage_service/hardcover_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
context "coverage_service is :jenkins_ci" do
before(:each) do
fixtures_project.ci_service = :jenkins_ci
Slather::Project.stub(:yml).and_return(fixture_yaml)
allow(Slather::Project).to receive(:yml).and_return(fixture_yaml)
end

it "should return a valid json" do
Expand All @@ -50,7 +50,7 @@
end

it "should raise an error if there is no BUILD_NUMBER or JOB_NAME" do
fixtures_project.stub(:jenkins_job_id).and_return(nil)
allow(fixtures_project).to receive(:jenkins_job_id).and_return(nil)
expect { fixtures_project.send(:hardcover_coverage_data) }.to raise_error(StandardError)
end
end
Expand All @@ -63,10 +63,10 @@

describe '#post' do
before(:each) do
Slather::Project.stub(:yml).and_return(fixture_yaml)
allow(Slather::Project).to receive(:yml).and_return(fixture_yaml)
fixtures_project.ci_service = :jenkins_ci
project_root = Pathname("./").realpath
fixtures_project.stub(:profdata_llvm_cov_output).and_return("#{project_root}/spec/fixtures/fixtures/fixtures.m:
allow(fixtures_project).to receive(:profdata_llvm_cov_output).and_return("#{project_root}/spec/fixtures/fixtures/fixtures.m:
| 1|//
| 2|// fixtures.m
| 3|// fixtures
Expand Down Expand Up @@ -94,22 +94,22 @@
end

it "should save the hardcover_coverage_data to a file and post it to hardcover" do
fixtures_project.stub(:jenkins_job_id).and_return("slather-master/9182")
fixtures_project.stub(:coverage_service_url).and_return("http://api.hardcover.io")
allow(fixtures_project).to receive(:jenkins_job_id).and_return("slather-master/9182")
allow(fixtures_project).to receive(:coverage_service_url).and_return("http://api.hardcover.io")
expect(fixtures_project).to receive(:`) do |cmd|
expect(cmd).to eq("curl --form json_file=@hardcover_json_file http://api.hardcover.io/v1/jobs")
end.once
fixtures_project.post
end

it "should always remove the hardcover_json_file after it's done" do
fixtures_project.stub(:`)
allow(fixtures_project).to receive(:`)

fixtures_project.stub(:jenkins_job_id).and_return("slather-master/9182")
fixtures_project.stub(:coverage_service_url).and_return("http://api.hardcover.io")
allow(fixtures_project).to receive(:jenkins_job_id).and_return("slather-master/9182")
allow(fixtures_project).to receive(:coverage_service_url).and_return("http://api.hardcover.io")
fixtures_project.post
expect(File.exist?("hardcover_json_file")).to be_falsy
fixtures_project.stub(:jenkins_job_id).and_return(nil)
allow(fixtures_project).to receive(:jenkins_job_id).and_return(nil)
expect { fixtures_project.post }.to raise_error(StandardError)
expect(File.exist?("hardcover_json_file")).to be_falsy
end
Expand Down
8 changes: 4 additions & 4 deletions spec/slather/coverage_service/html_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

describe '#post' do
before(:each) {
fixtures_project.stub(:print_path_coverage)
allow(fixtures_project).to receive(:print_path_coverage)
fixtures_project.send(:configure)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ def extract_header_title(doc)
end

it "should open the index.html automatically if --show is flagged" do
fixtures_project.stub(:open_coverage)
allow(fixtures_project).to receive(:open_coverage)

fixtures_project.show_html = true
fixtures_project.post
Expand Down Expand Up @@ -180,8 +180,8 @@ def extract_filepath(doc)
(path = doc.at_css('h4.cov_filepath'))? path.text : ""
end

fixtures_project.stub(:input_format).and_return("profdata")
fixtures_project.stub(:profdata_llvm_cov_output).and_return("./spec/fixtures/fixtures/other_fixtures.m:
allow(fixtures_project).to receive(:input_format).and_return("profdata")
allow(fixtures_project).to receive(:profdata_llvm_cov_output).and_return("./spec/fixtures/fixtures/other_fixtures.m:
| 1|//
| 2|// other_fixtures.m
| 3|// fixtures
Expand Down
2 changes: 1 addition & 1 deletion spec/slather/profdata_coverage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
describe "#ignored" do

before(:each) {
fixtures_project.stub(:ignore_list).and_return([])
allow(fixtures_project).to receive(:ignore_list).and_return([])
}

it "shouldn't ignore project files" do
Expand Down
Loading

0 comments on commit b516b95

Please sign in to comment.