Skip to content

Commit

Permalink
Test all RSpec versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyasha committed Jul 27, 2017
1 parent 00b3a1f commit 8c74b17
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
2 changes: 2 additions & 0 deletions spec/integration/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
97 changes: 59 additions & 38 deletions spec/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8c74b17

Please sign in to comment.