Skip to content

Commit

Permalink
Use DocString. Closes cucumber#74.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jun 5, 2011
1 parent 5a448df commit 9db8aeb
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for important information about this release. Happy cuking!
}

s.add_dependency 'gherkin', '>= 2.3.9'
s.add_dependency 'gherkin', '~> 2.4.0'
s.add_dependency 'term-ansicolor', '>= 1.0.5'
s.add_dependency 'builder', '>= 2.1.2'
s.add_dependency 'diff-lcs', '>= 1.1.2'
Expand Down
2 changes: 1 addition & 1 deletion examples/v8/features/fibonacci.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Fibonacci
| 9 | [1, 1, 2, 3, 5, 8] |
| 100 | [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] |

Scenario: Single series tested via a PyString
Scenario: Single series tested via a DocString
When I ask Javascript to calculate fibonacci up to 2 with formatting
Then it should give me:
"""
Expand Down
2 changes: 1 addition & 1 deletion features/json_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Feature: JSON output formatter
"multiline_arg": {
"value": "a string",
"line": 5,
"type": "py_string"
"type": "doc_string"
},
"match": {
"location": "features/step_definitions/pystring_steps.rb:1"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/tickets/features.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/cucumber/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require 'cucumber/ast/step'
require 'cucumber/ast/table'
require 'cucumber/ast/tags'
require 'cucumber/ast/py_string'
require 'cucumber/ast/doc_string'
require 'cucumber/ast/outline_table'
require 'cucumber/ast/examples'
require 'cucumber/ast/visitor'
Expand Down
12 changes: 6 additions & 6 deletions lib/cucumber/ast/py_string.rb → lib/cucumber/ast/doc_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ module Ast
# Cucumber sandwich
# """
#
# The text between the pair of <tt>"""</tt> is stored inside a PyString,
# The text between the pair of <tt>"""</tt> is stored inside a DocString,
# which is yielded to the StepDefinition block as the last argument.
#
# The StepDefinition can then access the String via the #to_s method. In the
# example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
#
# Note how the indentation from the source is stripped away.
#
class PyString #:nodoc:
class DocString #:nodoc:
class Builder
attr_reader :string

def initialize
@string = ''
end

def py_string(string, line_number)
def doc_string(string, line_number)
@string = string
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def to_step_definition_arg

def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_py_string(@string)
visitor.visit_doc_string(@string)
end

def arguments_replaced(arguments) #:nodoc:
Expand All @@ -64,7 +64,7 @@ def arguments_replaced(arguments) #:nodoc:
value ||= ''
string = string.gsub(name, value)
end
PyString.new(string)
DocString.new(string)
end

def has_text?(text)
Expand All @@ -73,7 +73,7 @@ def has_text?(text)

# For testing only
def to_sexp #:nodoc:
[:py_string, to_step_definition_arg]
[:doc_string, to_step_definition_arg]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/ast/tree_walker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def visit_exception(exception, status) #:nodoc:
broadcast(exception, status)
end

def visit_py_string(string)
def visit_doc_string(string)
broadcast(string)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def after_multiline_arg(multiline_arg)
end
end

def py_string(string)
def doc_string(string)
return if @hide_this_step
@builder.pre(:class => 'val') do |pre|
@builder << string.gsub("\n", '&#x000A;')
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def before_outline_table(table)
end
end

def before_py_string(string)
def before_doc_string(string)
return if @hide_this_step
s = %{"""\n#{string}\n"""}.indent(10)
s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/pretty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def step_name(keyword, step_match, status, source_indent, background)
print_announcements
end

def py_string(string)
def doc_string(string)
return if @hide_this_step
s = %{"""\n#{string}\n"""}.indent(@indent)
s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n")
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/parser/gherkin_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def step(step)
@table_owner.gherkin_statement(step)
multiline_arg = rubify(step.multiline_arg)
case(multiline_arg)
when Gherkin::Formatter::Model::PyString
@table_owner.multiline_arg = Ast::PyString.new(multiline_arg.value)
when Gherkin::Formatter::Model::DocString
@table_owner.multiline_arg = Ast::DocString.new(multiline_arg.value)
when Array
@table_owner.multiline_arg = Ast::Table.new(matrix(multiline_arg))
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/rb_support/rb_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def table(text_or_table, file=nil, line_offset=0)
@__cucumber_step_mother.table(text_or_table, file, line_offset)
end

