From d6fbf444606014086baeb93b34cd3f27ed755282 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 24 Jun 2017 23:17:03 +0200 Subject: [PATCH] Step: Rename name to text --- lib/cucumber/filters/activate_steps.rb | 5 +-- lib/cucumber/formatter/console.rb | 2 +- lib/cucumber/formatter/json.rb | 1 + lib/cucumber/formatter/legacy_api/adapter.rb | 23 +++++++---- lib/cucumber/formatter/legacy_api/ast.rb | 2 +- spec/cucumber/filters/activate_steps_spec.rb | 8 ++-- spec/cucumber/formatter/json_spec.rb | 42 ++++++++++---------- spec/cucumber/formatter/junit_spec.rb | 4 +- spec/support/standard_step_actions.rb | 2 +- 9 files changed, 49 insertions(+), 40 deletions(-) diff --git a/lib/cucumber/filters/activate_steps.rb b/lib/cucumber/filters/activate_steps.rb index 14773c41e0..7af8b71f7e 100644 --- a/lib/cucumber/filters/activate_steps.rb +++ b/lib/cucumber/filters/activate_steps.rb @@ -44,11 +44,10 @@ def initialize(step_match_search, configuration, test_step) def result begin - return NoStepMatch.new(test_step.source.last, test_step.name) unless matches.any? + return NoStepMatch.new(test_step.source.last, test_step.text) unless matches.any? rescue Cucumber::Ambiguous => e return AmbiguousStepMatch.new(e) end - configuration.notify :step_activated, test_step, match return SkippingStepMatch.new if configuration.dry_run? match @@ -64,7 +63,7 @@ def match end def matches - step_match_search.call(test_step.name) + step_match_search.call(test_step.text) end end end diff --git a/lib/cucumber/formatter/console.rb b/lib/cucumber/formatter/console.rb index 401e1e9079..83cf3f03a7 100644 --- a/lib/cucumber/formatter/console.rb +++ b/lib/cucumber/formatter/console.rb @@ -135,7 +135,7 @@ def print_snippets(options) def do_print_snippets(snippet_text_proc) snippets = @snippets_input.map do |data| - snippet_text_proc.call(data.actual_keyword, data.step.name, data.step.multiline_arg) + snippet_text_proc.call(data.actual_keyword, data.step.text, data.step.multiline_arg) end.uniq text = "\nYou can implement step definitions for undefined steps with these snippets:\n\n" diff --git a/lib/cucumber/formatter/json.rb b/lib/cucumber/formatter/json.rb index db2e2f83ab..6e46d1d01a 100644 --- a/lib/cucumber/formatter/json.rb +++ b/lib/cucumber/formatter/json.rb @@ -14,6 +14,7 @@ class Json def initialize(config) @io = ensure_io(config.out_stream) @feature_hashes = [] + @step_or_hook_hash = {} config.on_event :test_case_started, &method(:on_test_case_started) config.on_event :test_case_finished, &method(:on_test_case_finished) config.on_event :test_step_started, &method(:on_test_step_started) diff --git a/lib/cucumber/formatter/legacy_api/adapter.rb b/lib/cucumber/formatter/legacy_api/adapter.rb index 4ef38b901b..08347dec8a 100644 --- a/lib/cucumber/formatter/legacy_api/adapter.rb +++ b/lib/cucumber/formatter/legacy_api/adapter.rb @@ -201,7 +201,7 @@ def method_missing(name, node, step_result, *_args) class StepSource < OpenStruct def build_step_invocation(indent, matches, config, messages, embeddings) step_result.step_invocation( - matches.fetch(step) { NoStepMatch.new(step, step.name) }, + matches.fetch(step) { NoStepMatch.new(step, step.text) }, step, indent, background, @@ -404,7 +404,7 @@ def switch_to_child(child, source) @previous_outline_child.after unless same_scenario_outline_as_previous_test_case?(source) end end - if from_scenario_outline_to_hidden_backgroud(@child, child) + if from_scenario_outline_to_hidden_background(@child, child) @previous_outline_child = @child else @child.after @@ -415,7 +415,7 @@ def switch_to_child(child, source) @child = child end - def from_scenario_outline_to_hidden_backgroud(from, to) + def from_scenario_outline_to_hidden_background(from, to) from.class.name == ScenarioOutlinePrinter.name && to.class.name == HiddenBackgroundPrinter.name end @@ -657,7 +657,7 @@ def scenario_outline(_node, &descend) end def outline_step(step) - step_match = NoStepMatch.new(step, step.name) + step_match = NoStepMatch.new(step, step.text) step_invocation = LegacyResultBuilder.new(Core::Test::Result::Skipped.new). step_invocation(step_match, step, indent, nil, configuration, [], []) steps_printer.step_invocation step_invocation @@ -920,7 +920,7 @@ def initialize(node) [:step, :outline_step].each do |node_name| define_method(node_name) do |node| - record_width_of node + record_width_of_step node end end @@ -930,12 +930,21 @@ def examples_table_row(*); end def of(node) # The length of the instantiated steps in --expand mode are currently # not included in the calculation of max => make sure to return >= 1 - [1, max - node.name.length - node.keyword.length].max + if node.respond_to?(:name) + [1, max - node.name.length - node.keyword.length].max + else + [1, max - node.text.length - node.keyword.length].max + end + end def record_width_of(node) @widths << node.keyword.length + node.name.length + 1 end + + def record_width_of_step(node) + @widths << node.keyword.length + node.text.length + 1 + end private @@ -1006,7 +1015,7 @@ def describe_exception_to(formatter) def step_exception(step, configuration) return filtered_step_exception(step) if @exception return nil unless @status == :undefined && configuration.strict.strict?(:undefined) - @exception = Cucumber::Undefined.from(@result, step.name) + @exception = Cucumber::Undefined.from(@result, step.text) @exception.backtrace << step.backtrace_line filtered_step_exception(step) end diff --git a/lib/cucumber/formatter/legacy_api/ast.rb b/lib/cucumber/formatter/legacy_api/ast.rb index 982643f7a2..aa0f124349 100644 --- a/lib/cucumber/formatter/legacy_api/ast.rb +++ b/lib/cucumber/formatter/legacy_api/ast.rb @@ -103,7 +103,7 @@ def describe_exception_to(formatter) :embeddings) do extend Forwardable - def_delegators :step, :keyword, :name, :multiline_arg, :location + def_delegators :step, :keyword, :text, :multiline_arg, :location def accept(formatter) formatter.before_step(self) diff --git a/spec/cucumber/filters/activate_steps_spec.rb b/spec/cucumber/filters/activate_steps_spec.rb index dc14ffd978..17d4d2c270 100644 --- a/spec/cucumber/filters/activate_steps_spec.rb +++ b/spec/cucumber/filters/activate_steps_spec.rb @@ -27,7 +27,7 @@ it 'activates each step' do expect(step_match).to receive(:activate) do |test_step| - expect(test_step.name).to eq 'a passing step' + expect(test_step.text).to eq 'a passing step' end compile [doc], receiver, [filter] end @@ -35,7 +35,7 @@ it 'notifies with a StepActivated event' do expect(configuration).to receive(:notify) do |message, test_step, step_match| expect(message).to eq :step_activated - expect(test_step.name).to eq 'a passing step' + expect(test_step.text).to eq 'a passing step' expect(step_match).to eq step_match end compile [doc], receiver, [filter] @@ -60,7 +60,7 @@ it 'activates each step' do expect(step_match).to receive(:activate) do |test_step| - expect(test_step.name).to eq 'a passing step' + expect(test_step.text).to eq 'a passing step' end compile [doc], receiver, [filter] end @@ -115,7 +115,7 @@ it 'notifies with a StepActivated event' do expect(configuration).to receive(:notify) do |message, test_step, step_match| expect(message).to eq :step_activated - expect(test_step.name).to eq 'a passing step' + expect(test_step.text).to eq 'a passing step' expect(step_match).to eq step_match end compile [doc], receiver, [filter] diff --git a/spec/cucumber/formatter/json_spec.rb b/spec/cucumber/formatter/json_spec.rb index 64a6b5fa51..ddc5bc4228 100644 --- a/spec/cucumber/formatter/json_spec.rb +++ b/spec/cucumber/formatter/json_spec.rb @@ -43,7 +43,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec.feature:4"}, "result": {"status": "undefined"}}]}]}]}) @@ -79,7 +79,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec/cucumber/formatter/json_spec.rb:62"}, "result": {"status": "passed", @@ -116,7 +116,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec/cucumber/formatter/json_spec.rb:99"}, "result": {"status": "failed", @@ -154,7 +154,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec/cucumber/formatter/json_spec.rb:137"}, "result": {"status": "pending", @@ -196,7 +196,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 8, "match": {"location": "spec/cucumber/formatter/json_spec.rb:179"}, "result": {"status": "passed", @@ -250,7 +250,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 6, "match": {"location": "spec/cucumber/formatter/json_spec.rb:227"}, "result": {"status": "passed", @@ -269,7 +269,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 15, "match": {"location": "spec/cucumber/formatter/json_spec.rb:227"}, "result": {"status": "passed", @@ -343,7 +343,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Then ", - "name": "the monkey eats bananas", + "text": "the monkey eats bananas", "line": 11, "comments": [{"value": "#step comment1", "line": 10}], @@ -359,7 +359,7 @@ module Formatter "type": "background", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 6, "match": {"location": "spec/cucumber/formatter/json_spec.rb:307"}, "result": {"status": "passed", @@ -378,7 +378,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Then ", - "name": "the monkey eats bananas", + "text": "the monkey eats bananas", "line": 22, "comments": [{"value": "#step comment2", "line": 15}], @@ -420,7 +420,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "doc_string": {"value": "the doc string", "content_type": "", @@ -460,7 +460,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "output": ["from step"], "match": {"location": "spec/cucumber/formatter/json_spec.rb:443"}, @@ -499,7 +499,7 @@ module Formatter "type": "background", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec.feature:4"}, "result": {"status": "undefined"}}]}, @@ -511,7 +511,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Then ", - "name": "the monkey eats bananas", + "text": "the monkey eats bananas", "line": 7, "match": {"location": "spec.feature:7"}, "result": {"status": "undefined"}}]}, @@ -522,7 +522,7 @@ module Formatter "type": "background", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec.feature:4"}, "result": {"status": "undefined"}}]}, @@ -534,7 +534,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Then ", - "name": "the monkey eats more bananas", + "text": "the monkey eats more bananas", "line": 10, "match": {"location": "spec.feature:10"}, "result": {"status": "undefined"}}]}]}]}) @@ -571,7 +571,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "embeddings": [{"mime_type": "mime-type", "data": "YWJj"}], @@ -616,7 +616,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "embeddings": [{"mime_type": "image/png", "data": "Zm9v"}], @@ -669,7 +669,7 @@ module Formatter "duration": 1}}], "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec/cucumber/formatter/json_spec.rb:645"}, "result": {"status": "passed", @@ -721,7 +721,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "match": {"location": "spec/cucumber/formatter/json_spec.rb:704"}, "result": {"status": "passed", @@ -765,7 +765,7 @@ module Formatter "type": "scenario", "steps": [{"keyword": "Given ", - "name": "there are bananas", + "text": "there are bananas", "line": 4, "rows": [{"cells": ["aa", "bb"]}, diff --git a/spec/cucumber/formatter/junit_spec.rb b/spec/cucumber/formatter/junit_spec.rb index 2309607504..88773e4cc6 100644 --- a/spec/cucumber/formatter/junit_spec.rb +++ b/spec/cucumber/formatter/junit_spec.rb @@ -43,7 +43,7 @@ def write_file(feature_filename, data) " class Junit def before_step(step) - return unless step.name.match('a passing ctrl scenario') + return unless step.text.match('a passing ctrl scenario') Interceptor::Pipe.unwrap! :stdout @fake_io = $stdout = StringIO.new $stdout.sync = true @@ -51,7 +51,7 @@ def before_step(step) end def after_step(step) - return unless step.name.match('a passing ctrl scenario') + return unless step.text.match('a passing ctrl scenario') @interceptedout.write("boo\b\cx\e\a\f boo ") $stdout = STDOUT @fake_io.close diff --git a/spec/support/standard_step_actions.rb b/spec/support/standard_step_actions.rb index 378ea7b730..3627441061 100644 --- a/spec/support/standard_step_actions.rb +++ b/spec/support/standard_step_actions.rb @@ -3,7 +3,7 @@ class StandardStepActions < Cucumber::Core::Filter.new def test_case(test_case) test_steps = test_case.test_steps.map do |step| - case step.name + case step.text when /fail/ step.with_action { raise Failure } when /pass/