Skip to content

Step#name renamed to #text #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ActivateSteps < Cucumber::Core::Filter.new
private

def activate(step)
case step.name
case step.text
when /fail/
step.with_action { raise Failure }
when /pass/
Expand Down Expand Up @@ -105,7 +105,7 @@ end
MyRunner.new.execute([feature], [ActivateSteps.new]) do |events|
events.on(:test_step_finished) do |event|
test_step, result = event.test_step, event.result
puts "#{test_step.name} #{result}"
puts "#{test_step.text} #{result}"
end
end
```
Expand Down
11 changes: 5 additions & 6 deletions lib/cucumber/core/ast/outline_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class OutlineStep
include HasLocation
include DescribesItself

attr_reader :language, :location, :comments, :keyword, :name, :multiline_arg
attr_reader :language, :location, :comments, :keyword, :text, :multiline_arg

def initialize(language, location, comments, keyword, text, multiline_arg)
@language, @location, @comments, @keyword, @name, @multiline_arg = language, location, comments, keyword, text, multiline_arg
@language, @location, @comments, @keyword, @text, @multiline_arg = language, location, comments, keyword, text, multiline_arg
end

def to_step(row)
Ast::ExpandedOutlineStep.new(self, language, row.location, comments, keyword, row.expand(name), replace_multiline_arg(row))
Ast::ExpandedOutlineStep.new(self, language, row.location, comments, keyword, row.expand(text), replace_multiline_arg(row))
end

def inspect
keyword_and_name = [keyword, name].join(": ")
%{#<#{self.class} "#{keyword_and_name}" (#{location})>}
keyword_and_text = [keyword, text].join(": ")
%{#<#{self.class} "#{keyword_and_text}" (#{location})>}
end

private
Expand All @@ -47,4 +47,3 @@ def replace_multiline_arg(example_row)
end
end
end

20 changes: 10 additions & 10 deletions lib/cucumber/core/ast/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class Step
include HasLocation
include DescribesItself

attr_reader :keyword, :name, :language, :comments, :exception, :multiline_arg
attr_reader :keyword, :text, :language, :comments, :exception, :multiline_arg

def initialize(language, location, comments, keyword, name, multiline_arg)
@language, @location, @comments, @keyword, @name, @multiline_arg = language, location, comments, keyword, name, multiline_arg
def initialize(language, location, comments, keyword, text, multiline_arg)
@language, @location, @comments, @keyword, @text, @multiline_arg = language, location, comments, keyword, text, multiline_arg
end

def to_sexp
[:step, line, keyword, name, @multiline_arg.to_sexp]
[:step, line, keyword, text, @multiline_arg.to_sexp]
end

def backtrace_line
"#{location}:in `#{keyword}#{name}'"
"#{location}:in `#{keyword}#{text}'"
end

def actual_keyword(previous_step_keyword = nil)
Expand All @@ -36,8 +36,8 @@ def actual_keyword(previous_step_keyword = nil)
end

def inspect
keyword_and_name = [keyword, name].join(": ")
%{#<#{self.class} "#{keyword_and_name}" (#{location})>}
keyword_and_text = [keyword, text].join(": ")
%{#<#{self.class} "#{keyword_and_text}" (#{location})>}
end

private
Expand All @@ -53,8 +53,8 @@ def description_for_visitors

class ExpandedOutlineStep < Step

def initialize(outline_step, language, location, comments, keyword, name, multiline_arg)
@outline_step, @language, @location, @comments, @keyword, @name, @multiline_arg = outline_step, language, location, comments, keyword, name, multiline_arg
def initialize(outline_step, language, location, comments, keyword, text, multiline_arg)
@outline_step, @language, @location, @comments, @keyword, @text, @multiline_arg = outline_step, language, location, comments, keyword, text, multiline_arg
end

def all_locations
Expand All @@ -65,7 +65,7 @@ def all_locations

def backtrace_line
"#{step_backtrace_line}\n" +
"#{@outline_step.location}:in `#{@outline_step.keyword}#{@outline_step.name}'"
"#{@outline_step.location}:in `#{@outline_step.keyword}#{@outline_step.text}'"
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActivateStepsForSelfTest < 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 /pending/
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/test/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def initialize(step_result)

def execute(test_step, monitor, &continue)
result = test_step.execute(monitor.result, &continue)
result = result.with_message(%(Undefined step: "#{test_step.name}")) if result.undefined?
result = result.with_message(%(Undefined step: "#{test_step.text}")) if result.undefined?
result = result.with_appended_backtrace(test_step.source.last) if IsStepVisitor.new(test_step).step?
result.describe_to(monitor, result)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/core/test/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def with_action(location = nil, &block)
self.class.new(source, Test::Action.new(location, &block))
end

def name
source.last.name
def text
source.last.text
end

def location
Expand Down
16 changes: 8 additions & 8 deletions spec/cucumber/core/ast/outline_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ module Cucumber
module Core
module Ast
describe OutlineStep do
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, name, multiline_arg) }
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, text, multiline_arg) }
let(:language) { double }
let(:location) { double }
let(:comments) { double }
let(:keyword) { double }
let(:name) { 'anything' }
let(:text) { 'anything' }
let(:multiline_arg) { EmptyMultilineArgument.new }

describe 'location' do
Expand All @@ -36,18 +36,18 @@ module Ast

