Class: Cucumber::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Query

Returns a new instance of Query.



15
16
17
# File 'lib/cucumber/query.rb', line 15

def initialize(repository)
  @repository = repository
end

Instance Method Details

#count_test_cases_startedObject

TODO: find****By methods (16/25) Complete

Missing: findLocationOf (1 variant) - This strictly speaking isn't a findBy but is located within them
Missing: findSuggestionsBy (2 variants)
Missing: findUnambiguousStepDefinitionBy (1 variant)
Missing: findTestStepFinishedAndTestStepBy (1 variant)
Missing: findMostSevereTestStepResultBy (2 variants)
Missing: findAttachmentsBy (2 variants)
Missing: findTestCaseDurationBy (2 variant)
Missing: findLineageBy (9 variants!)
To Review: findTestRunDuration (1 variant) - This strictly speaking isn't a findBy but is located within them
Complete: findMeta (1 variant)
Complete: findTestRunHookStartedBy (1 variant)
Complete: findTestRunHookFinishedBy (1 variant)
Complete: findPickleStepBy (1 variant)
Complete: findStepDefinitionsBy (1 variant)
Complete: findStepBy (1 variant)
Complete: findTestRunFinished (1 variant)
Complete: findTestRunStarted (1 variant)
Fully Complete (2/2): findTestStepsStartedBy (2 variants)
Fully Complete (2/2): findTestStepBy (2 variants)
Fully Complete (3/3): findTestCaseStartedBy (3 variants)
Fully Complete (1/1): findTestCaseFinishedBy (1 variant)
Fully Complete (4/4): findTestCaseBy (4 variants)
Fully Complete (5/5): findPickleBy (5 variants)
Fully Complete (3/3): findHookBy (3 variants)
Fully Complete (2/2): findTestStepsFinishedBy (2 variants)


52
53
54
# File 'lib/cucumber/query.rb', line 52

def count_test_cases_started
  find_all_test_case_started.length
end

#find_all_pickle_stepsObject



60
61
62
# File 'lib/cucumber/query.rb', line 60

def find_all_pickle_steps
  repository.pickle_step_by_id.values
end

#find_all_picklesObject



56
57
58
# File 'lib/cucumber/query.rb', line 56

def find_all_pickles
  repository.pickle_by_id.values
end

#find_all_step_definitionsObject



64
65
66
# File 'lib/cucumber/query.rb', line 64

def find_all_step_definitions
  repository.step_definition_by_id.values
end

#find_all_test_case_finishedObject

This finds all test cases that have finished AND will not be retried



79
80
81
# File 'lib/cucumber/query.rb', line 79

def find_all_test_case_finished
  repository.test_case_finished_by_test_case_started_id.values.reject(&:will_be_retried)
end

#find_all_test_case_startedObject

This finds all test cases from the following conditions (UNION)

-> Test cases that have started, but not yet finished
-> Test cases that have started, finished, but that will NOT be retried


71
72
73
74
75
76
# File 'lib/cucumber/query.rb', line 71

def find_all_test_case_started
  repository.test_case_started_by_id.values.select do |test_case_started|
    test_case_finished = find_test_case_finished_by(test_case_started)
    test_case_finished.nil? || !test_case_finished.will_be_retried
  end
end

#find_all_test_casesObject



83
84
85
# File 'lib/cucumber/query.rb', line 83

def find_all_test_cases
  repository.test_case_by_id.values
end

#find_all_test_run_hook_finishedObject



91
92
93
# File 'lib/cucumber/query.rb', line 91

def find_all_test_run_hook_finished
  repository.test_run_hook_finished_by_test_run_hook_started_id.values
end

#find_all_test_run_hook_startedObject



87
88
89
# File 'lib/cucumber/query.rb', line 87

def find_all_test_run_hook_started
  repository.test_run_hook_started_by_id.values
end

#find_all_test_step_finishedObject



99
100
101
# File 'lib/cucumber/query.rb', line 99

def find_all_test_step_finished
  repository.test_steps_finished_by_test_case_started_id.values.flatten
