tty 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +141 -23
  3. data/benchmarks/table.rb +5 -0
  4. data/lib/tty/logger.rb +71 -0
  5. data/lib/tty/support/equatable.rb +6 -2
  6. data/lib/tty/system/which.rb +41 -0
  7. data/lib/tty/system.rb +8 -0
  8. data/lib/tty/table/border/ascii.rb +15 -16
  9. data/lib/tty/table/border/null.rb +9 -4
  10. data/lib/tty/table/border/unicode.rb +15 -16
  11. data/lib/tty/table/border.rb +69 -9
  12. data/lib/tty/table/border_dsl.rb +247 -0
  13. data/lib/tty/table/border_options.rb +52 -0
  14. data/lib/tty/table/field.rb +101 -0
  15. data/lib/tty/table/header.rb +115 -0
  16. data/lib/tty/table/operation/alignment_set.rb +14 -10
  17. data/lib/tty/table/operation/truncation.rb +19 -13
  18. data/lib/tty/table/operation/wrapped.rb +20 -9
  19. data/lib/tty/table/operations.rb +69 -0
  20. data/lib/tty/table/renderer/basic.rb +35 -26
  21. data/lib/tty/table/renderer.rb +13 -1
  22. data/lib/tty/table/row.rb +174 -0
  23. data/lib/tty/table.rb +96 -21
  24. data/lib/tty/text/truncation.rb +1 -1
  25. data/lib/tty/vector.rb +8 -7
  26. data/lib/tty/version.rb +1 -1
  27. data/lib/tty.rb +21 -0
  28. data/spec/tty/logger/new_spec.rb +36 -0
  29. data/spec/tty/logger/valid_level_spec.rb +33 -0
  30. data/spec/tty/system/platform_spec.rb +8 -0
  31. data/spec/tty/system/which_spec.rb +41 -0
  32. data/spec/tty/table/access_spec.rb +12 -1
  33. data/spec/tty/table/add_row_spec.rb +28 -0
  34. data/spec/tty/table/border/new_spec.rb +9 -4
  35. data/spec/tty/table/border/null/rendering_spec.rb +39 -1
  36. data/spec/tty/table/border/options/from_spec.rb +39 -0
  37. data/spec/tty/table/border/options/new_spec.rb +15 -0
  38. data/spec/tty/table/border/style_spec.rb +70 -0
  39. data/spec/tty/table/border_spec.rb +107 -0
  40. data/spec/tty/table/each_with_index_spec.rb +30 -0
  41. data/spec/tty/table/field/equality_spec.rb +51 -0
  42. data/spec/tty/table/field/new_spec.rb +29 -0
  43. data/spec/tty/table/field/width_spec.rb +21 -0
  44. data/spec/tty/table/header/call_spec.rb +30 -0
  45. data/spec/tty/table/header/new_spec.rb +25 -0
  46. data/spec/tty/table/header/set_spec.rb +15 -0
  47. data/spec/tty/table/header/to_ary_spec.rb +14 -0
  48. data/spec/tty/table/header_spec.rb +14 -0
  49. data/spec/tty/table/operation/alignment_set/align_rows_spec.rb +8 -1
  50. data/spec/tty/table/operation/truncation/call_spec.rb +27 -0
  51. data/spec/tty/table/operation/wrapped/call_spec.rb +27 -0
  52. data/spec/tty/table/operations/new_spec.rb +32 -0
  53. data/spec/tty/table/options_spec.rb +17 -9
  54. data/spec/tty/table/renderer/basic/alignment_spec.rb +76 -29
  55. data/spec/tty/table/renderer/basic/separator_spec.rb +99 -0
  56. data/spec/tty/table/renderer_spec.rb +7 -1
  57. data/spec/tty/table/renders_with_spec.rb +35 -28
  58. data/spec/tty/table/rotate_spec.rb +1 -0
  59. data/spec/tty/table/row/access_spec.rb +25 -0
  60. data/spec/tty/table/row/call_spec.rb +41 -0
  61. data/spec/tty/table/row/data_spec.rb +26 -0
  62. data/spec/tty/table/row/equality_spec.rb +73 -0
  63. data/spec/tty/table/row/new_spec.rb +41 -0
  64. data/spec/tty/table/row/to_ary_spec.rb +14 -0
  65. data/spec/tty/text/truncation/truncate_spec.rb +6 -0
  66. metadata +72 -10
