Skip to content

Commit

Permalink
Merge #14 'Adapt to the move of Location to Cucumber::Core::Test'
Browse files Browse the repository at this point in the history
Also update Changelog.md, cucumber-wire.gemspec and .travis.yml.
  • Loading branch information
brasmusson committed Jul 26, 2018
2 parents 6395397 + 51ff015 commit 8b2c16f
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 34 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ rvm:
- 2.4.0
- 2.3.3
- 2.2
- 2.1
- 2.0

matrix:
allow_failures:
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

----

## [Unreleased] - In Git
## [In Git (targeting 1.0.0)](https://github.com/cucumber/cucumber-ruby-wire/compare/v0.0.1...master)

### Removed

Expand All @@ -20,11 +20,15 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Changed

* Changes to work with a modern Cucumber-Ruby ([#14](https://github.com/cucumber/cucumber-ruby-wire/pull/14) [brasmusson](https://github.com/brasmusson))
* Adapt to the move of Location to Cucumber::Core::Test ([#14](https://github.com/cucumber/cucumber-ruby-wire/pull/14) [brasmusson](https://github.com/brasmusson))

### Fixed

<!-- Releases -->

<!-- Contributors -->
[brasmusson]: https://github.com/brasmusson
[jaysonesmith]: https://github.com/jaysonesmith
[junaruga]: https://github.com/junaruga
[mattwynne]: https://github.com/mattwynne
Expand Down
7 changes: 5 additions & 2 deletions cucumber-wire.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ Gem::Specification.new do |s|
s.homepage = "http://cucumber.io"
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.required_ruby_version = ">= 1.9.3"
s.required_ruby_version = ">= 2.2"

s.add_development_dependency 'cucumber', '~> 2.1.0'
s.add_dependency 'cucumber-core', '~> 3.2'
s.add_dependency 'cucumber-expressions', '~> 6.0'

s.add_development_dependency 'cucumber', '~> 3.1'

s.add_development_dependency 'bundler', '>= 1.3.5'
s.add_development_dependency 'rake', '>= 0.9.2'
Expand Down
4 changes: 1 addition & 3 deletions features/invoke_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion features/step_matches_message.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Feature: Step matches message
"""
-
we.* # MyApp.MyClass:123
"we.*" # MyApp.MyClass:123
1 scenario (1 skipped)
1 step (1 skipped)
Expand Down
6 changes: 3 additions & 3 deletions features/table_diffing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion features/timeouts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/cucumber/wire/add_hooks_filter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
module Cucumber
module Wire
class AddHooksFilter < Core::Filter.new(:connections)
Expand All @@ -10,13 +11,13 @@ def test_case(test_case)
def before_hook(test_case)
# TODO: is this dependency on Cucumber::Hooks OK? Feels a bit internal..
# TODO: how do we express the location of the hook? Should we create one hook per connection so we can use the host:port of the connection?
Cucumber::Hooks.before_hook(test_case.source, Core::Ast::Location.new('TODO:wire')) do
Cucumber::Hooks.before_hook(Core::Test::Location.new('TODO:wire')) do
connections.begin_scenario(test_case)
end
end

def after_hook(test_case)
Cucumber::Hooks.after_hook(test_case.source, Core::Ast::Location.new('TODO:wire')) do
Cucumber::Hooks.after_hook(Core::Test::Location.new('TODO:wire')) do
connections.end_scenario(test_case)
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/cucumber/wire/connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions lib/cucumber/wire/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/wire/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions lib/cucumber/wire/protocol/requests.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
require 'cucumber/wire/request_handler'
require 'cucumber/step_argument'
require 'cucumber/wire/step_argument'

module Cucumber
module Wire
Expand All @@ -25,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
Expand Down Expand Up @@ -69,7 +70,7 @@ def handle_pending(message)

def handle_diff!(tables)
# TODO: figure out if / how we could get a location for a table from the wire (or make a null location)
location = Core::Ast::Location.new(__FILE__, __LINE__)
location = Core::Test::Location.new(__FILE__, __LINE__)
table1 = table(tables[0], location)
table2 = table(tables[1], location)
table1.diff!(table2)
Expand All @@ -89,7 +90,7 @@ def handle_diff(tables)
private

def table(data, location)
Cucumber::MultilineArgument.from_core(Core::Ast::DataTable.new(data, location))
Cucumber::MultilineArgument.from_core(Core::Test::DataTable.new(data, location))
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/cucumber/wire/request_handler.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
24 changes: 24 additions & 0 deletions lib/cucumber/wire/step_argument.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions lib/cucumber/wire/step_definition.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require 'cucumber/core/ast/location'
require 'cucumber/core/test/location'

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"
@location = Core::Ast::Location.from_file_colon_line(data['source'] || "unknown:0")
@expression = registry.create_expression(@regexp_source)
@location = Core::Test::Location.from_file_colon_line(data['source'] || "unknown:0")
end

def invoke(args)
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/wire/connections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b2c16f

Please sign in to comment.