# See StepMother#py_string
def py_string(string_with_triple_quotes, file=nil, line_offset=0)
@__cucumber_step_mother.py_string(string_with_triple_quotes, file, line_offset)
# See StepMother#doc_string
def doc_string(string_with_triple_quotes, file=nil, line_offset=0)
@__cucumber_step_mother.doc_string(string_with_triple_quotes, file, line_offset)
end

# See StepMother#announce
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/runtime/for_programming_languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def table(text_or_table, file=nil, line_offset=0)
#
# Is retured as: " hello\nworld"
#
def py_string(string_with_triple_quotes, file=nil, line_offset=0)
Ast::PyString.parse(string_with_triple_quotes)
def doc_string(string_with_triple_quotes, file=nil, line_offset=0)
Ast::DocString.parse(string_with_triple_quotes)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/runtime/support_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def uri(uri)

def step(step)
cucumber_multiline_arg = case(rubify(step.multiline_arg))
when Gherkin::Formatter::Model::PyString
when Gherkin::Formatter::Model::DocString
step.multiline_arg.value
when Array
Ast::Table.new(step.multiline_arg.map{|row| row.cells})
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/step_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def name
end

def invoke(multiline_arg)
multiline_arg = Ast::PyString.new(multiline_arg) if String === multiline_arg
multiline_arg = Ast::DocString.new(multiline_arg) if String === multiline_arg
all_args = args
all_args << multiline_arg.to_step_definition_arg if multiline_arg
@step_definition.invoke(all_args)
Expand Down
40 changes: 40 additions & 0 deletions spec/cucumber/ast/doc_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'cucumber/ast/doc_string'

module Cucumber
module Ast
describe DocString do
describe "replacing arguments" do

before(:each) do
@ps = DocString.new("<book>\n<qty>\n")
end

it "should return a new doc_string with arguments replaced with values" do
doc_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere', '<qty>' => '5'})

doc_string_with_replaced_arg.to_step_definition_arg.should == "Life is elsewhere\n5\n"
end

it "should not change the original doc_string" do
doc_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere'})

@ps.to_s.should_not include("Life is elsewhere")
end

it "should replaced nil with empty string" do
ps = DocString.new("'<book>'")
doc_string_with_replaced_arg = ps.arguments_replaced({'<book>' => nil})

doc_string_with_replaced_arg.to_step_definition_arg.should == "''"
end

it "should recognise when just a subset of a cell is delimited" do
@ps.should have_text('<qty>')
end

end

end
end
end
4 changes: 2 additions & 2 deletions spec/cucumber/ast/feature_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_feature(dsl)
%w{1 22 333},
%w{4444 55555 666666}
])
py_string = Ast::PyString.new(%{\n I like\nCucumber sandwich\n})
doc_string = Ast::DocString.new(%{\n I like\nCucumber sandwich\n})

background = Ast::Background.new(Ast::Comment.new(""), 2, "Background:", "",
[
Expand All @@ -46,7 +46,7 @@ def create_feature(dsl)
"Scenario:", "A Scenario",
[
Step.new(10, "Given", "a passing step with an inline arg:", table),
Step.new(11, "Given", "a happy step with an inline arg:", py_string),
Step.new(11, "Given", "a happy step with an inline arg:", doc_string),
Step.new(12, "Given", "a failing step")
]
)]
Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/ast/feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Ast
[:row, -1,
[:cell, "4444"], [:cell, "55555"], [:cell, "666666"]]]],
[:step_invocation, 11, "Given", "a happy step with an inline arg:",
[:py_string, "\n I like\nCucumber sandwich\n"]],
[:doc_string, "\n I like\nCucumber sandwich\n"]],
[:step_invocation, 12, "Given", "a failing step"]]]
end

Expand Down
40 changes: 0 additions & 40 deletions spec/cucumber/ast/py_string_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/cucumber/ast/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ module Ast
end

it "should replace arguments in py string arg" do
py_string = PyString.new('taste_<taste> color_<color>')
doc_string = DocString.new('taste_<taste> color_<color>')

step = Step.new(1, 'Given', 'a <color> cucumber', py_string)
step = Step.new(1, 'Given', 'a <color> cucumber', doc_string)

invocation_table = Table.new([
%w{color taste},
Expand Down

0 comments on commit 9db8aeb

Please sign in to comment.