data/lib/tty.rb CHANGED
@@ -16,6 +16,7 @@ require 'tty/text'
16
16
  require 'tty/vector'
17
17
  require 'tty/shell'
18
18
  require 'tty/coercer'
19
+ require 'tty/logger'
19
20
 
20
21
  require 'tty/coercer/range'
21
22
  require 'tty/coercer/integer'
@@ -34,10 +35,19 @@ require 'tty/terminal/color'
34
35
  require 'tty/terminal/echo'
35
36
  require 'tty/terminal/home'
36
37
 
38
+ require 'tty/system/which'
39
+
37
40
  require 'tty/text/wrapping'
38
41
  require 'tty/text/truncation'
39
42
 
43
+ require 'tty/table/field'
44
+ require 'tty/table/header'
45
+ require 'tty/table/row'
46
+ require 'tty/table/options'
47
+
40
48
  require 'tty/table/border'
49
+ require 'tty/table/border_dsl'
50
+ require 'tty/table/border_options'
41
51
  require 'tty/table/border/unicode'
42
52
  require 'tty/table/border/ascii'
43
53
  require 'tty/table/border/null'
@@ -47,6 +57,7 @@ require 'tty/table/orientation'
47
57
  require 'tty/table/orientation/horizontal'
48
58
  require 'tty/table/orientation/vertical'
49
59
 
60
+ require 'tty/table/operations'
50
61
  require 'tty/table/operation/alignment_set'
51
62
  require 'tty/table/operation/alignment'
52
63
  require 'tty/table/operation/truncation'
@@ -57,6 +68,9 @@ module TTY
57
68
  # Raised when the argument type is different from expected
58
69
  class TypeError < ArgumentError; end
59
70
 
71
+ # Raised when the operation is not implemented
72
+ class NoImplementationError < NotImplementedError; end
73
+
60
74
  # Raised when the required argument is not supplied
61
75
  class ArgumentRequired < ArgumentError; end
62
76
 
@@ -72,6 +86,13 @@ module TTY
72
86
  # Raised when the passed in validation argument is of wrong type
73
87
  class ValidationCoercion < TypeError; end
74
88
 
89
+ # Raised when the attribute is unknown
90
+ class UnknownAttributeError < IndexError; end
91
+
92
+
93
+ # An empty array used as a default value
94
+ EMPTY_ARRAY = Array.new.freeze
95
+
75
96
  class << self
76
97
 
77
98
  # Return terminal instance
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Logger, '#new' do
6
+ let(:object) { described_class }
7
+ let(:output) { StringIO.new }
8
+
9
+ subject { object.new options }
10
+
11
+ context 'when default' do
12
+ let(:options) { {:namespace => ''} }
13
+
14
+ its(:level) { should eql object::ALL }
15
+
16
+ its(:output) { should eql $stderr }
17
+
18
+ its(:timestamp_format) { should eql '%Y-%m-%d %T' }
19
+ end
20
+
21
+ context 'when custom' do
22
+ let(:options) { {
23
+ :namespace => 'tty::color',
24
+ :level => 2,
25
+ :output => output,
26
+ :timestamp_format => "%dd" } }
27
+
28
+ its(:namespace) { should eql 'tty::color' }
29
+
30
+ its(:level) { should eql 2 }
31
+
32
+ its(:output) { should eql output }
33
+
34
+ its(:timestamp_format) { should eql '%dd' }
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Logger, '#valid_level' do
6
+ let(:object) { described_class }
7
+
8
+ subject { object.valid_level?(level) }
9
+
10
+ context 'when level is nil' do
11
+ let(:level) { nil }
12
+
13
+ it { should be_false }
14
+ end
15
+
16
+ context 'when level is non numeric' do
17
+ let(:level) { 'a' }
18
+
19
+ it { should be_false }
20
+ end
21
+
22
+ context 'when level is not a valid number' do
23
+ let(:level) { -1 }
24
+
25
+ it { should be_false }
26
+ end
27
+
28
+ context 'when level is valid number' do
29
+ let(:level) { 0 }
30
+
31
+ it { should be_true }
32
+ end
33
+ end
@@ -9,6 +9,8 @@ describe TTY::System, '#platform' do
9
9
 
