From 8c74b17fac535db25d85dabb5931990772941959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=A0ar=C4=8Devi=C4=87?= Date: Thu, 27 Jul 2017 11:14:08 +0200 Subject: [PATCH] Test all RSpec versions --- spec/integration/integration_helper.rb | 2 + spec/integration/rspec_spec.rb | 97 ++++++++++++++++---------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/spec/integration/integration_helper.rb b/spec/integration/integration_helper.rb index ae0a805..6d49317 100644 --- a/spec/integration/integration_helper.rb +++ b/spec/integration/integration_helper.rb @@ -3,6 +3,8 @@ class TestRepo REPO = "https://github.com/renderedtext/test-boosters-tests.git".freeze + attr_reader :project_path + def initialize(test_project) @repo_path = "/tmp/test-boosters-tests" @project_path = "/tmp/test-boosters-tests/#{test_project}" diff --git a/spec/integration/rspec_spec.rb b/spec/integration/rspec_spec.rb index aa4ae4c..2b3aedd 100644 --- a/spec/integration/rspec_spec.rb +++ b/spec/integration/rspec_spec.rb @@ -3,61 +3,82 @@ describe "RSpec Booster", :integration do - before(:all) do - @split_configuration_path = "/tmp/rspec_split_configuration.json" + shared_examples "an rspec booster" do |options| + before(:all) do + @rspec_version = options.fetch(:rspec_version) - @test_repo = IntegrationHelper::TestRepo.new("rspec_project") - @test_repo.clone - @test_repo.set_env_var("RSPEC_SPLIT_CONFIGURATION_PATH", @split_configuration_path) + puts "======================================================================" + puts "Testing RSpec Booster with RSpec version #{@rspec_version} " + puts "======================================================================" - File.write(@split_configuration_path, [ - { :files => [] }, - { :files => ["spec/lib/a_spec.rb"] } - ].to_json) + @split_configuration_path = "/tmp/rspec_split_configuration.json" - @test_repo.run_command("bundle install --path vendor/bundle") - end + @test_repo = IntegrationHelper::TestRepo.new("rspec_project") + @test_repo.clone + @test_repo.set_env_var("RSPEC_SPLIT_CONFIGURATION_PATH", @split_configuration_path) - before { FileUtils.rm_f("#{ENV["HOME"]}/rspec_report.json") } + # set RSpec version of the test project + rspec_dependancy_pattern = 'spec.add_development_dependency "rspec".*$' + rspec_dependancy_version = "spec.add_development_dependency \"rspec\", '#{@rspec_version}'" + system(%Q{sed -i 's/#{rspec_dependancy_pattern}/#{rspec_dependancy_version}/' #{@test_repo.project_path}/rspec_project.gemspec}) - specify "first job's behaviour" do - output = @test_repo.run_booster("rspec_booster --job 1/3") + File.write(@split_configuration_path, [ + { :files => [] }, + { :files => ["spec/lib/a_spec.rb"] } + ].to_json) - expect(output).to include("3 examples, 1 failure") - expect($?.exitstatus).to eq(1) + @test_repo.run_command("bundle install --path vendor/bundle") + end - expect(File).to exist("#{ENV["HOME"]}/rspec_report.json") - end + before { FileUtils.rm_f("#{ENV["HOME"]}/rspec_report.json") } - specify "second job's behaviour" do - output = @test_repo.run_booster("rspec_booster --job 2/3") + specify "first job's behaviour" do + output = @test_repo.run_booster("rspec_booster --job 1/3") - expect(output).to include("1 example, 0 failures") - expect($?.exitstatus).to eq(0) + expect(output).to include("3 examples, 1 failure") + expect($?.exitstatus).to eq(1) - expect(File).to exist("#{ENV["HOME"]}/rspec_report.json") - end + expect(File).to exist("#{ENV["HOME"]}/rspec_report.json") + end - specify "third job's behaviour" do - output = @test_repo.run_booster("rspec_booster --job 3/3") + specify "second job's behaviour" do + output = @test_repo.run_booster("rspec_booster --job 2/3") - expect(output).to include("No files to run in this job!") - expect($?.exitstatus).to eq(0) + expect(output).to include("1 example, 0 failures") + expect($?.exitstatus).to eq(0) - expect(File).to_not exist("#{ENV["HOME"]}/rspec_report.json") - end + expect(File).to exist("#{ENV["HOME"]}/rspec_report.json") + end - specify "rspec_report format" do - @test_repo.run_booster("rspec_booster --job 1/3") + specify "third job's behaviour" do + output = @test_repo.run_booster("rspec_booster --job 3/3") - report = JSON.parse(File.read("#{ENV["HOME"]}/rspec_report.json")) - expected = JSON.parse(File.read("spec/expected_rspec_report_format.json")) + expect(output).to include("No files to run in this job!") + expect($?.exitstatus).to eq(0) - # ignore actual runtimes - report["examples"].each { |e| e["run_time"] = 0 } - expected["examples"].each { |e| e["run_time"] = 0 } + expect(File).to_not exist("#{ENV["HOME"]}/rspec_report.json") + end - expect(report).to eq(expected) + specify "rspec_report format" do + @test_repo.run_booster("rspec_booster --job 1/3") + + report = JSON.parse(File.read("#{ENV["HOME"]}/rspec_report.json")) + expected = JSON.parse(File.read("spec/expected_rspec_report_format.json")) + + # ignore actual runtimes + report["examples"].each { |e| e["run_time"] = 0 } + expected["examples"].each { |e| e["run_time"] = 0 } + + expect(report).to eq(expected) + end end + it_behaves_like "an rspec booster", :rspec_version => 3.6 + it_behaves_like "an rspec booster", :rspec_version => 3.5 + it_behaves_like "an rspec booster", :rspec_version => 3.4 + it_behaves_like "an rspec booster", :rspec_version => 3.3 + it_behaves_like "an rspec booster", :rspec_version => 3.2 + it_behaves_like "an rspec booster", :rspec_version => 3.1 + it_behaves_like "an rspec booster", :rspec_version => 3.0 + end