colszowka-cucumber_table_formatter 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/cucumber_table_formatter.gemspec +1 -1
- data/lib/cucumber_table_formatter.rb +7 -2
- data/test/cucumber_table_formatter_test.rb +47 -2
- data/test/test_helper.rb +4 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
@@ -27,8 +27,13 @@ class CucumberTableFormatter
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(
|
31
|
-
|
30
|
+
def initialize(table)
|
31
|
+
# Convert string by splitting by newlines if string given. If array, this can be skipped
|
32
|
+
table = table.split("\n") if table.kind_of?(String)
|
33
|
+
# Remove all empty lines and put all others into lines instance variable, cleaned up from newline chars
|
34
|
+
# TODO: Leave lines without a pipe character as they are so whole feature-files can be processed
|
35
|
+
self.lines = table.reject { |l| l.strip.chomp.length == 0 }.map(&:chomp)
|
36
|
+
# Get the whitespace
|
32
37
|
@whitespace = self.lines.first.split("|")[0].length
|
33
38
|
read_columns!
|
34
39
|
end
|
@@ -1,7 +1,52 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class CucumberTableFormatterTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
context "A simple table" do
|
5
|
+
setup { @table = "| a | b | c |" }
|
6
|
+
|
7
|
+
should "be returned as-is" do
|
8
|
+
assert_equal @table, format(@table)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "A simple table with missing whitespace" do
|
13
|
+
setup { @table = "|a|b | c|" }
|
14
|
+
|
15
|
+
should "be returned with whitespace" do
|
16
|
+
assert_equal "| a | b | c |", format(@table)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "A more complex table without leading whitespace" do
|
21
|
+
setup do
|
22
|
+
@table = "| a | b | c |\n|def|ghi|jkl|\n|foobar|baz|blur|"
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be returned in proper format" do
|
26
|
+
expectation = "| a | b | c |\n| def | ghi | jkl |\n| foobar | baz | blur |"
|
27
|
+
assert_equal expectation, format(@table)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "A more complex table with leading whitespace" do
|
32
|
+
setup do
|
33
|
+
@table = " | a | b | c |\n |def|ghi|jkl|\n |foobar|baz|blur|"
|
34
|
+
end
|
35
|
+
|
36
|
+
should "be returned in proper format" do
|
37
|
+
expectation = " | a | b | c |\n | def | ghi | jkl |\n | foobar | baz | blur |"
|
38
|
+
assert_equal expectation, format(@table)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "A more complex table with unicode-characters" do
|
43
|
+
setup do
|
44
|
+
@table = "| Ö | b | c |\n|def|ghi|jkl|\n|foobar|baz|blur|"
|
45
|
+
end
|
46
|
+
|
47
|
+
should "be returned in proper format" do
|
48
|
+
expectation = "| Ö | b | c |\n| def | ghi | jkl |\n| foobar | baz | blur |"
|
49
|
+
assert_equal expectation, format(@table)
|
50
|
+
end
|
6
51
|
end
|
7
52
|
end
|
data/test/test_helper.rb
CHANGED