colszowka-cucumber_table_formatter 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
2
+ :patch: 1
3
3
  :major: 0
4
4
  :minor: 2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cucumber_table_formatter}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christoph Olszowka"]
@@ -27,8 +27,13 @@ class CucumberTableFormatter
27
27
  end
28
28
  end
29
29
 
30
- def initialize(table_string)
31
- self.lines = table_string.reject { |l| l.strip.chomp.length == 0 }.map(&:chomp)
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
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
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
@@ -7,4 +7,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'cucumber_table_formatter'
8
8
 
9
9
  class Test::Unit::TestCase
10
+ # Shorthand for CucumberTableFormatter.new(table).formatted
11
+ def format(table)
12
+ CucumberTableFormatter.new(table).formatted
13
+ end
10
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colszowka-cucumber_table_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Olszowka