Skip to content

Commit

Permalink
can now override and without throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 29, 2017
1 parent f61ad74 commit 08fbcc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Fixed

* Gemspec has `required_ruby_version = '>= 2.1'`
* `ParameterType` can now override `use_for_snippets` and `prefer_for_regexp_match` without throwing an error. ([@aslakhellesoy](https://github.com/aslakhellesoy))
* Gemspec has `required_ruby_version = '>= 2.1'` ([@aslakhellesoy](https://github.com/aslakhellesoy))

### Improved

Expand Down
16 changes: 16 additions & 0 deletions features/docs/writing_support_code/parameter_types.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ Feature: Parameter Types
"""
When I run `cucumber features/foo.feature`
Then it should pass

Scenario: Parameter type defined with ParameterType method
If your parameter type's `regexp` is very general, you can tell
Cucumber not to suggest its use in snippets:

Given a file named "features/support/parameter_types.rb" with:
"""
ParameterType(
name: 'person',
regexp: /[A-Z]\w+/,
transformer: -> (name) { Person.new(name) },
use_for_snippets: false
)
"""
When I run `cucumber features/foo.feature`
Then it should pass
8 changes: 6 additions & 2 deletions lib/cucumber/glue/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def AfterStep(*tag_expressions, &proc)

def ParameterType(options)
type = options[:type] || Object
use_for_snippets = true if options[:use_for_snippets].nil?
prefer_for_regexp_match = false if options[:prefer_for_regexp_match].nil?
use_for_snippets = if_nil(options[:use_for_snippets], true)
prefer_for_regexp_match = if_nil(options[:prefer_for_regexp_match], false)

parameter_type = CucumberExpressions::ParameterType.new(
options[:name],
Expand All @@ -102,6 +102,10 @@ def ParameterType(options)
Dsl.define_parameter_type(parameter_type)
end

def if_nil(value, default)
value.nil? ? default : value
end

# Registers a proc that will run after Cucumber is configured. You can register as
# as you want (typically from ruby scripts under <tt>support/hooks.rb</tt>).
def AfterConfiguration(&proc)
Expand Down

0 comments on commit 08fbcc9

Please sign in to comment.