| 1 |
require_relative "../../test_helper" |
| 2 |
|
| 3 |
module MinitestReportersTest |
| 4 |
class JUnitReporterUnitTest < Minitest::Test |
| 5 |
def setup |
| 6 |
@reporter = Minitest::Reporters::JUnitReporter.new( |
| 7 |
"report", |
| 8 |
false, |
| 9 |
:base_apath => Dir.pwd |
| 10 |
) |
| 11 |
@result = Minitest::Result.new("test_name") |
| 12 |
end |
| 13 |
|
| 14 |
def test_relative_path |
| 15 |
path = Pathname.new(__FILE__).relative_path_from(Pathname.new(Dir.pwd)).to_s |
| 16 |
@result.source_location = [path, 10] |
| 17 |
relative_path = @reporter.get_relative_path(@result) |
| 18 |
assert_equal path, relative_path.to_s |
| 19 |
end |
| 20 |
|
| 21 |
def test_defaults_reports_path |
| 22 |
reporter = Minitest::Reporters::JUnitReporter.new |
| 23 |
expected_reports_dir = Minitest::Reporters::JUnitReporter::DEFAULT_REPORTS_DIR |
| 24 |
expected_reports_path = File.absolute_path(expected_reports_dir) |
| 25 |
assert_equal expected_reports_path, reporter.reports_path |
| 26 |
end |
| 27 |
|
| 28 |
def test_accepts_custom_report_dir_using_env |
| 29 |
expected_reports_dir = "test_reports" |
| 30 |
expected_reports_path = File.absolute_path(expected_reports_dir) |
| 31 |
with_env("MINITEST_REPORTERS_REPORTS_DIR" => expected_reports_dir) do |
| 32 |
reporter = Minitest::Reporters::JUnitReporter.new |
| 33 |
assert_equal expected_reports_path, reporter.reports_path |
| 34 |
end |
| 35 |
end |
| 36 |
|
| 37 |
private |
| 38 |
|
| 39 |
def with_env(hash) |
| 40 |
original_env = ENV.to_hash |
| 41 |
ENV.update(hash) |
| 42 |
yield |
| 43 |
ENV.replace(original_env) |
| 44 |
end |
| 45 |
end |
| 46 |
end |