Class: Cucumber::Messages::Background

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

Overview

Represents the Background message in Cucumber’s message protocol.

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(location: Location.new, keyword: '', name: '', description: '', steps: [], id: '') ⇒ Background

Returns a new instance of Background.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cucumber/messages/background.rb', line 26

def initialize(
  location: Location.new,
  keyword: '',
  name: '',
  description: '',
  steps: [],
  id: ''
)
  @location = location
  @keyword = keyword
  @name = name
  @description = description
  @steps = steps
  @id = id
  super()
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



20
21
22
# File 'lib/cucumber/messages/background.rb', line 20

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/cucumber/messages/background.rb', line 24

def id
  @id
end

#keywordObject (readonly)

Returns the value of attribute keyword.



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

def keyword
  @keyword
end

#locationObject (readonly)

The location of the ‘Background` keyword



14
15
16
# File 'lib/cucumber/messages/background.rb', line 14

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/cucumber/messages/background.rb', line 18

def name
  @name
end

#stepsObject (readonly)

Returns the value of attribute steps.



22
23
24
# File 'lib/cucumber/messages/background.rb', line 22

def steps
  @steps
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cucumber/messages/background.rb', line 50

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

  new(
    location: Location.from_h(hash[:location]),
    keyword: hash[:keyword],
    name: hash[:name],
    description: hash[:description],
    steps: hash[:steps]&.map { |item| Step.from_h(item) },
    id: hash[:id]
  )
end