end

#find_all_test_step_startedObject



95
96
97
# File 'lib/cucumber/query.rb', line 95

def find_all_test_step_started
  repository.test_steps_started_by_test_case_started_id.values.flatten
end

#find_all_test_stepsObject



103
104
105
# File 'lib/cucumber/query.rb', line 103

def find_all_test_steps
  repository.test_step_by_id.values
end

#find_hook_by(message) ⇒ Object

This method will be called with 1 of these 3 messages

[TestStep || TestRunHookStarted || TestRunHookFinished]


109
110
111
112
113
114
115
116
117
118
# File 'lib/cucumber/query.rb', line 109

def find_hook_by(message)
  ensure_only_message_types!(message, i[test_step test_run_hook_started test_run_hook_finished], '#find_hook_by')

  if message.is_a?(Cucumber::Messages::TestRunHookFinished)
    test_run_hook_started_message = find_test_run_hook_started_by(message)
    test_run_hook_started_message ? find_hook_by(test_run_hook_started_message) : nil
  else
    repository.hook_by_id[message.hook_id]
  end
end

#find_metaObject



120
121
122
# File 'lib/cucumber/query.rb', line 120

def find_meta
  repository.meta
end

#find_pickle_by(message) ⇒ Object

This method will be called with 1 of these 5 messages

[TestCase || TestCaseStarted || TestCaseFinished || TestStepStarted || TestStepFinished]


126
127
128
129
130
131
# File 'lib/cucumber/query.rb', line 126

def find_pickle_by(message)
  ensure_only_message_types!(message, i[test_case test_case_started test_case_finished test_step_started test_step_finished], '#find_pickle_by')

  test_case_message = message.is_a?(Cucumber::Messages::TestCase) ? message : find_test_case_by(message)
  repository.pickle_by_id[test_case_message.pickle_id]
end

#find_pickle_step_by(test_step) ⇒ Object

This method will be called with only 1 message

[TestStep]


135
136
137
138
139
# File 'lib/cucumber/query.rb', line 135

def find_pickle_step_by(test_step)
  ensure_only_message_types!(test_step, i[test_step], '#find_pickle_step_by')

  repository.pickle_step_by_id[test_step.pickle_step_id]
end

#find_step_by(pickle_step) ⇒ Object

This method will be called with only 1 message

[PickleStep]


143
144
145
146
147
# File 'lib/cucumber/query.rb', line 143

def find_step_by(pickle_step)
  ensure_only_message_types!(pickle_step, i[pickle_step], '#find_step_by')

  repository.step_by_id[pickle_step.ast_node_ids.first]
end

#find_step_definitions_by(test_step) ⇒ Object

This method will be called with only 1 message

[TestStep]


151
152
153
154
155
156
# File 'lib/cucumber/query.rb', line 151

def find_step_definitions_by(test_step)
  ensure_only_message_types!(test_step, i[test_step], '#find_step_definitions_by')

  ids = test_step.step_definition_ids.nil? ? [] : test_step.step_definition_ids
  ids.map { |id| repository.step_definition_by_id[id] }.compact
end

#find_test_case_by(message) ⇒ Object

This method will be called with 1 of these 4 messages

[TestCaseStarted || TestCaseFinished || TestStepStarted || TestStepFinished]


160
161
162
163
164
165
# File 'lib/cucumber/query.rb', line 160

def find_test_case_by(message)
  ensure_only_message_types!(message, i[test_case_started test_case_finished test_step_started test_step_finished], '#find_test_case_by')

  test_case_started_message = message.is_a?(Cucumber::Messages::TestCaseStarted) ? message : find_test_case_started_by(message)
  repository.test_case_by_id[test_case_started_message.test_case_id]
end

#find_test_case_finished_by(test_case_started) ⇒ Object

This method will be called with only 1 message

[TestCaseStarted]


177
178
179
180
181
# File 'lib/cucumber/query.rb', line 177

