From 984fd70a36c85b6312d439b6a21fb4f2ff0f90c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Tue, 14 Jul 2015 12:34:19 +0200 Subject: [PATCH 1/2] Pass DocString as String --- .../nested_steps_with_second_arg.feature | 25 +++---------------- features/docs/gherkin/doc_strings.feature | 10 ++++---- lib/cucumber/multiline_argument/doc_string.rb | 3 +-- lib/cucumber/rb_support/rb_world.rb | 15 +---------- 4 files changed, 10 insertions(+), 43 deletions(-) diff --git a/features/docs/defining_steps/nested_steps_with_second_arg.feature b/features/docs/defining_steps/nested_steps_with_second_arg.feature index 8b7b7eb38b..8b1ed219c9 100644 --- a/features/docs/defining_steps/nested_steps_with_second_arg.feature +++ b/features/docs/defining_steps/nested_steps_with_second_arg.feature @@ -34,7 +34,7 @@ Feature: Nested Steps with either table or doc string """ - Scenario: Use #step with docstring + Scenario: Use #step with Doc String Given a step definition that looks like this: """ruby Given /two turtles/ do @@ -44,30 +44,11 @@ Feature: Nested Steps with either table or doc string And a step definition that looks like this: """ruby Given /turtles:/ do |text| - puts text + puts "#{text}:#{text.class}" end """ When I run the feature with the progress formatter Then the output should contain: """ - Sturm and Lioville - """ - - Scenario: Use #step with docstring and content-type - Given a step definition that looks like this: - """ruby - Given /two turtles/ do - step %{turtles:}, doc_string('Sturm and Lioville','math') - end - """ - And a step definition that looks like this: - """ruby - Given /turtles:/ do |text| - puts text.content_type - end - """ - When I run the feature with the progress formatter - Then the output should contain: - """ - math + Sturm and Lioville:String """ diff --git a/features/docs/gherkin/doc_strings.feature b/features/docs/gherkin/doc_strings.feature index e468e5db20..f2eb180ae8 100644 --- a/features/docs/gherkin/doc_strings.feature +++ b/features/docs/gherkin/doc_strings.feature @@ -53,22 +53,22 @@ Feature: Doc strings Three """ - Scenario: DocString with interesting content type + Scenario: DocString passed as String Given a scenario with a step that looks like this: """gherkin Given I have some code for you: - \"\"\"ruby - # hello + \"\"\" + hello \"\"\" """ And a step definition that looks like this: """ruby Given /code/ do |text| - puts text.content_type + puts text.class end """ When I run the feature with the progress formatter Then the output should contain: """ - ruby + String """ diff --git a/lib/cucumber/multiline_argument/doc_string.rb b/lib/cucumber/multiline_argument/doc_string.rb index b6a3f7292d..e9c24af905 100644 --- a/lib/cucumber/multiline_argument/doc_string.rb +++ b/lib/cucumber/multiline_argument/doc_string.rb @@ -2,9 +2,8 @@ module Cucumber module MultilineArgument class DocString < SimpleDelegator def append_to(array) - array << self + array << self.to_s end end end end - diff --git a/lib/cucumber/rb_support/rb_world.rb b/lib/cucumber/rb_support/rb_world.rb index adb27e754f..a28f826b97 100644 --- a/lib/cucumber/rb_support/rb_world.rb +++ b/lib/cucumber/rb_support/rb_world.rb @@ -65,19 +65,6 @@ def table(text_or_table, file=nil, line_offset=0) @__cucumber_runtime.table(text_or_table, file, line_offset) end - # Create an {Cucumber::Ast::DocString} object - # - # Useful in conjunction with the #step method, when - # want to specify a content type. - # @example Create a multiline string - # code = multiline_string(%{ - # puts "this is ruby code" - # %}, 'ruby') - def doc_string(string_without_triple_quotes, content_type='', line_offset=0) - # TODO: rename this method to multiline_string - @__cucumber_runtime.doc_string(string_without_triple_quotes, content_type, line_offset) - end - # @deprecated Use {#puts} instead. def announce(*messages) STDERR.puts AnsiEscapes.failed + "WARNING: #announce is deprecated. Use #puts instead:" + caller[0] + AnsiEscapes.reset @@ -89,7 +76,7 @@ def announce(*messages) # @note Cucumber might surprise you with the behaviour of this method. Instead # of sending the output directly to STDOUT, Cucumber will intercept and cache # the message until the current step has finished, and then display it. - # + # # If you'd prefer to see the message immediately, call {Kernel.puts} instead. def puts(*messages) @__cucumber_runtime.puts(*messages) From 4e5bd49c913934a049769ab189ee91c0246c7fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Tue, 28 Jul 2015 23:05:52 -0500 Subject: [PATCH 2/2] Added back the method (and deprecated it) --- lib/cucumber/rb_support/rb_world.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/cucumber/rb_support/rb_world.rb b/lib/cucumber/rb_support/rb_world.rb index a28f826b97..5d0c91f074 100644 --- a/lib/cucumber/rb_support/rb_world.rb +++ b/lib/cucumber/rb_support/rb_world.rb @@ -65,6 +65,20 @@ def table(text_or_table, file=nil, line_offset=0) @__cucumber_runtime.table(text_or_table, file, line_offset) end + # Create an {Cucumber::Ast::DocString} object + # + # Useful in conjunction with the #step method, when + # want to specify a content type. + # @example Create a multiline string + # code = multiline_string(%{ + # puts "this is ruby code" + # %}, 'ruby') + def doc_string(string_without_triple_quotes, content_type='', line_offset=0) + STDERR.puts AnsiEscapes.failed + "WARNING: #doc_string is deprecated. Just pass a regular String instead:" + caller[0] + AnsiEscapes.reset + # TODO: rename this method to multiline_string + @__cucumber_runtime.doc_string(string_without_triple_quotes, content_type, line_offset) + end + # @deprecated Use {#puts} instead. def announce(*messages) STDERR.puts AnsiEscapes.failed + "WARNING: #announce is deprecated. Use #puts instead:" + caller[0] + AnsiEscapes.reset