From da8cf3cab7b14899cdd12c6d3c54b848a206c8eb Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 27 Sep 2017 23:35:12 +0200 Subject: [PATCH] Step: Rename name to text (#1130) --- features/docs/api/listen_for_events.feature | 2 +- .../docs/events/test_step_finished_event.feature | 2 +- lib/cucumber/filters/activate_steps.rb | 5 ++--- lib/cucumber/formatter/console.rb | 2 +- lib/cucumber/formatter/json.rb | 15 ++++++++------- lib/cucumber/formatter/junit.rb | 4 ++-- lib/cucumber/formatter/legacy_api/adapter.rb | 14 +++++++------- lib/cucumber/formatter/legacy_api/ast.rb | 10 +++++++++- lib/cucumber/hooks.rb | 6 +++--- spec/cucumber/filters/activate_steps_spec.rb | 8 ++++---- spec/cucumber/formatter/junit_spec.rb | 4 ++-- spec/cucumber/hooks_spec.rb | 4 ++-- spec/support/standard_step_actions.rb | 2 +- 13 files changed, 43 insertions(+), 35 deletions(-) diff --git a/features/docs/api/listen_for_events.feature b/features/docs/api/listen_for_events.feature index dbbae31406..1577ce890b 100644 --- a/features/docs/api/listen_for_events.feature +++ b/features/docs/api/listen_for_events.feature @@ -21,7 +21,7 @@ Feature: Listen for events io = config.out_stream config.on_event :step_activated do |event| io.puts "Success!" - io.puts "Step name: #{event.test_step.name}" + io.puts "Step text: #{event.test_step}" io.puts "Source location: #{event.step_match.location}" end end diff --git a/features/docs/events/test_step_finished_event.feature b/features/docs/events/test_step_finished_event.feature index 77e4ad374d..ac0b25ba20 100644 --- a/features/docs/events/test_step_finished_event.feature +++ b/features/docs/events/test_step_finished_event.feature @@ -24,7 +24,7 @@ Feature: Test Step Finished Event """ AfterConfiguration do |config| config.on_event :test_step_finished do |event| - config.out_stream.puts "Test step: #{event.test_step.name}" + config.out_stream.puts "Test step: #{event.test_step}" config.out_stream.puts "The result is: #{event.result}" end end 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..76fbdcb4f9 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) @@ -101,7 +102,7 @@ def same_feature_as_previous_test_case?(feature) end def first_step_after_background?(test_step) - test_step.source[1].name != @element_hash[:name] + test_step.source[1].to_s != @element_hash[:name] end def internal_hook?(test_step) @@ -160,7 +161,7 @@ def test_step_embeddings def create_step_hash(step_source) step_hash = { keyword: step_source.keyword, - name: step_source.name, + name: step_source.to_s, line: step_source.location.line } step_hash[:comments] = Formatter.create_comments_array(step_source.comments) unless step_source.comments.empty? @@ -239,7 +240,7 @@ def feature(feature) uri: feature.file, id: create_id(feature), keyword: feature.keyword, - name: feature.name, + name: feature.to_s, description: feature.description, line: feature.location.line } @@ -258,7 +259,7 @@ def feature(feature) def background(background) @background_hash = { keyword: background.keyword, - name: background.name, + name: background.to_s, description: background.description, line: background.location.line, type: 'background' @@ -270,7 +271,7 @@ def scenario(scenario) @test_case_hash = { id: create_id(scenario), keyword: scenario.keyword, - name: scenario.name, + name: scenario.to_s, description: scenario.description, line: scenario.location.line, type: 'scenario' @@ -283,7 +284,7 @@ def scenario_outline(scenario) @test_case_hash = { id: create_id(scenario) + ';' + @example_id, keyword: scenario.keyword, - name: scenario.name, + name: scenario.to_s, description: scenario.description, line: @row.location.line, type: 'scenario' @@ -316,7 +317,7 @@ def examples_table_row(row) private def create_id(element) - element.name.downcase.tr(' ', '-') + element.to_s.downcase.tr(' ', '-') end def create_tags_array(tags) diff --git a/lib/cucumber/formatter/junit.rb b/lib/cucumber/formatter/junit.rb index 812510c335..9ce6cad9a7 100644 --- a/lib/cucumber/formatter/junit.rb +++ b/lib/cucumber/formatter/junit.rb @@ -105,7 +105,7 @@ def create_output_string(test_case, scenario, result, row_name) return output if result.ok?(@config.strict) if test_case.keyword == 'Scenario' output += @failing_step_source.keyword.to_s unless hook?(@failing_step_source) - output += "#{@failing_step_source.name}\n" + output += "#{@failing_step_source}\n" else output += "Example row: #{row_name}\n" end @@ -113,7 +113,7 @@ def create_output_string(test_case, scenario, result, row_name) end def hook?(step) - ['Before hook', 'After hook', 'AfterStep hook'].include? step.name + ['Before hook', 'After hook', 'AfterStep hook'].include? step.text end def build_testcase(result, scenario_designation, output) diff --git a/lib/cucumber/formatter/legacy_api/adapter.rb b/lib/cucumber/formatter/legacy_api/adapter.rb index 4ef38b901b..5c3460b23c 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 @@ -930,11 +930,11 @@ 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 + [1, max - node.to_s.length - node.keyword.length].max end def record_width_of(node) - @widths << node.keyword.length + node.name.length + 1 + @widths << node.keyword.length + node.to_s.length + 1 end private @@ -1006,7 +1006,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..bd11effe7e 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) @@ -155,6 +155,10 @@ def step_invocation self end + def to_s + text + end + private def source_indent @@ -240,6 +244,10 @@ def name '| ' + cells.join(' | ') + ' |' end + def to_s + name + end + def failed? status == :failed end diff --git a/lib/cucumber/hooks.rb b/lib/cucumber/hooks.rb index 949508e50b..f457866f42 100644 --- a/lib/cucumber/hooks.rb +++ b/lib/cucumber/hooks.rb @@ -43,7 +43,7 @@ def initialize(location) @location = location end - def name + def text 'After hook' end @@ -63,7 +63,7 @@ def initialize(location) @location = location end - def name + def text 'Before hook' end @@ -83,7 +83,7 @@ def initialize(location) @location = location end - def name + def text 'AfterStep hook' end 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/junit_spec.rb b/spec/cucumber/formatter/junit_spec.rb index 7535a25a04..6d37330736 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/cucumber/hooks_spec.rb b/spec/cucumber/hooks_spec.rb index 15fc0ad535..4d59adb21e 100644 --- a/spec/cucumber/hooks_spec.rb +++ b/spec/cucumber/hooks_spec.rb @@ -2,8 +2,8 @@ require 'cucumber/hooks' module Cucumber::Hooks shared_examples_for 'a source node' do - it 'responds to name' do - expect( subject.name ).to be_a(String) + it 'responds to text' do + expect( subject.text ).to be_a(String) end it 'responds to location' do 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/