Skip to content

Commit

Permalink
CI: support Ruby 3.4+ error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Dec 27, 2024
1 parent b9a6070 commit a416874
Showing 1 changed file with 137 additions and 88 deletions.
225 changes: 137 additions & 88 deletions spec/cucumber/formatter/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,45 @@ module Formatter
end

it 'outputs the json data' do
expect(load_normalised_json(@out)).to eq JSON.parse(%{
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
expected_error_message =
if RUBY_VERSION < '3.4'
<<~ERROR.chomp
no bananas (RuntimeError)
./spec/cucumber/formatter/json_spec.rb:99:in `/^there are bananas$/'
spec.feature:4:in `there are bananas'
ERROR
else
<<~ERROR.chomp
no bananas (RuntimeError)
./spec/cucumber/formatter/json_spec.rb:99:in 'block (4 levels) in <module:Formatter>'
./spec/cucumber/formatter/spec_helper.rb:29:in 'Cucumber::Formatter::SpecHelper#run_defined_feature'
./spec/cucumber/formatter/json_spec.rb:18:in 'block (2 levels) in <module:Formatter>'
spec.feature:4:in `there are bananas'
ERROR
end
expect(load_normalised_json(@out)).to eq JSON.parse(<<~JSON)
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:99"},
"result": {"status": "failed",
"error_message": "no bananas (RuntimeError)\\n./spec/cucumber/formatter/json_spec.rb:99:in `/^there are bananas$/'\\nspec.feature:4:in `there are bananas'",
"duration": 1}}]}]}]})
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:99"},
"result": {"status": "failed",
"error_message": #{expected_error_message.to_json},
"duration": 1}}]}]}]
JSON
end
end

Expand All @@ -138,28 +155,45 @@ module Formatter
end