10
10
  it { should respond_to(:unix?) }
11
11
 
12
+ it { should respond_to(:which) }
13
+
12
14
  it 'checks if windows' do
13
15
  RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'windows'
14
16
  subject.windows?.should be_true
@@ -18,4 +20,10 @@ describe TTY::System, '#platform' do
18
20
  RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'darwin'
19
21
  subject.unix?.should be_true
20
22
  end
23
+
24
+ it 'delegates to which' do
25
+ command = 'ruby'
26
+ TTY::System::Which.should_receive(:new).with(command)
27
+ subject.which(command)
28
+ end
21
29
  end
@@ -0,0 +1,41 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe TTY::System::Which, '#which' do
5
+ let(:path) { "/usr/local/bin:/usr/local/git/bin" }
6
+ let(:extension) { '.bat' }
7
+
8
+ context 'without extension' do
9
+ before {
10
+ ENV.stub(:[]).with('PATHEXT').and_return(nil)
11
+ ENV.stub(:[]).with('PATH').and_return(path)
12
+ }
13
+
14
+ it 'finds command' do
15
+ File.stub(:executable?) { true }
16
+ expect(subject.which("ruby")).to eql "/usr/local/bin/ruby"
17
+ end
18
+
19
+ it "doesn't find command" do
20
+ File.stub(:executable?) { false }
21
+ expect(subject.which("ruby")).to be_nil
22
+ end
23
+ end
24
+
25
+ context 'with extension' do
26
+ before {
27
+ ENV.stub(:[]).with('PATHEXT').and_return(extension)
28
+ ENV.stub(:[]).with('PATH').and_return(path)
29
+ }
30
+
31
+ it 'finds command' do
32
+ File.stub(:executable?) { true }
33
+ expect(subject.which("ruby")).to eql "/usr/local/bin/ruby.bat"
34
+ end
35
+
36
+ it "doesn't find command" do
37
+ File.stub(:executable?) { false }
38
+ expect(subject.which("ruby")).to be_nil
39
+ end
40
+ end
41
+ end
@@ -3,8 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe TTY::Table, 'access' do
6
+ let(:header) { [:head1, :head2] }
6
7
  let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
- subject { TTY::Table.new :rows => rows }
8
+ subject { TTY::Table.new :rows => rows, :header => header }
8
9
 
9
10
  it { should respond_to(:element) }
10
11
 
@@ -49,6 +50,16 @@ describe TTY::Table, 'access' do
49
50
  end
50
51
 
51
52
  context '#column' do
53
+ it "gets based on header name" do
54
+ subject.column(:head1).should eql ['a1', 'b1']
55
+ end
56
+
57
+ it "yields based on header name" do
58
+ yielded = []
59
+ subject.column(:head1) { |el| yielded << el }
60
+ expect(yielded).to eql(['a1', 'b1'])
61
+ end
62
+
52
63
  it 'returns nil for wrong index' do
53
64
  subject.column(11).should be_nil
54
65
  end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, '#<<' do
6
+ let(:rows) { ['a', 'b', 'c'] }
7
+ let(:object) { described_class }
8
+
9
+ subject(:table) { object[rows] }
10
+
11
+ context 'with primitive values' do
12
+ let(:row) { [1, 2, 3] }
13
+
14
+ it 'extracts values correctly' do
15
+ table << row
16
+ expect(table.to_a.last).to eql(row)
17
+ end
18
+ end
19
+
20
+ context 'with complex values' do
21
+ let(:row) { [1, { :value => 2 }, 3] }
22
+
23
+ it 'extracts values correctly' do
24
+ table << row
25
+ expect(table.to_a.last).to eql([1,2,3])
26
+ end
27
+ end
28
+ end
@@ -3,18 +3,23 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe TTY::Table::Border, '#new' do
6
- subject { klass.new }
6
+ let(:row) { [] }
7
+ subject(:instance) { klass.new row }
7
8
 
