Class: Cucumber::Ast::DocString

Inherits:
String show all
Defined in:
lib/cucumber/ast/doc_string.rb

Overview

Represents an inline argument in a step. Example:

Given the message
  """
  I like
  Cucumber sandwich
  """

The text between the pair of """ 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: "I like\nCucumber sandwich"

Note how the indentation from the source is stripped away.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#end_with?, #indent

Constructor Details

#initialize(string, content_type) ⇒ DocString

Returns a new instance of DocString.



28
29
30
31
# File 'lib/cucumber/ast/doc_string.rb', line 28

def initialize(string, content_type)
  @content_type = content_type
  super string
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



26
27
28
# File 'lib/cucumber/ast/doc_string.rb', line 26

def content_type
  @content_type
end

#fileObject

:nodoc:



20
21
22
# File 'lib/cucumber/ast/doc_string.rb', line 20

def file
  @file
end

Class Method Details

.default_arg_nameObject



22
23
24
# File 'lib/cucumber/ast/doc_string.rb', line 22

def self.default_arg_name
  "string"
end

Instance Method Details

#accept(visitor) ⇒ Object



37
38
39
40
# File 'lib/cucumber/ast/doc_string.rb', line 37

def accept(visitor)
  return if Cucumber.wants_to_quit
  visitor.visit_doc_string(self)
end

#arguments_replaced(arguments) ⇒ Object

:nodoc:



42
43
44
45
46
47
48
49
# File 'lib/cucumber/ast/doc_string.rb', line 42

def arguments_replaced(arguments) #:nodoc:
  string = self
  arguments.each do |name, value|
    value ||= ''
    string = string.gsub(name, value)
  end
  DocString.new(string, content_type)
end

#has_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cucumber/ast/doc_string.rb', line 51

def has_text?(text)
  index(text)
end

#to_sexpObject

For testing only



56
57
58
# File 'lib/cucumber/ast/doc_string.rb', line 56

def to_sexp #:nodoc:
  [:doc_string, to_step_definition_arg]
end

#to_step_definition_argObject



33
34
35
# File 'lib/cucumber/ast/doc_string.rb', line 33

def to_step_definition_arg
  self
end