Skip to content

Commit

Permalink
Write test for rspec output with shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyasha committed Jul 20, 2017
1 parent 0f7c185 commit 9fb2012
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AllCops:
- "lib/test_boosters/cucumber_booster.rb"
- "test_data_pass/**/*"
- "test_data_fail/**/*"
- "rspec_formatters/semaphore_rspec3_json_formatter.rb"

Style/StringLiterals:
EnforcedStyle: double_quotes
Expand Down
2 changes: 2 additions & 0 deletions lib/test_boosters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ module TestBoosters
require "test_boosters/boosters/go_test"
require "test_boosters/boosters/ex_unit"
require "test_boosters/boosters/minitest"

ROOT_PATH = File.absolute_path(File.dirname(__FILE__) + "/..")
end
7 changes: 6 additions & 1 deletion lib/test_boosters/boosters/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def command
end

def rspec_options
@rspec_options ||= "#{ENV["TB_RSPEC_OPTIONS"]} --format documentation --format json --out #{report_path}"
# rubocop:disable LineLength
@rspec_options ||= "#{ENV["TB_RSPEC_OPTIONS"]} --format documentation --require #{formatter_path} --format SemaphoreFormatter --out #{report_path}"
end

def report_path
Expand All @@ -36,6 +37,10 @@ def split_configuration_path
ENV["RSPEC_SPLIT_CONFIGURATION_PATH"] || "#{ENV["HOME"]}/rspec_split_configuration.json"
end

def formatter_path
@formatter_path ||= File.join(::TestBoosters::ROOT_PATH, "rspec_formatters/semaphore_rspec3_json_formatter.rb")
end

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ def initialize(output)
end

def stop(notification)
@output_hash[:examples] = notification.examples.map do |example|
format_example(example).tap do |hash|
if exception = example.exception
hash[:exception] = {
:class => exception.class.name,
:message => exception.message,
:backtrace => exception.backtrace,
}
end
end
end
@output_hash[:examples] = notification.examples.map { |example| format_example(example) }
end

def close(_notification)
Expand Down
25 changes: 25 additions & 0 deletions spec/expected_rspec_report_format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"examples": [
{
"description": "has a version number",
"full_description": "RspecProject has a version number",
"status": "passed",
"file_path": "./spec/rspec_project_spec.rb",
"run_time": 0.00055454
},
{
"description": "does something useful",
"full_description": "RspecProject does something useful",
"status": "failed",
"file_path": "./spec/rspec_project_spec.rb",
"run_time": 0.010931278
},
{
"description": "does something interesting",
"full_description": "RspecProject behaves like a test with shared examples does something interesting",
"status": "passed",
"file_path": "./spec/rspec_project_spec.rb",
"run_time": 0.000126273
}
]
}
15 changes: 14 additions & 1 deletion spec/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
specify "first job's behaviour" do
output = @test_repo.run_booster("rspec_booster --job 1/3")

expect(output).to include("2 examples, 1 failure")
expect(output).to include("3 examples, 1 failure")
expect($?.exitstatus).to eq(1)

expect(File).to exist("#{ENV["HOME"]}/rspec_report.json")
Expand All @@ -47,4 +47,17 @@
expect(File).to_not exist("#{ENV["HOME"]}/rspec_report.json")
end

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

0 comments on commit 9fb2012

Please sign in to comment.