From c0a94cb6c05350652f19010c20274e70000e6d1b Mon Sep 17 00:00:00 2001 From: Eric Kessler Date: Wed, 30 Nov 2016 18:57:20 -0500 Subject: [PATCH] More versatile row value access. Added a method to allow retrieving a row value by it's corresponding parameter. --- lib/cucumber/core/ast/examples_table.rb | 4 ++++ spec/cucumber/core/ast/examples_table_spec.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cucumber/core/ast/examples_table.rb b/lib/cucumber/core/ast/examples_table.rb index 79c4f9f9..cab5de44 100644 --- a/lib/cucumber/core/ast/examples_table.rb +++ b/lib/cucumber/core/ast/examples_table.rb @@ -82,6 +82,10 @@ def ==(other) other.data == data end + def [](parameter_name) + @data[parameter_name] + end + def values @data.values end diff --git a/spec/cucumber/core/ast/examples_table_spec.rb b/spec/cucumber/core/ast/examples_table_spec.rb index 0592a57a..1b4a4cb3 100644 --- a/spec/cucumber/core/ast/examples_table_spec.rb +++ b/spec/cucumber/core/ast/examples_table_spec.rb @@ -75,11 +75,16 @@ module Cucumber::Core::Ast end end - describe 'accesing the values' do + describe 'accessing the values' do it 'returns the actual row values' do row = ExamplesTable::Row.new({'x' => '1', 'y' => '2'}, 1, location, language, comments) expect( row.values ).to eq ['1', '2'] end + + it "can access a row value by it's parameter name" do + row = ExamplesTable::Row.new({'x' => '1', 'y' => '2'}, 1, location, language, comments) + expect( row['x']).to eq '1' + end end describe 'equality' do