Class: Cucumber::Messages::Pickle

Inherits:
Message
  • Object
show all
Defined in:
lib/cucumber/messages/pickle.rb

Overview

Represents the Pickle message in Cucumber’s message protocol.

A ‘Pickle` represents a template for a `TestCase`. It is typically derived from another format, such as [GherkinDocument](#io.cucumber.messages.GherkinDocument). In the future a `Pickle` may be derived from other formats such as Markdown or Excel files.

By making ‘Pickle` the main data structure Cucumber uses for execution, the implementation of Cucumber itself becomes simpler, as it doesn’t have to deal with the complex structure of a [GherkinDocument](#io.cucumber.messages.GherkinDocument).

Each ‘PickleStep` of a `Pickle` is matched with a `StepDefinition` to create a `TestCase`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

camelize, from_json, #to_h, #to_json

Constructor Details

#initialize(id: '', uri: '', name: '', language: '', steps: [], tags: [], ast_node_ids: []) ⇒ Pickle

Returns a new instance of Pickle.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cucumber/messages/pickle.rb', line 60

def initialize(
  id: '',
  uri: '',
  name: '',
  language: '',
  steps: [],
  tags: [],
  ast_node_ids: []
)
  @id = id
  @uri = uri
  @name = name
  @language = language
  @steps = steps
  @tags = tags
  @ast_node_ids = ast_node_ids
  super()
end

Instance Attribute Details

#ast_node_idsObject (readonly)

Points to the AST node locations of the pickle. The last one represents the unique id of the pickle. A pickle constructed from ‘Examples` will have the first id originating from the `Scenario` AST node, and the second from the `TableRow` AST node.



58
59
60
# File 'lib/cucumber/messages/pickle.rb', line 58

def ast_node_ids
  @ast_node_ids
end

#idObject (readonly)

A unique id for the pickle



25
26
27
# File 'lib/cucumber/messages/pickle.rb', line 25

def id
  @id
end

#languageObject (readonly)

The language of the pickle



40
41
42
# File 'lib/cucumber/messages/pickle.rb', line 40

def language
  @language
end

#nameObject (readonly)

The name of the pickle



35
36
37
# File 'lib/cucumber/messages/pickle.rb', line 35

def name
  @name
end

#stepsObject (readonly)

One or more steps



45
46
47
# File 'lib/cucumber/messages/pickle.rb', line 45

def steps
  @steps
end

#tagsObject (readonly)

One or more tags. If this pickle is constructed from a Gherkin document, It includes inherited tags from the ‘Feature` as well.



51
52
53
# File 'lib/cucumber/messages/pickle.rb', line 51

def tags
  @tags
end

#uriObject (readonly)

The uri of the source file



30
31
32
# File 'lib/cucumber/messages/pickle.rb', line 30

def uri
  @uri
end

Class Method Details

.from_h(hash) ⇒ Object

Returns a new Pickle from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.

Cucumber::Messages::Pickle.from_h(some_hash) # => #<Cucumber::Messages::Pickle:0x... ...>


86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cucumber/messages/pickle.rb', line 86

def self.from_h(hash)
  return nil if hash.nil?

  new(
    id: hash[:id],
    uri: hash[:uri],
    name: hash[:name],
    language: hash[:language],
    steps: hash[:steps]&.map { |item| PickleStep.from_h(item) },
    tags: hash[:tags]&.map { |item| PickleTag.from_h(item) },
    ast_node_ids: hash[:astNodeIds]
  )
end