-
-
Notifications
You must be signed in to change notification settings - Fork 50
V17/redundancy optimisation #318
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
39fb746
3acc239
cf31a38
de6ef90
df0b9e1
8f0b332
ec399bc
8f53769
25ed8b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'cucumber/core/test/location' | ||
| require 'cucumber/core/test/result' | ||
| require 'cucumber/core/test/timer' | ||
| require_relative 'location' | ||
| require_relative 'result' | ||
| require_relative 'timer' | ||
|
|
||
| require 'cucumber/core/test/action/defined' | ||
| require 'cucumber/core/test/action/undefined' | ||
| require 'cucumber/core/test/action/unskippable' | ||
| require_relative 'action/defined' | ||
| require_relative 'action/undefined' | ||
| require_relative 'action/unskippable' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,60 +16,52 @@ module Test | |
| # | ||
| # And a matching StepDefinition: | ||
| # | ||
| # Given /I have:/ do |table| | ||
| # Given('I have:') do |table| | ||
| # data = table.raw | ||
| # end | ||
| # | ||
| # This will store <tt>[['a', 'b'], ['c', 'd']]</tt> in the <tt>data</tt> variable. | ||
| # | ||
| class DataTable | ||
| # Creates a new instance. +raw+ should be an Array of Array of String | ||
| # or an Array of Hash | ||
| attr_reader :raw | ||
|
|
||
| # Creates a new instance. +raw+ should be a square (2d), array of strings or an array of hashes | ||
| # | ||
| # You don't typically create your own DataTable objects - Cucumber will do | ||
| # it internally and pass them to your Step Definitions. | ||
| # | ||
| def initialize(rows) | ||
| raw = ensure_array_of_array(rows) | ||
|
Comment on lines
+28
to
33
|
||
| verify_rows_are_same_length(raw) | ||
| @raw = raw.freeze | ||
| end | ||
| attr_reader :raw | ||
|
|
||
| def describe_to(visitor, *) | ||
| visitor.data_table(self, *) | ||
| end | ||
|
|
||
| def to_step_definition_arg | ||
| dup | ||
| def ==(other) | ||
| other.class == self.class && raw == other.raw | ||
| end | ||
|
|
||
| def data_table? | ||
| true | ||
| end | ||
|
|
||
| def describe_to(visitor, *) | ||
| visitor.data_table(self, *) | ||
| end | ||
|
|
||
| def doc_string? | ||
| false | ||
| end | ||
|
|
||
| # Creates a copy of this table | ||
| # | ||
| def dup | ||
| self.class.new(raw.dup) | ||
| end | ||
|
|
||
| # Returns a new, transposed table. Example: | ||
| # | ||
| # | a | 7 | 4 | | ||
| # | b | 9 | 2 | | ||
| # | ||
| # Gets converted into the following: | ||
| # | ||
| # | a | b | | ||
| # | 7 | 9 | | ||
| # | 4 | 2 | | ||
| # | ||
| def transpose | ||
| self.class.new(raw.transpose) | ||
| def inspect | ||
| %{#<#{self.class} #{raw.inspect}>} | ||
| end | ||
|
|
||
| def lines_count | ||
| raw.count | ||
| end | ||
|
|
||
| def map(&block) | ||
|
|
@@ -80,26 +72,26 @@ def map(&block) | |
| self.class.new(new_raw) | ||
| end | ||
|
|
||
| def lines_count | ||
| raw.count | ||
| end | ||
|
|
||
| def ==(other) | ||
| other.class == self.class && raw == other.raw | ||
| def to_step_definition_arg | ||
| dup | ||
| end | ||
|
|
||
| def inspect | ||
| %{#<#{self.class} #{raw.inspect})>} | ||
| # Returns a new, transposed table. Example: | ||
| # | ||
| # | a | 7 | 4 | | ||
| # | b | 9 | 2 | | ||
| # | ||
| # Gets converted into the following: | ||
| # | ||
| # | a | b | | ||
| # | 7 | 9 | | ||
| # | 4 | 2 | | ||
| def transpose | ||
| self.class.new(raw.transpose) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def verify_rows_are_same_length(raw) | ||
| raw.transpose | ||
| rescue IndexError | ||
| raise ArgumentError, 'Rows must all be the same length' | ||
| end | ||
|
|
||
| def ensure_array_of_array(array) | ||
| array[0].is_a?(Hash) ? hashes_to_array(array) : array | ||
| end | ||
|
|
@@ -108,6 +100,12 @@ def hashes_to_array(hashes) | |
| header = hashes[0].keys.sort | ||
| [header] + hashes.map { |hash| header.map { |key| hash[key] } } | ||
| end | ||
|
|
||
| def verify_rows_are_same_length(raw) | ||
| raw.transpose | ||
| rescue IndexError | ||
| raise ArgumentError, 'Rows must all be the same length' | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.