-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
bugfix: Fix potential NME when converting ParameterType to envelope #1789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
require 'spec_helper' | ||
require 'cucumber/glue/registry_and_more' | ||
require 'cucumber/cucumber_expressions/parameter_type' | ||
require 'support/fake_objects' | ||
|
||
module Cucumber | ||
|
@@ -221,5 +222,60 @@ class << registry.current_world | |
end | ||
end | ||
end | ||
|
||
describe RegistryAndMore do | ||
let(:registry) { described_class.new(double, configuration) } | ||
let(:configuration) { Configuration.new({}) } | ||
|
||
describe '#parameter_type_envelope' do | ||
subject(:envelope) { registry.send(:parameter_type_envelope, parameter_type) } | ||
|
||
let(:parameter_type) { CucumberExpressions::ParameterType.new(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) } | ||
let(:id) { '279e0f28-c91b-4de2-89c0-e7fbc2a15406' } | ||
let(:name) { 'person' } | ||
let(:regexp) { /"[^"]+"/ } | ||
let(:type) { String } | ||
let(:transformer) { ->(s) { s } } | ||
let(:use_for_snippets) { false } | ||
let(:prefer_for_regexp_match) { true } | ||
|
||
before do | ||
allow(configuration).to receive_message_chain(:id_generator, :new_id).and_return(id) # rubocop:disable RSpec/MessageChain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to remove inline stuff, I don't mind it being added to the overall directive to be fixed up at a later date or if you can tackle it here that would be good |
||
end | ||
|
||
it 'produces an envelope with the expected contents' do | ||
expect(envelope).to be_a Cucumber::Messages::Envelope | ||
expect(envelope.parameter_type).to be_a Cucumber::Messages::ParameterType | ||
expect(envelope.parameter_type).to have_attributes( | ||
id: '279e0f28-c91b-4de2-89c0-e7fbc2a15406', | ||
name: 'person', | ||
regular_expressions: [%("[^"]+")], | ||
prefer_for_regular_expression_match: true, | ||
use_for_snippets: false, | ||
source_reference: anything # tested in later cases | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid cop offenses can this be returned as something like |
||
) | ||
end | ||
|
||
context 'when provided a ParameterType with transformer being a lambda' do | ||
let(:transformer) { ->(s) { s } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is autocorrected via rubocop to lambda(&:to_s) as an example |
||
|
||
it 'includes the lambda source-location in the envelope' do | ||
expect(envelope.parameter_type.source_reference).to be_a Cucumber::Messages::SourceReference | ||
expect(envelope.parameter_type.source_reference).to have_attributes( | ||
uri: transformer.source_location[0], | ||
location: have_attributes(line: transformer.source_location[1]) | ||
) | ||
end | ||
end | ||
|
||
context 'when provided a ParameterType with transformer being a bound method, which has no source location' do | ||
let(:transformer) { String.method(:new) } | ||
|
||
it 'does not include the source-location in the envelope' do | ||
expect(envelope.parameter_type.source_reference).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will conflict soon as I'm about to cut v10. I will happily cut another v10.0.1 soon after if desired