Skip to content

Commit

Permalink
Step: Rename name to text (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle authored and mattwynne committed Sep 27, 2017
1 parent ad42cd0 commit da8cf3c
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion features/docs/api/listen_for_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion features/docs/events/test_step_finished_event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
15 changes: 8 additions & 7 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 Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
}
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/formatter/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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
output + "\nMessage:\n"
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)
Expand Down
14 changes: 7 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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 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 Expand Up @@ -155,6 +155,10 @@ def step_invocation
self
end

def to_s
text
end

private

def source_indent
Expand Down Expand Up @@ -240,6 +244,10 @@ def name
'| ' + cells.join(' | ') + ' |'
end

def to_s
name
end

def failed?
status == :failed
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(location)
@location = location
end

def name
def text
'After hook'
end

Expand All @@ -63,7 +63,7 @@ def initialize(location)
@location = location
end

def name
def text
'Before hook'
end

Expand All @@ -83,7 +83,7 @@ def initialize(location)
@location = location
end

def name
def text
'AfterStep hook'
end

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
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
4 changes: 2 additions & 2 deletions spec/cucumber/hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 da8cf3c

Please sign in to comment.