Class: Cucumber::Messages::Step

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

Overview

Represents the Step message in Cucumber’s message protocol.

A 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(location: Location.new, keyword: '', keyword_type: nil, text: '', doc_string: nil, data_table: nil, id: '') ⇒ Step

Returns a new instance of Step.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cucumber/messages/step.rb', line 39

def initialize(
  location: Location.new,
  keyword: '',
  keyword_type: nil,
  text: '',
  doc_string: nil,
  data_table: nil,
  id: ''
)
  @location = location
  @keyword = keyword
  @keyword_type = keyword_type
  @text = text
  @doc_string = doc_string
  @data_table = data_table
  @id = id
  super()
end

Instance Attribute Details

#data_tableObject (readonly)

Returns the value of attribute data_table.



32
33
34
# File 'lib/cucumber/messages/step.rb', line 32

def data_table
  @data_table
end

#doc_stringObject (readonly)

Returns the value of attribute doc_string.



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

def doc_string
  @doc_string
end

#idObject (readonly)

Unique ID to be able to reference the Step from PickleStep



37
38
39
# File 'lib/cucumber/messages/step.rb', line 37

def id
  @id
end

#keywordObject (readonly)

The actual keyword as it appeared in the source.



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

def keyword
  @keyword
end

#keyword_typeObject (readonly)

The test phase signalled by the keyword: Context definition (Given), Action performance (When), Outcome assertion (Then). Other keywords signal Continuation (And and But) from a prior keyword. Please note that all translations which a dialect maps to multiple keywords (‘*` is in this category for all dialects), map to ’Unknown’.



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

def keyword_type
  @keyword_type
end

#locationObject (readonly)

The location of the steps’ ‘keyword`



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

def location
  @location
end

#textObject (readonly)

Returns the value of attribute text.



28
29
30
# File 'lib/cucumber/messages/step.rb', line 28

def text
  @text
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cucumber/messages/step.rb', line 65

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

  new(
    location: Location.from_h(hash[:location]),
    keyword: hash[:keyword],
    keyword_type: hash[:keywordType],
    text: hash[:text],
    doc_string: DocString.from_h(hash[:docString]),
    data_table: DataTable.from_h(hash[:dataTable]),
    id: hash[:id]
  )
end