8
9
  context 'when abstract' do
9
10
  let(:klass) { described_class }
10
11
 
11
- specify { expect { subject }.to raise_error(NotImplementedError) }
12
+ specify { expect { instance }.to raise_error(NotImplementedError) }
12
13
  end
13
14
 
14
15
  context 'when concrete' do
15
- let(:klass) { Class.new }
16
+ let(:klass) {
17
+ Class.new do
18
+ def initialize(row); end
19
+ end
20
+ }
16
21
 
17
- specify { expect {subject }.to_not raise_error(NotImplementedError) }
22
+ specify { expect { instance }.to_not raise_error(NotImplementedError) }
18
23
 
19
24
  it { should be_instance_of klass }
20
25
  end
@@ -3,8 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe TTY::Table::Border::Null, '#rendering' do
6
+ let(:border) { nil }
6
7
 
7
- subject { described_class.new row }
8
+ subject { described_class.new row, border }
8
9
 
9
10
  context 'with empty row' do
10
11
  let(:row) { [] }
@@ -46,4 +47,41 @@ describe TTY::Table::Border::Null, '#rendering' do
46
47
  end
47
48
  end
48
49
 
50
+ context 'with border' do
51
+ let(:row) { ['a1', 'a2', 'a3'] }
52
+ let(:border) { { :characters => {
53
+ 'top' => '=',
54
+ 'top_mid' => '=',
55
+ 'top_left' => '=',
56
+ 'top_right' => '=',
57
+ 'bottom' => '=',
58
+ 'bottom_mid' => '=',
59
+ 'bottom_left' => '=',
60
+ 'bottom_right' => '=',
61
+ 'mid' => '=',
62
+ 'mid_mid' => '=',
63
+ 'mid_left' => '=',
64
+ 'mid_right' => '=',
65
+ 'left' => '=',
66
+ 'center' => '=',
67
+ 'right' => '='
68
+ } } }
69
+
70
+ it 'draws top line' do
71
+ expect(subject.top_line).to eql '=========='
72
+ end
73
+
74
+ it 'draws separator line' do
75
+ expect(subject.separator).to eql '=========='
76
+ end
77
+
78
+ it 'draws bottom line' do
79
+ expect(subject.bottom_line).to eql '=========='
80
+ end
81
+
82
+ it 'draws row line' do
83
+ expect(subject.row_line).to eql '=a1=a2=a3='
84
+ end
85
+ end
86
+
49
87
  end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::BorderOptions, '#from' do