def find_test_case_finished_by(test_case_started)
  ensure_only_message_types!(test_case_started, i[test_case_started], '#find_test_case_finished_by')

  repository.test_case_finished_by_test_case_started_id[test_case_started.id]
end

#find_test_case_started_by(message) ⇒ Object

This method will be called with 1 of these 3 messages

[TestCaseFinished || TestStepStarted || TestStepFinished]


169
170
171
172
173
# File 'lib/cucumber/query.rb', line 169

def find_test_case_started_by(message)
  ensure_only_message_types!(message, i[test_case_finished test_step_started test_step_finished], '#find_test_case_started_by')

  repository.test_case_started_by_id[message.test_case_started_id]
end

#find_test_run_durationObject



183
184
185
186
187
188
189
# File 'lib/cucumber/query.rb', line 183

def find_test_run_duration
  if repository.test_run_started.nil? || repository.test_run_finished.nil?
    nil
  else
    timestamp_to_time(repository.test_run_finished.timestamp) - timestamp_to_time(repository.test_run_started.timestamp)
  end
end

#find_test_run_finishedObject



211
212
213
# File 'lib/cucumber/query.rb', line 211

def find_test_run_finished
  repository.test_run_finished
end

#find_test_run_hook_finished_by(test_run_hook_started) ⇒ Object

This method will be called with only 1 message

[TestRunHookStarted]


201
202
203
204
205
# File 'lib/cucumber/query.rb', line 201

def find_test_run_hook_finished_by(test_run_hook_started)
  ensure_only_message_types!(test_run_hook_started, i[test_run_hook_started], '#find_test_run_hook_finished_by')

  repository.test_run_hook_finished_by_test_run_hook_started_id[test_run_hook_started.id]
end

#find_test_run_hook_started_by(test_run_hook_finished) ⇒ Object

This method will be called with only 1 message

[TestRunHookFinished]


193
194
195
196
197
# File 'lib/cucumber/query.rb', line 193

def find_test_run_hook_started_by(test_run_hook_finished)
  ensure_only_message_types!(test_run_hook_finished, i[test_run_hook_finished], '#find_test_run_hook_started_by')

  repository.test_run_hook_started_by_id[test_run_hook_finished.test_run_hook_started_id]
end

#find_test_run_startedObject



207
208
209
# File 'lib/cucumber/query.rb', line 207

def find_test_run_started
  repository.test_run_started
end

#find_test_step_by(message) ⇒ Object

This method will be called with 1 of these 2 messages

[TestStepStarted || TestStepFinished]


217
218
219
220
221
# File 'lib/cucumber/query.rb', line 217

def find_test_step_by(message)
  ensure_only_message_types!(message, i[test_case_started test_case_finished], '#find_test_step_by')

  repository.test_step_by_id[message.test_step_id]
end

#find_test_steps_finished_by(message) ⇒ Object

This method will be called with 1 of these 2 messages

[TestCaseStarted || TestCaseFinished]


234
235
236
237
238
239
240
241
242
243
# File 'lib/cucumber/query.rb', line 234

def find_test_steps_finished_by(message)
  ensure_only_message_types!(message, i[test_case_started test_case_finished], '#find_test_steps_finished_by')

  if message.is_a?(Cucumber::Messages::TestCaseStarted)
    test_steps_finished_by_test_case_started_id.fetch(message.id, [])
  else
    test_case_started_message = find_test_case_started_by(message)
    test_case_started_message.nil? ? [] : find_test_steps_finished_by(test_case_started_message)
  end
end

#find_test_steps_started_by(message) ⇒ Object

This method will be called with 1 of these 2 messages

[TestCaseStarted || TestCaseFinished]


225
226
227
228
229
230
# File 'lib/cucumber/query.rb', line 225

def find_test_steps_started_by(message)
  ensure_only_message_types!(message, i[test_case_started test_case_finished], '#find_test_steps_started_by')

  key = message.is_a?(Cucumber::Messages::TestCaseStarted) ? message.id : message.test_case_started_id
  repository.test_steps_started_by_test_case_started_id.fetch(key, [])
end