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`.

When derived from a PickleStep:

* For `UNDEFINED` steps `stepDefinitionIds` and `stepMatchArgumentsLists` will be empty.
* For `AMBIGUOUS` steps, there will be multiple entries in `stepDefinitionIds` and `stepMatchArgumentsLists`. The first entry in the stepMatchArgumentsLists holds the list of arguments for the first matching step definition, the second entry for the second, etc

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.



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

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)



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

def hook_id
  @hook_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#pickle_step_idObject (readonly)

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



27
28
29
# File 'lib/cucumber/messages/test_step.rb', line 27

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.



34
35
36
# File 'lib/cucumber/messages/test_step.rb', line 34

def step_definition_ids
  @step_definition_ids
end

#step_match_arguments_listsObject (readonly)

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

Each element represents the arguments for a matching step definition.



41
42
43
# File 'lib/cucumber/messages/test_step.rb', line 41

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... ...>


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

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