table_diff 0.0.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/README.md +52 -0
- data/lib/table_diff.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/table_diff/comparable_table_spec.rb +53 -0
- data/spec/table_diff/compare_tables_spec.rb +28 -0
- data/spec/table_diff/different_tables_spec.rb +4 -0
- data/spec/table_diff/output_formatter_spec.rb +32 -0
- data/spec/table_diff/row_spec.rb +38 -0
- data/spec/table_diff/row_with_differences_spec.rb +28 -0
- data/spec/table_diff/table_spec.rb +44 -0
- metadata +75 -0
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Table Diff
|
2
|
+
|
3
|
+
A simple library for use in testing to compare an actual and expected table. Compatible with Cucumber, Rspec, and Turnip
|
4
|
+
|
5
|
+
## Tables
|
6
|
+
|
7
|
+
A table is essentially an array of arrays. Cucumber and Turnip both provide table classes that should be compatible with this library.
|
8
|
+
|
9
|
+
A sample table:
|
10
|
+
|
11
|
+
[
|
12
|
+
[ "Name", "Age", "Height" ], # The first 'row' will be used as headers
|
13
|
+
[ "Dave", "99" , " 999cm" ],
|
14
|
+
[ "Andy", "99" , " 999cm" ]
|
15
|
+
]
|
16
|
+
|
17
|
+
This would be printed as:
|
18
|
+
|
19
|
+
| Name | Age | Height |
|
20
|
+
| Dave | 99 | 999cm |
|
21
|
+
| Andy | 99 | 999cm |
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TableDiff::CompareTables.compare(actual, expected).should_not be_different
|
26
|
+
|
27
|
+
## Forthcoming
|
28
|
+
|
29
|
+
* Should handle extra rows
|
30
|
+
* Should handle extra columns
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'table_diff'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install table_diff
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/lib/table_diff.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "table_diff/version"
|
2
|
+
|
3
|
+
module TableDiff
|
4
|
+
autoload :Table, "table_diff/table"
|
5
|
+
autoload :ComparableTable, "table_diff/comparable_table"
|
6
|
+
autoload :DifferentTables, "table_diff/different_tables"
|
7
|
+
|
8
|
+
autoload :Row, "table_diff/row"
|
9
|
+
autoload :RowWithDifferences, "table_diff/row_with_differences"
|
10
|
+
|
11
|
+
autoload :CompareTables, "table_diff/compare_tables"
|
12
|
+
autoload :OutputFormatter, "table_diff/output_formatter"
|
13
|
+
|
14
|
+
class MissingRows < Exception; end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'table_diff'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::ComparableTable do
|
4
|
+
|
5
|
+
let(:table) { stub( :hashes => [{"foo" => "bar"}, {"baz" => "xlerb"}], :headers => {"foo" => "foo"}) }
|
6
|
+
let(:comparable_table) { described_class.new(table) }
|
7
|
+
|
8
|
+
describe "#rows" do
|
9
|
+
subject { comparable_table.rows }
|
10
|
+
it "is a collection of Rows" do
|
11
|
+
should(satisfy do |rows|
|
12
|
+
rows.all? { |r| r.is_a? TableDiff::Row }
|
13
|
+
end)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#diff" do
|
18
|
+
subject { comparable_table.diff(expected_table) }
|
19
|
+
|
20
|
+
context "when there are no differences" do
|
21
|
+
let(:expected_table) { comparable_table }
|
22
|
+
it "returns self" do
|
23
|
+
should == comparable_table
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when there are differences" do
|
28
|
+
let(:expected_table) do
|
29
|
+
described_class.new( stub( :hashes => [{ "foo" => "bar"}, {"baz" => "nope"}]) )
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises DifferentTables" do
|
33
|
+
expect { subject }.to raise_error TableDiff::DifferentTables
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the number of rows is not equal" do
|
38
|
+
let(:expected_table) do
|
39
|
+
described_class.new( stub( :hashes => [{"baz" => "nope"}] ) )
|
40
|
+
end
|
41
|
+
it "raises an error" do
|
42
|
+
expect {
|
43
|
+
subject
|
44
|
+
}.to raise_error TableDiff::MissingRows
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#different?" do
|
50
|
+
subject { comparable_table }
|
51
|
+
it { should_not be_different }
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::CompareTables do
|
4
|
+
let(:diff) { TableDiff::CompareTables.compare actual, expected }
|
5
|
+
|
6
|
+
subject { diff }
|
7
|
+
context "when tables are the same" do
|
8
|
+
let(:actual) do
|
9
|
+
TableDiff::Table.new [ [ "Name", "Email", "Hat Size" ], [ "Dave", "a@b.co", "7 3/4" ] ]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:expected) do
|
13
|
+
actual
|
14
|
+
end
|
15
|
+
it { should_not be_different }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when tables are not the same" do
|
19
|
+
let(:actual) do
|
20
|
+
TableDiff::Table.new [ [ "Name", "Email", "Hat Size" ], [ "Dave", "a@b.co", "7" ] ]
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:expected) do
|
24
|
+
TableDiff::Table.new [ [ "Name", "Email", "Hat Size" ], [ "Dave", "a@b.co", 7 ] ]
|
25
|
+
end
|
26
|
+
it { expect {subject}.to raise_error TableDiff::DifferentTables }
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::OutputFormatter do
|
4
|
+
HEADERS = ["One", "Two", "Tree"]
|
5
|
+
Row = TableDiff::Row
|
6
|
+
RowWithDifferences = TableDiff::RowWithDifferences
|
7
|
+
def row_hash(array)
|
8
|
+
Hash[HEADERS.zip(array)]
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:rows) do
|
12
|
+
actual = Row.new(row_hash ["Dave", "Jon", "Josh"])
|
13
|
+
expected = Row.new(row_hash ["Dave", "Brian", "Josh"])
|
14
|
+
[
|
15
|
+
Row.new(row_hash(HEADERS)),
|
16
|
+
Row.new(row_hash ["Foo", "Bar", "Baz"]),
|
17
|
+
RowWithDifferences.new( actual, expected)
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
subject { described_class.new(rows) }
|
23
|
+
|
24
|
+
it do
|
25
|
+
expected = <<EOS
|
26
|
+
| One | Two | Tree |
|
27
|
+
| Foo | Bar | Baz |
|
28
|
+
| Dave | Jon (Brian) | Josh |
|
29
|
+
EOS
|
30
|
+
subject.to_s.should == expected.chomp
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::Row do
|
4
|
+
let(:row_hash) do
|
5
|
+
{ "Name" => "Dave", "Number" => 11 }
|
6
|
+
end
|
7
|
+
let(:row) { described_class.new( row_hash ) }
|
8
|
+
|
9
|
+
it "keeps the raw row hash" do
|
10
|
+
row.raw.should == row_hash
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#diff" do
|
14
|
+
context "when there are no differences" do
|
15
|
+
let(:expected_row) { described_class.new(row_hash) }
|
16
|
+
it "returns self" do
|
17
|
+
row.diff(expected_row).should == row
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when there are differences" do
|
22
|
+
let(:expected_row) { described_class.new(row_hash.merge("Name" => "Bob")) }
|
23
|
+
it "returns an instance of RowWithDifferences" do
|
24
|
+
row.diff(expected_row).should be_a TableDiff::RowWithDifferences
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#different?" do
|
30
|
+
subject { row }
|
31
|
+
it { should_not be_different }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#widths" do
|
35
|
+
subject { row.widths }
|
36
|
+
it { should == [ 4, 2 ] }
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::RowWithDifferences do
|
4
|
+
subject { described_class.new nil, nil }
|
5
|
+
describe "#different?" do
|
6
|
+
it { should be_different }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "printing methods" do
|
10
|
+
let(:actual) { TableDiff::Row.new( { "a" => "bee", "d" => "foo"} ) }
|
11
|
+
let(:expected) { TableDiff::Row.new( { "a" => "woo", "d" => "foo"} ) }
|
12
|
+
describe "#strings" do
|
13
|
+
subject { described_class.new(actual, expected).strings }
|
14
|
+
|
15
|
+
it do
|
16
|
+
should == [ "bee (woo)", "foo" ]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#widths" do
|
21
|
+
subject { described_class.new(actual, expected).widths }
|
22
|
+
|
23
|
+
it do
|
24
|
+
should == [ 9, 3 ]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TableDiff::Table do
|
4
|
+
let(:raw_table) do
|
5
|
+
[
|
6
|
+
[ "Name", "Email", "Hat Size"],
|
7
|
+
[ "Dave", "a@b.co", "7 3/4" ]
|
8
|
+
]
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:table) { described_class.new(raw_table) }
|
12
|
+
|
13
|
+
it "keeps the raw state" do
|
14
|
+
table.raw.should == raw_table
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#headers" do
|
18
|
+
subject { table.headers }
|
19
|
+
it "is the first row of the table" do
|
20
|
+
should == raw_table[0]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#rows" do
|
25
|
+
subject { table.rows }
|
26
|
+
it "is all but the first row" do
|
27
|
+
should == [raw_table[1]]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#hashes" do
|
32
|
+
subject { table.hashes }
|
33
|
+
|
34
|
+
let(:hashes) do
|
35
|
+
[{ "Name" => "Dave",
|
36
|
+
"Email" => "a@b.co",
|
37
|
+
"Hat Size" => "7 3/4" }]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "hashes the header => column" do
|
41
|
+
should == hashes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: table_diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Lyon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2151932660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2151932660
|
25
|
+
description: A simple library for use in testing to compare an actual and expected
|
26
|
+
table. Compatible with Cucumber, Rspec, and Turnip
|
27
|
+
email:
|
28
|
+
- dave@davelyon.net
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/table_diff.rb
|
34
|
+
- README.md
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
- spec/table_diff/comparable_table_spec.rb
|
37
|
+
- spec/table_diff/compare_tables_spec.rb
|
38
|
+
- spec/table_diff/different_tables_spec.rb
|
39
|
+
- spec/table_diff/output_formatter_spec.rb
|
40
|
+
- spec/table_diff/row_spec.rb
|
41
|
+
- spec/table_diff/row_with_differences_spec.rb
|
42
|
+
- spec/table_diff/table_spec.rb
|
43
|
+
homepage: https://github.com/davelyon/table_diff
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.15
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Table Difference library for use in testing
|
67
|
+
test_files:
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/table_diff/comparable_table_spec.rb
|
70
|
+
- spec/table_diff/compare_tables_spec.rb
|
71
|
+
- spec/table_diff/different_tables_spec.rb
|
72
|
+
- spec/table_diff/output_formatter_spec.rb
|
73
|
+
- spec/table_diff/row_spec.rb
|
74
|
+
- spec/table_diff/row_with_differences_spec.rb
|
75
|
+
- spec/table_diff/table_spec.rb
|