1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
# frozen_string_literal: true
require 'cucumber/wire/request_handler'
require 'cucumber/wire/step_argument'
module Cucumber
module Wire
module Protocol
module Requests
class StepMatches < RequestHandler
def execute(name_to_match)
@name_to_match = name_to_match
request_params = {
name_to_match: name_to_match
}
super(request_params)
end
def handle_success(params)
params.map do |raw_step_match|
create_step_match(raw_step_match)
end
end
alias handle_step_matches handle_success
private
def create_step_match(raw_step_match)
step_definition = StepDefinition.new(@connection, raw_step_match, @registry)
step_args = raw_step_match['args'].map do |raw_arg|
StepArgument.new(raw_arg['pos'], raw_arg['val'])
end
step_match(step_definition, step_args)
end
def step_match(step_definition, step_args)
StepMatch.new(step_definition, @name_to_match, step_args)
end
end
class SnippetText < RequestHandler
def execute(step_keyword, step_name, multiline_arg_class_name)
request_params = {
step_keyword: step_keyword,
step_name: step_name,
multiline_arg_class: multiline_arg_class_name
}
super(request_params)
end
def handle_success(snippet_text)
snippet_text
end
alias handle_snippet_text handle_success
end
class Invoke < RequestHandler
def execute(step_definition_id, args)
request_params = {
id: step_definition_id,
args: args
}
super(request_params)
end
def handle_pending(message)
raise Pending, message || 'TODO'
end
def handle_diff!(tables)
table1 = table(tables[0])
table2 = table(tables[1])
table1.diff!(table2)
end
def handle_diff(tables)
begin
handle_diff!(tables)
rescue Cucumber::MultilineArgument::DataTable::Different
@connection.diff_failed
end
@connection.diff_ok
end
alias handle_step_failed handle_fail
private
def table(data)
Cucumber::MultilineArgument.from_core(Core::Test::DataTable.new(data))
end
end
class DiffFailed < RequestHandler
alias handle_step_failed handle_fail
end
class DiffOk < RequestHandler
alias handle_step_failed handle_fail
end
class HookRequestHandler < RequestHandler
def execute(test_case)
super(request_params(test_case))
end
def method_missing(name, *args, &block)
# TODO: Hard-code this until Ruby 3.4 is a minimum then this can be removed
raise NoMethodError, "Undefined method '#{name}' for #{self.class}"
end
def respond_to_missing?(name, include_private = false)
# TODO: Remove this once ruby 3.4 is the minimum
super
end
private
def request_params(test_case)
return nil unless test_case.tags.any?
{ 'tags' => clean_tag_names(test_case.tags) }
end
def clean_tag_names(tags)
tags.map { |tag| tag.name.gsub(/^@/, '') }.sort
end
end
BeginScenario = Class.new(HookRequestHandler)
EndScenario = Class.new(HookRequestHandler)
end
end
end
end
|