Skip to content

Commit

Permalink
Step: Rename name to text
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Sep 27, 2017
1 parent 062f5b7 commit d6fbf44
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 40 deletions.
5 changes: 2 additions & 3 deletions lib/cucumber/filters/activate_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/formatter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions lib/cucumber/formatter/legacy_api/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/legacy_api/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spec/cucumber/filters/activate_steps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

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

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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down
42 changes: 21 additions & 21 deletions spec/cucumber/formatter/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]}]}]})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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}],
Expand All @@ -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",
Expand All @@ -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}],
Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"}}]},
Expand All @@ -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"}}]},
Expand All @@ -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"}}]},
Expand All @@ -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"}}]}]}]})
Expand Down Expand Up @@ -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"}],
Expand Down Expand Up @@ -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"}],
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"]},
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/formatter/junit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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
@interceptedout = Interceptor::Pipe.wrap(:stdout)
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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/standard_step_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit d6fbf44

Please sign in to comment.