Skip to content

Commit c0a94cb

Browse files
committed
More versatile row value access.
Added a method to allow retrieving a row value by it's corresponding parameter.
1 parent 4be8c66 commit c0a94cb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/cucumber/core/ast/examples_table.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def ==(other)
8282
other.data == data
8383
end
8484

85+
def [](parameter_name)
86+
@data[parameter_name]
87+
end
88+
8589
def values
8690
@data.values
8791
end

spec/cucumber/core/ast/examples_table_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ module Cucumber::Core::Ast
7575
end
7676
end
7777

78-
describe 'accesing the values' do
78+
describe 'accessing the values' do
7979
it 'returns the actual row values' do
8080
row = ExamplesTable::Row.new({'x' => '1', 'y' => '2'}, 1, location, language, comments)
8181
expect( row.values ).to eq ['1', '2']
8282
end
83+
84+
it "can access a row value by it's parameter name" do
85+
row = ExamplesTable::Row.new({'x' => '1', 'y' => '2'}, 1, location, language, comments)
86+
expect( row['x']).to eq '1'
87+
end
8388
end
8489

8590
describe 'equality' do

0 commit comments

Comments
 (0)