it 'outputs the json data' do
expect(load_normalised_json(@out)).to eq JSON.parse(%{
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:137"},
"result": {"status": "pending",
"error_message": "TODO (Cucumber::Pending)\\n./spec/cucumber/formatter/json_spec.rb:137:in `/^there are bananas$/'\\nspec.feature:4:in `there are bananas'",
"duration": 1}}]}]}]})
expected_error_message =
if RUBY_VERSION < '3.4'
<<~ERROR.chomp
TODO (Cucumber::Pending)
./spec/cucumber/formatter/json_spec.rb:154:in `/^there are bananas$/'
spec.feature:4:in `there are bananas'
ERROR
else
<<~ERROR.chomp
TODO (Cucumber::Pending)
./spec/cucumber/formatter/json_spec.rb:154:in 'block (4 levels) in <module:Formatter>'
./spec/cucumber/formatter/spec_helper.rb:29:in 'Cucumber::Formatter::SpecHelper#run_defined_feature'
./spec/cucumber/formatter/json_spec.rb:18:in 'block (2 levels) in <module:Formatter>'
spec.feature:4:in `there are bananas'
ERROR
end
expect(load_normalised_json(@out)).to eq JSON.parse(<<~JSON)
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:154"},
"result": {"status": "pending",
"error_message": #{expected_error_message.to_json},
"duration": 1}}]}]}]
JSON
end
end

Expand Down Expand Up @@ -198,7 +232,7 @@ module Formatter
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:179"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:213"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -252,7 +286,7 @@ module Formatter
[{"keyword": "Given ",
"name": "there are bananas",
"line": 6,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:227"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:261"},
"result": {"status": "passed",
"duration": 1}}]},
{"id": "banana-party;monkey-eats-bananas;fruit-table;2",
Expand All @@ -271,7 +305,7 @@ module Formatter
[{"keyword": "Given ",
"name": "there are bananas",
"line": 10,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:227"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:261"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -326,7 +360,7 @@ module Formatter
[{"keyword": "Given ",
"name": "there are bananas",
"line": 6,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:307"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:341"},
"result": {"status": "passed",
"duration": 1}}]},
{"id": "banana-party;monkey-eats-bananas",
Expand All @@ -339,7 +373,7 @@ module Formatter
[{"keyword": "Then ",
"name": "the monkey eats bananas",
"line": 11,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:308"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:342"},
"result": {"status": "passed",
"duration": 1}}]},
{"keyword": "Background",
Expand All @@ -351,7 +385,7 @@ module Formatter
[{"keyword": "Given ",
"name": "there are bananas",
"line": 6,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:307"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:341"},
"result": {"status": "passed",
"duration": 1}}]},
{"id": "banana-party;monkey-eats-bananas;fruit-table;2",
Expand All @@ -364,7 +398,7 @@ module Formatter
[{"keyword": "Then ",
"name": "the monkey eats bananas",
"line": 16,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:308"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:342"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -407,7 +441,7 @@ module Formatter
"doc_string": {"value": "the doc string",
"content_type": "",
"line": 5},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:385"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:419"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -445,7 +479,7 @@ module Formatter
"name": "there are bananas",
"line": 4,
"output": ["from step"],
"match": {"location": "spec/cucumber/formatter/json_spec.rb:425"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:459"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -556,7 +590,7 @@ module Formatter
"line": 4,
"embeddings": [{"mime_type": "mime-type",
"data": "YWJj"}],
"match": {"location": "spec/cucumber/formatter/json_spec.rb:535"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:569"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -599,7 +633,7 @@ module Formatter
"line": 4,
"embeddings": [{"mime_type": "image/png",
"data": "Zm9v"}],
"match": {"location": "spec/cucumber/formatter/json_spec.rb:574"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:608"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down Expand Up @@ -640,31 +674,31 @@ module Formatter
"description": "",
"type": "scenario",
"before":
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:617"},
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:651"},
"result": {"status": "passed",
"duration": 1}},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:618"},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:652"},
"result": {"status": "passed",
"duration": 1}}],
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:624"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:658"},
"result": {"status": "passed",
"duration": 1},
"after":
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:621"},
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:655"},
"result": {"status": "passed",
"duration": 1}},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:622"},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:656"},
"result": {"status": "passed",
"duration": 1}}]}],
"after":
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:620"},
[{"match": {"location": "spec/cucumber/formatter/json_spec.rb:654"},
"result": {"status": "passed",
"duration": 1}},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:619"},
{"match": {"location": "spec/cucumber/formatter/json_spec.rb:653"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand All @@ -687,32 +721,47 @@ module Formatter
end

it 'includes the around hook result in the json data' do
expect(load_normalised_json(@out)).to eq JSON.parse(%{
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:686"},
"result": {"status": "passed",
"duration": 1}}],
"around":
[{"match": {"location": "unknown_hook_location:1"},
"result": {"status": "failed",
"error_message": "error (RuntimeError)\\n./spec/cucumber/formatter/json_spec.rb:684:in `Around'",
"duration": 1}}]}]}]})
expected_error_message =
if RUBY_VERSION < '3.4'
<<~ERROR.chomp
error (RuntimeError)
./spec/cucumber/formatter/json_spec.rb:718:in `Around'
ERROR
else
<<~ERROR.chomp
error (RuntimeError)
./spec/cucumber/formatter/json_spec.rb:718:in 'block (4 levels) in <module:Formatter>'
./spec/cucumber/formatter/spec_helper.rb:29:in 'Cucumber::Formatter::SpecHelper#run_defined_feature'
./spec/cucumber/formatter/json_spec.rb:18:in 'block (2 levels) in <module:Formatter>'
ERROR
end
expect(load_normalised_json(@out)).to eq JSON.parse(<<~JSON)
[{"id": "banana-party",
"uri": "spec.feature",
"keyword": "Feature",
"name": "Banana party",
"line": 1,
"description": "",
"elements":
[{"id": "banana-party;monkey-eats-bananas",
"keyword": "Scenario",
"name": "Monkey eats bananas",
"line": 3,
"description": "",
"type": "scenario",
"steps":
[{"keyword": "Given ",
"name": "there are bananas",
"line": 4,
"match": {"location": "spec/cucumber/formatter/json_spec.rb:720"},
"result": {"status": "passed",
"duration": 1}}],
"around":
[{"match": {"location": "unknown_hook_location:1"},
"result": {"status": "failed",
"error_message": #{expected_error_message.to_json},
"duration": 1}}]}]}]
JSON
end
end

Expand Down Expand Up @@ -752,7 +801,7 @@ module Formatter
"rows":
[{"cells": ["aa", "bb"]},
{"cells": ["cc", "dd"]}],
"match": {"location": "spec/cucumber/formatter/json_spec.rb:730"},
"match": {"location": "spec/cucumber/formatter/json_spec.rb:779"},
"result": {"status": "passed",
"duration": 1}}]}]}]))
end
Expand Down

0 comments on commit a416874

Please sign in to comment.