Class: Cucumber::Messages::Suggestion

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

Overview

Represents the Suggestion message in Cucumber’s message protocol.

A suggested fragment of code to implement an undefined step

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: '', pickle_step_id: '', snippets: []) ⇒ Suggestion

Returns a new instance of Suggestion.



28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/messages/suggestion.rb', line 28

def initialize(
  id: '',
  pickle_step_id: '',
  snippets: []
)
  @id = id
  @pickle_step_id = pickle_step_id
  @snippets = snippets
  super()
end

Instance Attribute Details

#idObject (readonly)

A unique id for this suggestion



16
17
18
# File 'lib/cucumber/messages/suggestion.rb', line 16

def id
  @id
end

#pickle_step_idObject (readonly)

The ID of the ‘PickleStep` this `Suggestion` was created for.



21
22
23
# File 'lib/cucumber/messages/suggestion.rb', line 21

def pickle_step_id
  @pickle_step_id
end

#snippetsObject (readonly)

A collection of code snippets that could implement the undefined step



26
27
28
# File 'lib/cucumber/messages/suggestion.rb', line 26

def snippets
  @snippets
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


46
47
48
49
50
51
52
53
54
# File 'lib/cucumber/messages/suggestion.rb', line 46

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

  new(
    id: hash[:id],
    pickle_step_id: hash[:pickleStepId],
    snippets: hash[:snippets]&.map { |item| Snippet.from_h(item) }
  )
end