Class: Cucumber::Messages::TestStep

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

Overview

Represents the TestStep message in Cucumber’s message protocol.

*

A `TestStep` is derived from either a `PickleStep`
combined with a `StepDefinition`, or from a `Hook`.

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(hook_id: nil, id: '', pickle_step_id: nil, step_definition_ids: nil, step_match_arguments_lists: nil) ⇒ TestStep

Returns a new instance of TestStep.



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

def initialize(
  hook_id: nil,
  id: '',
  pickle_step_id: nil,
  step_definition_ids: nil,
  step_match_arguments_lists: nil
)
  @hook_id = hook_id
  @id = id
  @pickle_step_id = pickle_step_id
  @step_definition_ids = step_definition_ids
  @step_match_arguments_lists = step_match_arguments_lists
  super()
end

Instance Attribute Details

#hook_idObject (readonly)

Pointer to the ‘Hook` (if derived from a Hook)



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

def hook_id
  @hook_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#pickle_step_idObject (readonly)

Pointer to the ‘PickleStep` (if derived from a `PickleStep`)



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

def pickle_step_id
  @pickle_step_id
end

#step_definition_idsObject (readonly)

Pointer to all the matching ‘StepDefinition`s (if derived from a `PickleStep`)

Each element represents a matching step definition. A size of 0 means `UNDEFINED`,
and a size of 2+ means `AMBIGUOUS`


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

def step_definition_ids
  @step_definition_ids
end

#step_match_arguments_listsObject (readonly)

A list of list of StepMatchArgument (if derived from a ‘PickleStep`).



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

def step_match_arguments_lists
  @step_match_arguments_lists
end

Class Method Details

.from_h(hash) ⇒ Object

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

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


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cucumber/messages/test_step.rb', line 61

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

  new(
    hook_id: hash[:hookId],
    id: hash[:id],
    pickle_step_id: hash[:pickleStepId],
    step_definition_ids: hash[:stepDefinitionIds],
    step_match_arguments_lists: hash[:stepMatchArgumentsLists]&.map { |item| StepMatchArgumentsList.from_h(item) }
  )
end