diff --git a/features/invoke_message.feature b/features/invoke_message.feature index ad9c26d..bb63ae7 100644 --- a/features/invoke_message.feature +++ b/features/invoke_message.feature @@ -47,8 +47,6 @@ Feature: Invoke message Scenario: Wired Given we're all wired - I'll do it later (Cucumber::Pending) - features/wired.feature:3:in `Given we're all wired' 1 scenario (1 pending) 1 step (1 pending) @@ -102,7 +100,7 @@ Feature: Invoke message (::) failed steps (::) The wires are down (Some.Foreign.ExceptionType from localhost:54321) - features/wired.feature:3:in `Given we're all wired' + features/wired.feature:3:in `we're all wired' Failing Scenarios: cucumber features/wired.feature:2 # Scenario: Wired diff --git a/features/step_matches_message.feature b/features/step_matches_message.feature index b0051f8..afa70be 100644 --- a/features/step_matches_message.feature +++ b/features/step_matches_message.feature @@ -70,7 +70,7 @@ Feature: Step matches message """ - - we.* # MyApp.MyClass:123 + "we.*" # MyApp.MyClass:123 1 scenario (1 skipped) 1 step (1 skipped) diff --git a/features/table_diffing.feature b/features/table_diffing.feature index 63d7b21..87278a5 100644 --- a/features/table_diffing.feature +++ b/features/table_diffing.feature @@ -39,7 +39,7 @@ Feature: Wire protocol table diffing Not same (DifferentException from localhost:54321) a.cs:12 b.cs:34 - features/wired.feature:3:in `Given we're all wired' + features/wired.feature:3:in `we're all wired' Failing Scenarios: cucumber features/wired.feature:2 @@ -84,7 +84,7 @@ Feature: Wire protocol table diffing (::) failed steps (::) I wanted things to be different for us (Cucumber::Wire::Exception) - features/wired.feature:3:in `Given we're all wired' + features/wired.feature:3:in `we're all wired' Failing Scenarios: cucumber features/wired.feature:2 @@ -113,7 +113,7 @@ Feature: Wire protocol table diffing | (-) a | (+) b | (Cucumber::MultilineArgument::DataTable::Different) - features/wired.feature:3:in `Given we're all wired' + features/wired.feature:3:in `we're all wired' Failing Scenarios: cucumber features/wired.feature:2 diff --git a/features/timeouts.feature b/features/timeouts.feature index f05fcd5..42ffbff 100644 --- a/features/timeouts.feature +++ b/features/timeouts.feature @@ -52,7 +52,7 @@ Feature: Wire protocol timeouts Scenario: Wired Given we're all wired Timed out calling wire server with message 'invoke' (Timeout::Error) - features/wired.feature:3:in `Given we're all wired' + features/wired.feature:3:in `we're all wired' Failing Scenarios: cucumber features/wired.feature:2 diff --git a/lib/cucumber/wire/connections.rb b/lib/cucumber/wire/connections.rb index 7856fea..4e57a22 100644 --- a/lib/cucumber/wire/connections.rb +++ b/lib/cucumber/wire/connections.rb @@ -16,10 +16,11 @@ class Connections attr_reader :connections private :connections - def initialize(connections, configuration) + def initialize(connections, configuration, registry) raise ArgumentError unless connections @connections = connections @configuration = configuration + @registry = registry end def find_match(test_step) @@ -30,7 +31,7 @@ def find_match(test_step) end def step_matches(step_name) - connections.map{ |c| c.step_matches(step_name)}.flatten + connections.map{ |c| c.step_matches(step_name, @registry)}.flatten end def begin_scenario(test_case) diff --git a/lib/cucumber/wire/plugin.rb b/lib/cucumber/wire/plugin.rb index d1d6277..79843cd 100644 --- a/lib/cucumber/wire/plugin.rb +++ b/lib/cucumber/wire/plugin.rb @@ -5,15 +5,16 @@ module Cucumber module Wire class Plugin - attr_reader :config - private :config + attr_reader :config, :registry + private :config, :registry - def initialize(config) + def initialize(config, registry) @config = config + @registry = registry end def install - connections = Connections.new(wire_files.map { |f| create_connection(f) }, @config) + connections = Connections.new(wire_files.map { |f| create_connection(f) }, config, registry) config.filters << Filters::ActivateSteps.new(StepMatchSearch.new(connections.method(:step_matches), @config), @config) config.filters << AddHooksFilter.new(connections) unless @config.dry_run? config.register_snippet_generator Snippet::Generator.new(connections) diff --git a/lib/cucumber/wire/protocol.rb b/lib/cucumber/wire/protocol.rb index 328c728..738577e 100644 --- a/lib/cucumber/wire/protocol.rb +++ b/lib/cucumber/wire/protocol.rb @@ -3,8 +3,8 @@ module Cucumber module Wire module Protocol - def step_matches(name_to_match) - handler = Requests::StepMatches.new(self) + def step_matches(name_to_match, registry) + handler = Requests::StepMatches.new(self, registry) handler.execute(name_to_match) end diff --git a/lib/cucumber/wire/protocol/requests.rb b/lib/cucumber/wire/protocol/requests.rb index eff80b0..5e32d11 100644 --- a/lib/cucumber/wire/protocol/requests.rb +++ b/lib/cucumber/wire/protocol/requests.rb @@ -1,6 +1,6 @@ # coding: utf-8 require 'cucumber/wire/request_handler' -require 'cucumber/step_argument' +require 'cucumber/wire/step_argument' module Cucumber module Wire @@ -26,7 +26,7 @@ def handle_success(params) private def create_step_match(raw_step_match) - step_definition = StepDefinition.new(@connection, 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 diff --git a/lib/cucumber/wire/request_handler.rb b/lib/cucumber/wire/request_handler.rb index ee8f2f1..118f9cd 100644 --- a/lib/cucumber/wire/request_handler.rb +++ b/lib/cucumber/wire/request_handler.rb @@ -1,9 +1,10 @@ module Cucumber module Wire class RequestHandler - def initialize(connection) + def initialize(connection, registry = nil) @connection = connection @message = underscore(self.class.name.split('::').last) + @registry = registry end def execute(request_params = nil) diff --git a/lib/cucumber/wire/step_argument.rb b/lib/cucumber/wire/step_argument.rb new file mode 100644 index 0000000..116ee3a --- /dev/null +++ b/lib/cucumber/wire/step_argument.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true +require 'cucumber/cucumber_expressions/group' + +module Cucumber + module Wire + # Defines the location and value of a captured argument from the step + # text + class StepArgument + attr_reader :offset + + def initialize(offset, val) + @offset, @value = offset, val + end + + def value(_current_world) + @value + end + + def group + CucumberExpressions::Group.new(@value, @offset, @offset + @value.length, []) + end + end + end +end diff --git a/lib/cucumber/wire/step_definition.rb b/lib/cucumber/wire/step_definition.rb index 09a4f1d..b453cdc 100644 --- a/lib/cucumber/wire/step_definition.rb +++ b/lib/cucumber/wire/step_definition.rb @@ -3,12 +3,14 @@ module Cucumber module Wire class StepDefinition - attr_reader :regexp_source, :location + attr_reader :regexp_source, :location, :registry, :expression - def initialize(connection, data) + def initialize(connection, data, registry) @connection = connection + @registry = registry @id = data['id'] @regexp_source = data['regexp'] || "Unknown" + @expression = registry.create_expression(@regexp_source) @location = Core::Test::Location.from_file_colon_line(data['source'] || "unknown:0") end diff --git a/spec/cucumber/wire/connections_spec.rb b/spec/cucumber/wire/connections_spec.rb index 449e19f..62c9f1a 100644 --- a/spec/cucumber/wire/connections_spec.rb +++ b/spec/cucumber/wire/connections_spec.rb @@ -9,12 +9,12 @@ module Wire connection1 = double(step_matches: [:a, :b]) connection2 = double(step_matches: [:c]) - connections = Connections.new([connection1, connection2], double) + connections = Connections.new([connection1, connection2], double, double) expect(connections.step_matches('')).to eq [:a, :b, :c] end it "copes with no connections" do - connections = Connections.new([], double) + connections = Connections.new([], double, double) expect(connections.step_matches('')).to eq [] end end