6
+
7
+ subject(:options) { described_class.from object }
8
+
9
+ context 'when empty hash' do
10
+ let(:object) { {} }
11
+
12
+ it { expect(options.style).to be_nil }
13
+
14
+ it { expect(options.separator).to be_nil }
15
+ end
16
+
17
+ context 'when hash' do
18
+ let(:object) { { :style => :red, :separator => :none } }
19
+
20
+ it { expect(options).to be_kind_of(described_class) }
21
+
22
+ it { expect(options.style).to eql :red }
23
+
24
+ it { expect(options.separator).to eql :none }
25
+
26
+ it { expect(options.characters).to eql({}) }
27
+ end
28
+
29
+ context 'when other BorderOptions' do
30
+ let(:object) { described_class.new(nil, nil, :blue) }
31
+
32
+ it { expect(options).to eql object }
33
+
34
+ it { expect(options.characters).to eql({}) }
35
+
36
+ it { expect(options.style).to eql :blue }
37
+ end
38
+
39
+ end # from
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::BorderOptions, '.new' do
6
+
7
+ subject(:options) { described_class.new }
8
+
9
+ its(:characters) { should eql({}) }
10
+
11
+ its(:separator) { should be_nil }
12
+
13
+ its(:style) { should be_nil }
14
+
15
+ end # new
@@ -0,0 +1,70 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, 'with style' do
6
+ let(:header) { ['h1', 'h2', 'h3'] }
7
+ let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
+
9
+ subject(:table) { described_class.new header, rows, :renderer => renderer }
10
+
11
+ context 'when default' do
12
+ let(:renderer) { :basic }
13
+
14
+ it "sets through hash" do
15
+ table.border :style => :red
16
+ expect(table.border.style).to eql :red
17
+ end
18
+
19
+ it "sets through attribute" do
20
+ table.border.style = :red
21
+ expect(table.border.style).to eql :red
22
+ end
23
+
24
+ it "renders without color" do
25
+ table.to_s.should == <<-EOS.normalize
26
+ h1 h2 h3
27
+ a1 a2 a3
28
+ b1 b2 b3
29
+ EOS
30
+ end
31
+ end
32
+
33
+ context 'when ascii' do
34
+ let(:renderer) { :ascii }
35
+ let(:red) { "\e[31m" }
36
+ let(:clear) { "\e[0m" }
37
+
38
+ it "renders border in color" do
39
+ table.border.style= :red
40
+
41
+ table.to_s.should == <<-EOS.normalize
42
+ #{red}+--+--+--+#{clear}
43
+ #{red}|#{clear}h1#{red}|#{clear}h2#{red}|#{clear}h3#{red}|#{clear}
44
+ #{red}+--+--+--+#{clear}
45
+ #{red}|#{clear}a1#{red}|#{clear}a2#{red}|#{clear}a3#{red}|#{clear}
46
+ #{red}|#{clear}b1#{red}|#{clear}b2#{red}|#{clear}b3#{red}|#{clear}
47
+ #{red}+--+--+--+#{clear}
48
+ EOS
49
+ end
50
+ end
51
+
52
+ context 'when unicode' do
53
+ let(:renderer) { :unicode }
54
+ let(:red) { "\e[31m" }
55
+ let(:clear) { "\e[0m" }
56
+
57
+ it "renders each row" do
58
+ table.border.style= :red
59
+ table.to_s.should == <<-EOS.normalize
60
+ #{red}┌──┬──┬──┐#{clear}
61
+ #{red}│#{clear}h1#{red}│#{clear}h2#{red}│#{clear}h3#{red}│#{clear}
62
+ #{red}├──┼──┼──┤#{clear}
63
+ #{red}│#{clear}a1#{red}│#{clear}a2#{red}│#{clear}a3#{red}│#{clear}
64
+ #{red}│#{clear}b1#{red}│#{clear}b2#{red}│#{clear}b3#{red}│#{clear}
65
+ #{red}└──┴──┴──┘#{clear}
66
+ EOS
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,107 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, '#border' do
6
+ let(:header) { ['h1', 'h2', 'h3'] }
7
+ let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
+ let(:border) { nil }
9
+
10
+ subject(:table) { described_class.new header, rows, :renderer => renderer, :border => border }
11
+
12
+ context 'when default' do
13
+ let(:renderer) { :basic }
14
+ let(:border) { { :characters => {'top' => '-'}, :style => :red } }
15
+
16
+ it 'specifies border at initialization' do
17
+ expect(table.border.style).to eql(:red)
18
+ end
19
+
20
+ it 'specifies border in hash' do
21
+ table.border border
22
+ expect(table.border.characters['top']).to eql('-')
23
+ end
24
+
25
+ it 'specifies border in characters attribute' do
26
+ table.border.characters = {'top' => '-'}
27
+ expect(table.border.characters['top']).to eql('-')
28
+ end
29
+
30
+ it 'specifies border in block' do
31
+ table.border do
32
+ mid '='
33
+ mid_mid ' '
34
+ end
35
+
36
+ table.to_s.should == <<-EOS.normalize
37
+ h1 h2 h3
38
+ == == ==
39
+ a1 a2 a3
40
+ b1 b2 b3
41
+ EOS
42
+ end
43
+ end
44
+
45
+ context 'when ascii' do
46
+ let(:renderer) { :ascii }
47
+
48
+ it 'specifies border in block' do
49
+ table.border do
50
+ mid '='
51
+ mid_mid '='
52
+ mid_left '='
53
+ mid_right '='
54
+ end
55
+
56
+ table.to_s.should == <<-EOS.normalize
57
+ +--+--+--+
58
+ |h1|h2|h3|
59
+ ==========
60
+ |a1|a2|a3|
61
+ |b1|b2|b3|
62
+ +--+--+--+
63
+ EOS
64
+ end
65
+
66
+ it 'specifies border as hash' do
67
+ table.border({ :characters => {
68
+ 'mid' => '=',
69
+ 'mid_mid' => '=',
70
+ 'mid_left' => '=',
71
+ 'mid_right' => '=',
72
+ }})
73
+
74
+ table.to_s.should == <<-EOS.normalize
75
+ +--+--+--+
76
+ |h1|h2|h3|
77
+ ==========
78
+ |a1|a2|a3|
79
+ |b1|b2|b3|
80
+ +--+--+--+
81
+ EOS
82
+ end
83
+ end
84
+
85
+ context 'when unicode' do
86
+ let(:renderer) { :unicode }
87
+
88
+ it 'specifies border in block' do
89
+ table.border do
90
+ mid '='
91
+ mid_mid '='
92
+ mid_left '='
93
+ mid_right '='
94
+ end
95
+
96
+ table.to_s.should == <<-EOS.normalize
97
+ ┌──┬──┬──┐
98
+ │h1│h2│h3│
99
+ ==========
100
+ │a1│a2│a3│
101
+ │b1│b2│b3│
102
+ └──┴──┴──┘
103
+ EOS
104
+ end
105
+ end
106
+
107
+ end # border
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, '#each_with_index' do
6
+ let(:object) { described_class.new header, rows }
7
+ let(:header) { ['Header1', 'Header2'] }
8
+ let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
9
+
10
+ context 'with no block' do
11
+ subject { object.each_with_index }
12
+ it { should be_instance_of(to_enum.class) }
13
+
14
+ it 'yields the expected values' do
15
+ subject.to_a.should eql(object.to_a)
16
+ end
17
+ end
18
+
19
+ context 'with block' do
20
+ subject { object.each_with_index { |el, row, col| yields << [el, row, col]}}
21
+ let(:yields) { [] }
22
+ let(:expected) { [['a1', 0, 0], ['a2', 0, 1], ['b1', 1, 0], ['b2', 1, 1]] }
23
+
24
+ it "" do
25
+ expect { subject }.to change { yields }.
26
+ from( [] ).
27
+ to( expected )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::Field, '#==' do
6
+ let(:value) { '1' }
7
+ let(:object) { described_class.new(value) }
8
+
9
+ subject { object == other }
10
+
11
+ context 'with the same object' do
12
+ let(:other) { object }
13
+
14
+ it { should be_true }
15
+
16
+ it 'is symmetric' do
17
+ should eql(other == object)
18
+ end
19
+ end
20
+
21
+ context 'with an equivalent object' do
22
+ let(:other) { object.dup }
23
+
24
+ it { should be_true }
25
+
26
+ it 'is symmetric' do
27
+ should eql(other == object)
28
+ end
29
+ end
30
+
31
+ context 'with an equivalent object of subclass' do
32
+ let(:other) { Class.new(described_class).new(value) }
33
+
34
+ it { should be_true }
35
+
36
+ it 'is symmetric' do
37
+ should eql(other == object)
38
+ end
39
+ end
40
+
41
+ context 'with an object having a different value' do
42
+ let(:other_value) { '2' }
43
+ let(:other) { described_class.new(other_value) }
44
+
45
+ it { should be_false }
46
+
47
+ it 'is symmetric' do
48
+ should eql(other == object)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::Field, '#new' do
6
+ let(:object) { described_class }
7
+
8
+ subject { object.new value }
9
+
10
+ context 'with only value' do
11
+ let(:value) { 'foo' }
12
+
13
+ it { should be_instance_of(object) }
14
+
15
+ its(:value) { should == value }
16
+
17
+ its(:height) { should == 1 }
18
+ end
19
+
20
+ context 'with hash value' do
21
+ let(:value) { { :value => 'foo' } }
22
+
23
+ it { should be_instance_of(object) }
24
+
25
+ its(:value) { should == 'foo' }
26
+
27
+ its(:height) { should == 1 }
28
+ end
29
+ end