Class: Cucumber::Core::Test::DocString

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/cucumber/core/test/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

Instance Method Summary collapse

Constructor Details

#initialize(content, content_type) ⇒ DocString

Returns a new instance of DocString.



26
27
28
29
30
# File 'lib/cucumber/core/test/doc_string.rb', line 26

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



24
25
26
# File 'lib/cucumber/core/test/doc_string.rb', line 24

def content
  @content
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



24
25
26
# File 'lib/cucumber/core/test/doc_string.rb', line 24

def content_type
  @content_type
end

Instance Method Details

#==(other) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/cucumber/core/test/doc_string.rb', line 59

def ==(other)
  if other.respond_to?(:content_type)
    return false unless content_type == other.content_type
  end
  return content == other.to_str if other.respond_to?(:to_str)

  false
end

#data_table?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cucumber/core/test/doc_string.rb', line 36

def data_table?
  false
end

#describe_to(visitor, *args) ⇒ Object



32
33
34
# File 'lib/cucumber/core/test/doc_string.rb', line 32

def describe_to(visitor, *args)
  visitor.doc_string(self, *args)
end

#doc_string?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cucumber/core/test/doc_string.rb', line 40

def doc_string?
  true
end

#inspectObject



68
69
70
71
72
73
74
75
# File 'lib/cucumber/core/test/doc_string.rb', line 68

def inspect
  [
    %(#<#{self.class}),
    %(  """#{content_type}),
    %(  #{@content}),
    %(  """>)
  ].join("\n")
end

#lines_countObject



55
56
57
# File 'lib/cucumber/core/test/doc_string.rb', line 55

def lines_count
  lines.count + 2
end

#mapObject

Raises:

  • (ArgumentError)


44
45
46
47
48
49
# File 'lib/cucumber/core/test/doc_string.rb', line 44

def map
  raise ArgumentError, 'No block given' unless block_given?

  new_content = yield content
  self.class.new(new_content, content_type)
end

#to_step_definition_argObject



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

def to_step_definition_arg
  self
end