From b516b959013fcde991394c5f30a9e14c64291239 Mon Sep 17 00:00:00 2001 From: Richard Lee Date: Thu, 31 Dec 2015 00:15:22 +0800 Subject: [PATCH] Update RSpec --- .travis.yml | 2 +- Rakefile | 7 +- lib/slather/project.rb | 13 ++- slather.gemspec | 4 +- spec/slather/coverage_file_spec.rb | 6 +- .../coverage_service/coveralls_spec.rb | 44 ++++---- .../coverage_service/hardcover_spec.rb | 20 ++-- .../coverage_service/html_output_spec.rb | 8 +- spec/slather/profdata_coverage_spec.rb | 2 +- spec/slather/project_spec.rb | 106 +++++++++--------- 10 files changed, 106 insertions(+), 106 deletions(-) diff --git a/.travis.yml b/.travis.yml index 57831251..8b2fce6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Rakefile b/Rakefile index 6b14ba2b..c92b11ee 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/slather/project.rb b/lib/slather/project.rb index 1de24f17..749cee1f 100644 --- a/lib/slather/project.rb +++ b/lib/slather/project.rb @@ -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`" diff --git a/slather.gemspec b/slather.gemspec index 2a43f6c3..0fe579ea 100644 --- a/slather.gemspec +++ b/slather.gemspec @@ -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" diff --git a/spec/slather/coverage_file_spec.rb b/spec/slather/coverage_file_spec.rb index 0a5f2431..57e4073c 100644 --- a/spec/slather/coverage_file_spec.rb +++ b/spec/slather/coverage_file_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/slather/coverage_service/coveralls_spec.rb b/spec/slather/coverage_service/coveralls_spec.rb index 9bf37029..8dc51fa0 100644 --- a/spec/slather/coverage_service/coveralls_spec.rb +++ b/spec/slather/coverage_service/coveralls_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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 diff --git a/spec/slather/coverage_service/hardcover_spec.rb b/spec/slather/coverage_service/hardcover_spec.rb index 1d07c822..337d9fdb 100644 --- a/spec/slather/coverage_service/hardcover_spec.rb +++ b/spec/slather/coverage_service/hardcover_spec.rb @@ -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 @@ -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 @@ -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 @@ -94,8 +94,8 @@ 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 @@ -103,13 +103,13 @@ 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 diff --git a/spec/slather/coverage_service/html_output_spec.rb b/spec/slather/coverage_service/html_output_spec.rb index 9aaeadcf..7e2e54a7 100644 --- a/spec/slather/coverage_service/html_output_spec.rb +++ b/spec/slather/coverage_service/html_output_spec.rb @@ -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) } @@ -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 @@ -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 diff --git a/spec/slather/profdata_coverage_spec.rb b/spec/slather/profdata_coverage_spec.rb index 3b523d09..f39ab490 100644 --- a/spec/slather/profdata_coverage_spec.rb +++ b/spec/slather/profdata_coverage_spec.rb @@ -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 diff --git a/spec/slather/project_spec.rb b/spec/slather/project_spec.rb index 02581e61..04db60e3 100644 --- a/spec/slather/project_spec.rb +++ b/spec/slather/project_spec.rb @@ -52,19 +52,19 @@ class SpecCoverageFile < Slather::CoverageFile end before(:each) do - Dir.stub(:[]).and_call_original - Dir.stub(:[]).with("#{fixtures_project.build_directory}/**/*.gcno").and_return(["/some/path/fixtures.gcno", + allow(Dir).to receive(:[]).and_call_original + allow(Dir).to receive(:[]).with("#{fixtures_project.build_directory}/**/*.gcno").and_return(["/some/path/fixtures.gcno", "/some/path/peekaview.gcno", "/some/path/fixturesTests.gcno", "/some/path/peekaviewTests.gcno", "/some/path/NotInProject.gcno", "/some/path/NSRange.gcno"]) - fixtures_project.stub(:coverage_file_class).and_return(SpecCoverageFile) + allow(fixtures_project).to receive(:coverage_file_class).and_return(SpecCoverageFile) end it "should return coverage file objects of type coverage_file_class for unignored project files" do fixtures_project.ignore_list = ["*fixturesTests*"] - fixtures_project.stub(:dedupe) { |coverage_files| coverage_files } + allow(fixtures_project).to receive(:dedupe) { |coverage_files| coverage_files } coverage_files = fixtures_project.send(:coverage_files) coverage_files.each { |cf| expect(cf.kind_of?(SpecCoverageFile)).to be_truthy } expect(coverage_files.map { |cf| cf.source_file_pathname.basename.to_s }).to eq(["fixtures.m", "peekaview.m"]) @@ -81,9 +81,9 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile end before(:each) do - Dir.stub(:[]).and_call_original - Dir.stub(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"]) - fixtures_project.stub(:profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}: + allow(Dir).to receive(:[]).and_call_original + allow(Dir).to receive(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"]) + allow(fixtures_project).to receive(:profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}: | 0| | 1|import UIKit | 2| @@ -99,8 +99,8 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile 0| 12| func applicationWillResignActive(application: UIApplication) { 0| 13| } 0| 14|}") - fixtures_project.stub(:coverage_file_class).and_return(SpecXcode7CoverageFile) - fixtures_project.stub(:ignore_list).and_return([]) + allow(fixtures_project).to receive(:coverage_file_class).and_return(SpecXcode7CoverageFile) + allow(fixtures_project).to receive(:ignore_list).and_return([]) end it "should return Coverage.profdata file objects" do @@ -110,7 +110,7 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile end it "should ignore files from the ignore list" do - fixtures_project.stub(:ignore_list).and_return(["**/Fixtures.swift"]) + allow(fixtures_project).to receive(:ignore_list).and_return(["**/Fixtures.swift"]) profdata_coverage_files = fixtures_project.send(:profdata_coverage_files) expect(profdata_coverage_files.count).to eq(0) end @@ -118,10 +118,10 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#invalid_characters" do it "should correctly encode invalid characters" do - fixtures_project.stub(:input_format).and_return("profdata") - fixtures_project.stub(:ignore_list).and_return([]) - Dir.stub(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"]) - fixtures_project.stub(:unsafe_profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}: + allow(fixtures_project).to receive(:input_format).and_return("profdata") + allow(fixtures_project).to receive(:ignore_list).and_return([]) + allow(Dir).to receive(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"]) + allow(fixtures_project).to receive(:unsafe_profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}: 1| 8| func application(application: \255, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 1| 9| return true 0| 14|}") @@ -138,31 +138,31 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile end before(:each) do - Dir.stub(:[]).and_call_original - fixtures_project.stub(:build_directory).and_return(build_directory) - fixtures_project.stub(:input_format).and_return("profdata") - fixtures_project.stub(:scheme).and_return("FixtureScheme") - Dir.stub(:[]).with("#{build_directory}/**/CodeCoverage/FixtureScheme").and_return(["#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme"]) - Dir.stub(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/**/*.xctest").and_return(["#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureAppTests.xctest"]) + allow(Dir).to receive(:[]).and_call_original + allow(fixtures_project).to receive(:build_directory).and_return(build_directory) + allow(fixtures_project).to receive(:input_format).and_return("profdata") + allow(fixtures_project).to receive(:scheme).and_return("FixtureScheme") + allow(Dir).to receive(:[]).with("#{build_directory}/**/CodeCoverage/FixtureScheme").and_return(["#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme"]) + allow(Dir).to receive(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/**/*.xctest").and_return(["#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureAppTests.xctest"]) end it "should return the binary file location for an app bundle provided a scheme" do - Dir.stub(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/*.app").and_return(["/FixtureScheme/FixtureApp.app"]) - Dir.stub(:[]).with("/FixtureScheme/FixtureApp.app/**/FixtureApp").and_return(["/FixtureScheme/FixtureApp.app/FixtureApp"]) + allow(Dir).to receive(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/*.app").and_return(["/FixtureScheme/FixtureApp.app"]) + allow(Dir).to receive(:[]).with("/FixtureScheme/FixtureApp.app/**/FixtureApp").and_return(["/FixtureScheme/FixtureApp.app/FixtureApp"]) fixtures_project.send(:configure_binary_file) binary_file_location = fixtures_project.send(:binary_file) expect(binary_file_location).to eq("/FixtureScheme/FixtureApp.app/FixtureApp") end it "should return the binary file location for a framework bundle provided a scheme" do - Dir.stub(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/*.framework").and_return(["/FixtureScheme/FixtureFramework.framework"]) + allow(Dir).to receive(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/*.framework").and_return(["/FixtureScheme/FixtureFramework.framework"]) fixtures_project.send(:configure_binary_file) binary_file_location = fixtures_project.send(:binary_file) expect(binary_file_location).to eq("/FixtureScheme/FixtureFramework.framework/FixtureFramework") end it "should return the binary file location for a test bundle provided a scheme" do - Dir.stub(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureAppTests.xctest/**/FixtureAppTests").and_return(["/FixtureScheme/FixtureAppTests.xctest/Contents/MacOS/FixtureAppTests"]) + allow(Dir).to receive(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureAppTests.xctest/**/FixtureAppTests").and_return(["/FixtureScheme/FixtureAppTests.xctest/Contents/MacOS/FixtureAppTests"]) fixtures_project.send(:configure_binary_file) binary_file_location = fixtures_project.send(:binary_file) expect(binary_file_location).to eq("/FixtureScheme/FixtureAppTests.xctest/Contents/MacOS/FixtureAppTests") @@ -176,7 +176,7 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile end it "should configure the binary_file from yml" do - Slather::Project.stub(:yml).and_return(fixture_yaml) + allow(Slather::Project).to receive(:yml).and_return(fixture_yaml) fixtures_project.send(:configure_binary_file) binary_file_location = fixtures_project.send(:binary_file) expect(binary_file_location).to eq("/FixtureScheme/From/Yaml/Contents/MacOS/FixturesFromYaml") @@ -190,8 +190,8 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile end it "should configure the binary_basename from yml" do - Slather::Project.stub(:yml).and_return(other_fixture_yaml) - Dir.stub(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureFramework.framework").and_return(["/FixtureScheme/FixtureFramework.framework"]) + allow(Slather::Project).to receive(:yml).and_return(other_fixture_yaml) + allow(Dir).to receive(:[]).with("#{build_directory}/Build/Intermediates/CodeCoverage/FixtureScheme/FixtureFramework.framework").and_return(["/FixtureScheme/FixtureFramework.framework"]) fixtures_project.send(:configure_binary_file) binary_file_location = fixtures_project.send(:binary_file) expect(binary_file_location).to eq("/FixtureScheme/FixtureFramework.framework/FixtureFramework") @@ -209,16 +209,16 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#dedupe" do it "should return a deduplicated list of coverage files, favoring the file with higher coverage" do coverage_file_1 = double(Slather::CoverageFile) - coverage_file_1.stub(:source_file_pathname).and_return("some/path/class1.m") - coverage_file_1.stub(:percentage_lines_tested).and_return(100) + allow(coverage_file_1).to receive(:source_file_pathname).and_return("some/path/class1.m") + allow(coverage_file_1).to receive(:percentage_lines_tested).and_return(100) coverage_file_2 = double(Slather::CoverageFile) - coverage_file_2.stub(:source_file_pathname).and_return("some/path/class2.m") - coverage_file_2.stub(:percentage_lines_tested).and_return(100) + allow(coverage_file_2).to receive(:source_file_pathname).and_return("some/path/class2.m") + allow(coverage_file_2).to receive(:percentage_lines_tested).and_return(100) coverage_file_2b = double(Slather::CoverageFile) - coverage_file_2b.stub(:source_file_pathname).and_return("some/path/class2.m") - coverage_file_2b.stub(:percentage_lines_tested).and_return(0) + allow(coverage_file_2b).to receive(:source_file_pathname).and_return("some/path/class2.m") + allow(coverage_file_2b).to receive(:percentage_lines_tested).and_return(0) coverage_files = [coverage_file_1, coverage_file_2, coverage_file_2b] deduped_coverage_files = fixtures_project.send(:dedupe, coverage_files) @@ -244,26 +244,26 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_ignore_list" do it "should set the ignore_list if it has been provided in the yml and has not already been set" do - Slather::Project.stub(:yml).and_return({"ignore" => ["test", "ing"] }) + allow(Slather::Project).to receive(:yml).and_return({"ignore" => ["test", "ing"] }) fixtures_project.configure_ignore_list expect(fixtures_project.ignore_list).to eq(["test", "ing"]) end it "should force the ignore_list into an array" do - Slather::Project.stub(:yml).and_return({"ignore" => "test" }) + allow(Slather::Project).to receive(:yml).and_return({"ignore" => "test" }) fixtures_project.configure_ignore_list expect(fixtures_project.ignore_list).to eq(["test"]) end it "should not set the ignore_list if it has already been set" do - Slather::Project.stub(:yml).and_return({"ignore" => ["test", "ing"] }) + allow(Slather::Project).to receive(:yml).and_return({"ignore" => ["test", "ing"] }) fixtures_project.ignore_list = ["already", "set"] fixtures_project.configure_ignore_list expect(fixtures_project.ignore_list).to eq(["already", "set"]) end it "should default the ignore_list to an empty array if nothing is provided in the yml" do - Slather::Project.stub(:yml).and_return({}) + allow(Slather::Project).to receive(:yml).and_return({}) fixtures_project.configure_ignore_list expect(fixtures_project.ignore_list).to eq([]) end @@ -271,20 +271,20 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_build_directory" do it "should set the build_directory if it has been provided in the yml and has not already been set" do - Slather::Project.stub(:yml).and_return({"build_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"build_directory" => "/some/path"}) fixtures_project.configure_build_directory expect(fixtures_project.build_directory).to eq("/some/path") end it "should not set the build_directory if it has already been set" do - Slather::Project.stub(:yml).and_return({"build_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"build_directory" => "/some/path"}) fixtures_project.build_directory = "/already/set" fixtures_project.configure_build_directory expect(fixtures_project.build_directory).to eq("/already/set") end it "should default the build_directory to derived data if nothing is provided in the yml" do - Slather::Project.stub(:yml).and_return({}) + allow(Slather::Project).to receive(:yml).and_return({}) fixtures_project.configure_build_directory expect(fixtures_project.build_directory).to eq(fixtures_project.send(:derived_data_path)) end @@ -292,13 +292,13 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_source_directory" do it "should set the source_directory if it has been provided in the yml and has not already been set" do - Slather::Project.stub(:yml).and_return({"source_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"source_directory" => "/some/path"}) fixtures_project.configure_source_directory expect(fixtures_project.source_directory).to eq("/some/path") end it "should not set the source_directory if it has already been set" do - Slather::Project.stub(:yml).and_return({"source_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"source_directory" => "/some/path"}) fixtures_project.source_directory = "/already/set" fixtures_project.configure_source_directory expect(fixtures_project.source_directory).to eq("/already/set") @@ -307,13 +307,13 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_output_directory" do it "should set the output_directory if it has been provided in the yml and has not already been set" do - Slather::Project.stub(:yml).and_return({"output_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"output_directory" => "/some/path"}) fixtures_project.configure_output_directory expect(fixtures_project.output_directory).to eq("/some/path") end it "should not set the output_directory if it has already been set" do - Slather::Project.stub(:yml).and_return({"output_directory" => "/some/path"}) + allow(Slather::Project).to receive(:yml).and_return({"output_directory" => "/some/path"}) fixtures_project.output_directory = "/already/set" fixtures_project.configure_output_directory expect(fixtures_project.output_directory).to eq("/already/set") @@ -322,20 +322,20 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_ci_service" do it "should set the ci_service if it has been provided in the yml and has not already been set" do - Slather::Project.stub(:yml).and_return({"ci_service" => "some_service"}) + allow(Slather::Project).to receive(:yml).and_return({"ci_service" => "some_service"}) fixtures_project.configure_ci_service expect(fixtures_project.ci_service).to eq(:some_service) end it "should not set the ci_service if it has already been set" do - Slather::Project.stub(:yml).and_return({"ci_service" => "some service"}) + allow(Slather::Project).to receive(:yml).and_return({"ci_service" => "some service"}) fixtures_project.ci_service = "already_set" fixtures_project.configure_ci_service expect(fixtures_project.ci_service).to eq(:already_set) end it "should default the ci_service to :travis_ci if nothing is provided in the yml" do - Slather::Project.stub(:yml).and_return({}) + allow(Slather::Project).to receive(:yml).and_return({}) fixtures_project.configure_ci_service expect(fixtures_project.ci_service).to eq(:travis_ci) end @@ -350,20 +350,20 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_coverage_service" do it "should set the coverage_service if it has been provided by the yml" do - Slather::Project.stub(:yml).and_return({"coverage_service" => "some_service"}) + allow(Slather::Project).to receive(:yml).and_return({"coverage_service" => "some_service"}) expect(fixtures_project).to receive(:coverage_service=).with("some_service") fixtures_project.configure_coverage_service end it "should default the coverage_service to :terminal if nothing is provided in the yml" do - Slather::Project.stub(:yml).and_return({}) + allow(Slather::Project).to receive(:yml).and_return({}) expect(fixtures_project).to receive(:coverage_service=).with(:terminal) fixtures_project.configure_coverage_service end it "should not set the coverage_service if it has already been set" do - Slather::Project.stub(:yml).and_return({"coverage_service" => "some_service" }) - fixtures_project.stub(:coverage_service).and_return("already set") + allow(Slather::Project).to receive(:yml).and_return({"coverage_service" => "some_service" }) + allow(fixtures_project).to receive(:coverage_service).and_return("already set") expect(fixtures_project).to_not receive(:coverage_service=) fixtures_project.configure_coverage_service end @@ -371,7 +371,7 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile describe "#configure_coverage_access_token" do it "should set the coverage_access_token if it has been provided by the yml" do - Slather::Project.stub(:yml).and_return({"coverage_access_token" => "abc123"}) + allow(Slather::Project).to receive(:yml).and_return({"coverage_access_token" => "abc123"}) expect(fixtures_project).to receive(:coverage_access_token=).with("abc123") fixtures_project.configure_coverage_access_token end @@ -406,7 +406,7 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile let(:fixtures_project_setup) do FileUtils.cp_r "#{FIXTURES_PROJECT_PATH}/", "#{FIXTURES_PROJECT_SETUP_PATH}/" - Slather::Project.any_instance.stub(:configure) + allow_any_instance_of(Slather::Project).to receive(:configure) Slather::Project.open(FIXTURES_PROJECT_SETUP_PATH) end