Skip to content

Commit

Permalink
Change DataTable#map_column 'strict' argument to a keyword argument (#…
Browse files Browse the repository at this point in the history
…1594)

* Change map_column 'strict' argument to a keyword argument

* Add link to PR in the changelog
  • Loading branch information
aurelien-reeves authored Dec 8, 2021
1 parent a7e6855 commit 8461102
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Changed

- In `DataTable#map_column`, Changed the `strict` argument into a keyword argument.
See [UPGRADING.md](./UPGRADING.md#upgrading-to-800).
([PR#1594](https://github.com/cucumber/cucumber-ruby/pull/1594)
[Issue#1592](https://github.com/cucumber/cucumber-ruby/issues/1592))

### Removed

- `AfterConfiguration` has been removed. Please use `InstallPlugin` or `BeforeAll` instead.
Expand Down
18 changes: 18 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ Cucumber::Cli::Main.new(
).execute!
```

## DataTable#map_column `strict` argument

The `strict` argument for the `map_column` method has changed to a keyword argument.

### Before 8.0.0

```ruby
table.map_column('column', false).do |value|
end
```

### With cucumber 8.0.0

```ruby
table.map_column('column', strict: false).do |value|
end
```

# Upgrading to 7.1.0

## The wire protocol
Expand Down
4 changes: 1 addition & 3 deletions lib/cucumber/multiline_argument/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ def map_headers(mappings = {}, &block)
# end
# end
#
# rubocop:disable Style/OptionalBooleanParameter # the optional boolean parameter is kept for retrocompatibility
def map_column(column_name, strict = true, &conversion_proc)
def map_column(column_name, strict: true, &conversion_proc)
conversion_procs = @conversion_procs.dup
conversion_procs[column_name.to_s] = { strict: strict, proc: conversion_proc }
self.class.new(Core::Test::DataTable.new(raw), conversion_procs, @header_mappings.dup, @header_conversion_proc)
end
# rubocop:enable Style/OptionalBooleanParameter

# Compares +other_table+ to self. If +other_table+ contains columns
# and/or rows that are not in self, new columns/rows are added at the
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/multiline_argument/data_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ module MultilineArgument

it 'should pass silently if a mapped column does not exist in non-strict mode' do
expect do
new_table = @table.map_column('two', false, &:to_i)
new_table = @table.map_column('two', strict: false, &:to_i)
new_table.hashes
end.not_to raise_error
end

it 'should fail if a mapped column does not exist in strict mode' do
expect do
new_table = @table.map_column('two', true, &:to_i)
new_table = @table.map_column('two', strict: true, &:to_i)
new_table.hashes
end.to raise_error('The column named "two" does not exist')
end
Expand Down Expand Up @@ -161,7 +161,7 @@ module MultilineArgument
%w[two 22222]
])
t2 = table.map_headers({ 'two' => 'Two' }, &:upcase)
.map_column('two', false, &:to_i)
.map_column('two', strict: false, &:to_i)
expect(t2.rows_hash).to eq('ONE' => '1111', 'Two' => 22_222)
end
end
Expand Down

0 comments on commit 8461102

Please sign in to comment.