describe "converting to a Step" do
context "a single argument in the name" do
let(:name) { 'a <color> cucumber' }
let(:text) { 'a <color> cucumber' }

it "replaces the argument" do
row = ExamplesTable::Row.new({'color' => 'green'}, 1, location, language, comments)
expect( outline_step.to_step(row).name ).to eq 'a green cucumber'
expect( outline_step.to_step(row).text ).to eq 'a green cucumber'
end

end

context "when the step has a DataTable" do
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, name, table) }
let(:name) { "anything" }
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, text, table) }
let(:text) { "anything" }
let(:table) { DataTable.new([['x', 'y'],['a', 'a <arg>']], Location.new('foo.feature', 23)) }

it "replaces the arguments in the DataTable" do
Expand All @@ -64,9 +64,9 @@ module Ast

context "when the step has a DocString" do
let(:location) { double }
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, name, doc_string) }
let(:outline_step) { OutlineStep.new(language, location, comments, keyword, text, doc_string) }
let(:doc_string) { DocString.new('a <arg> that needs replacing', '', location) }
let(:name) { 'anything' }
let(:text) { 'anything' }

it "replaces the arguments in the DocString" do
visitor = double
Expand Down
8 changes: 4 additions & 4 deletions spec/cucumber/core/ast/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module Core
module Ast
describe Step do
let(:step) do
language, location, comments, keyword, name = *double
language, location, comments, keyword, text = *double
multiline_arg = EmptyMultilineArgument.new
Step.new(language, location, comments, keyword, name, multiline_arg)
Step.new(language, location, comments, keyword, text, multiline_arg)
end

describe "describing itself" do
Expand Down Expand Up @@ -109,10 +109,10 @@ module Ast
describe ExpandedOutlineStep do
let(:outline_step) { double }
let(:step) do
language, location, keyword, name = *double
language, location, keyword, text = *double
multiline_arg = EmptyMultilineArgument.new
comments = []
ExpandedOutlineStep.new(outline_step, language, location, comments, keyword, name, multiline_arg)
ExpandedOutlineStep.new(outline_step, language, location, comments, keyword, text, multiline_arg)
end

describe "describing itself" do
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/core/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ def self.stubs(*names)
expect( visitor ).to receive(:test_step) do |test_step|
visit_source(test_step) do |source_visitor|
expect( source_visitor ).to receive(:step) do |step|
expect(step.name).to eq 'passing 1 with 2'
expect(step.text).to eq 'passing 1 with 2'
end
end
end.once.ordered

expect( visitor ).to receive(:test_step) do |test_step|
visit_source(test_step) do |source_visitor|
expect( source_visitor ).to receive(:step) do |step|
expect(step.name).to eq 'as well as 3'
expect(step.text).to eq 'as well as 3'
end
end
end.once.ordered
Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/core/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Cucumber::Core
my_filter = my_filter_class.new
expect(receiver).to receive(:test_case) { |test_case|
expect(test_case.test_steps.length).to eq 1
expect(test_case.test_steps.first.name).to eq 'a step'
expect(test_case.test_steps.first.text).to eq 'a step'
}.exactly(2).times
compile [doc], receiver, [my_filter]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/core/gherkin/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def feature
allow( visitor ).to receive(:scenario_outline).and_yield(visitor)
allow( visitor ).to receive(:examples_table)
expect( visitor ).to receive(:outline_step) do |step|
expect( step.name ).to eq 'passing <arg>'
expect( step.text ).to eq 'passing <arg>'
end
feature.describe_to(visitor)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/core/test/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ module Cucumber::Core::Test
expect(event_bus).to receive(:test_case_finished) do |test_case, result|
expect( result ).to be_undefined
end
allow( undefined.source.last ).to receive(:name)
allow( undefined.source.last ).to receive(:text)
test_case.describe_to runner
end

it 'sets the message on the result' do
expect(event_bus).to receive(:test_case_finished) do |test_case, result|
expect( result.message ).to eq("Undefined step: \"step name\"")
end
expect( undefined.source.last ).to receive(:name).and_return("step name")
expect( undefined.source.last ).to receive(:text).and_return("step name")
test_case.describe_to runner
end

Expand All @@ -116,7 +116,7 @@ module Cucumber::Core::Test
expect( result.backtrace ).to eq(["step line"])
end
expect( undefined.source.last ).to receive(:backtrace_line).and_return("step line")
allow( undefined.source.last ).to receive(:name)
allow( undefined.source.last ).to receive(:text)
test_case.describe_to runner
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/core/test/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ module Cucumber::Core::Test
end

it "exposes the name and location of the AST step or hook as attributes" do
name, location = double, double
step_or_hook = double(name: name, location: location)
text, location = double, double
step_or_hook = double(text: text, location: location)
test_step = Step.new([step_or_hook])
expect( test_step.name ).to eq name
expect( test_step.text ).to eq text
expect( test_step.location ).to eq location
end

Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ module Cucumber
end
event_bus.on(:test_step_started) do |event|
test_step = event.test_step
observed_events << [:test_step_started, test_step.name]
observed_events << [:test_step_starting, test_step.text]
end
event_bus.on(:test_step_finished) do |event|
test_step, result = *event.attributes
observed_events << [:test_step_finished, test_step.name, result.to_sym]
observed_events << [:test_step_finished, test_step.text, result.to_sym]
end
end

Expand Down