tty 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module TargetSpec
4
+ class Object
5
+ def output; end
6
+ end
7
+ end
8
+
9
+ module DelegetableSpec
10
+ class Object
11
+ extend TTY::Delegatable
12
+
13
+ def test
14
+ TargetSpec::Object.new
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::System, '#platform' do
6
+ subject { described_class }
7
+
8
+ it { should respond_to(:windows?) }
9
+
10
+ it { should respond_to(:unix?) }
11
+
12
+ it 'checks if windows' do
13
+ RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'windows'
14
+ subject.windows?.should be_true
15
+ end
16
+
17
+ it 'checks if unix' do
18
+ RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'darwin'
19
+ subject.unix?.should be_true
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, 'access' do
6
+ let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
7
+ subject { TTY::Table.new :rows => rows }
8
+
9
+ it { should respond_to(:element) }
10
+
11
+ it { should respond_to(:component) }
12
+
13
+ its([0,0]) { should == 'a1'}
14
+
15
+ context '#row' do
16
+
17
+ it 'returns nil for wrong index' do
18
+ subject.row(11).should be_nil
19
+ end
20
+
21
+ it 'gets row at index' do
22
+ subject.row(1).should == rows[1]
23
+ end
24
+
25
+ it 'yields self for wrong index' do
26
+ block = lambda { |el| [] << el }
27
+ subject.row(11, &block).should eql subject
28
+ end
29
+
30
+ it 'yields row at index' do
31
+ yields = []
32
+ expect { subject.row(1).each { |el| yields << el } }.to change { yields }.
33
+ from( [] ).
34
+ to( rows[1] )
35
+ end
36
+ end
37
+
38
+ context '#column' do
39
+ it 'returns nil for wrong index' do
40
+ subject.column(11).should be_nil
41
+ end
42
+
43
+ it 'gets column at index' do
44
+ subject.column(0).should == ['a1', 'b1']
45
+ end
46
+
47
+ it 'yields self for wrong index' do
48
+ block = lambda { |el| [] << el }
49
+ subject.column(11, &block).should eql subject
50
+ end
51
+
52
+ it 'yields column at index' do
53
+ yields = []
54
+ expect { subject.column(1).each { |el| yields << el } }.to change { yields }.
55
+ from( [] ).
56
+ to( ['a2', 'b2'])
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, '#eql?' do
6
+ subject { object.eql?(other) }
7
+ let(:object) { described_class.new }
8
+
9
+ context 'with the same object' do
10
+ let(:other) { object }
11
+
12
+ it { should be_true }
13
+
14
+ it 'is symmetric' do
15
+ should eql(other.eql?(object))
16
+ end
17
+ end
18
+
19
+ context 'with an equivalent object' do
20
+ let(:other) { object.dup }
21
+
22
+ it { should be_true }
23
+
24
+ it 'is symmetric' do
25
+ should eql(other.eql?(object))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, '#initialize' do
6
+ let(:header) { ['Header1', 'Header2'] }
7
+ let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
8
+
9
+ it { should be_kind_of(Enumerable) }
10
+ it { should be_kind_of(Comparable) }
11
+
12
+ it { (Enumerable === subject).should be_true }
13
+
14
+ it 'initializes table header' do
15
+ table = TTY::Table.new header
16
+ table.header.should == header
17
+ end
18
+
19
+ it 'initializes table header as an option' do
20
+ table = TTY::Table.new :header => header
21
+ table.header.should == header
22
+ end
23
+
24
+ it 'initializes with rows as arguments' do
25
+ table = TTY::Table[['a1', 'a2'], ['b1', 'b2']]
26
+ table.to_a.should == rows
27
+ end
28
+
29
+ it 'initializes table rows as an option' do
30
+ table = TTY::Table.new :rows => rows
31
+ table.to_a.should == rows
32
+ end
33
+
34
+ it 'initializes table rows as an argument' do
35
+ table = TTY::Table.new header, rows
36
+ table.to_a.should == rows
37
+ end
38
+
39
+ it 'initializes table rows in a block with param' do
40
+ table = TTY::Table.new header do |t|
41
+ t << rows[0]
42
+ t << rows[1]
43
+ end
44
+ table.to_a.should == rows
45
+ end
46
+
47
+ it 'initializes table and adds rows' do
48
+ table = TTY::Table.new header
49
+ table << rows[0]
50
+ table << rows[1]
51
+ table.to_a.should == rows
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table, 'properties' do
6
+ let(:rows) {[['a1', 'a2', 'a3'], ['b1', 'b2', 'c3']] }
7
+ subject { described_class.new :rows => rows, :renderer => :basic }
8
+
9
+ its(:width) { should == 6 }
10
+
11
+ its(:row_size) { should == 2 }
12
+
13
+ its(:column_size) { should == 3 }
14
+
15
+ its(:size) { should == [2,3] }
16
+
17
+ context 'no size' do
18
+ let(:rows) { [] }
19
+
20
+ its(:row_size) { should == 0 }
21
+
22
+ its(:column_size) { should == 0 }
23
+ end
24
+ end
@@ -7,6 +7,17 @@ describe TTY::Table::Renderer::Basic do
7
7
  let(:header) { ['Header1', 'Header2'] }
8
8
  let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
9
9
 
10
+ subject { described_class.new }
11
+
12
+ it { should respond_to(:render) }
13
+
14
+ context '#extract_column_widths' do
15
+ it 'calculates column widths' do
16
+ rows = [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']]
17
+ subject.extract_column_widths(rows).should == [5,6]
18
+ end
19
+ end
20
+
10
21
  context '#render' do
11
22
  it 'displays table without styling' do
12
23
  table = TTY::Table.new header, :renderer => :basic
@@ -17,5 +28,14 @@ describe TTY::Table::Renderer::Basic do
17
28
  b1 b2 b3
18
29
  EOS
19
30
  end
31
+
32
+ it 'displays table according to widths' do
33
+ rows = [['aaa1', 'a2'], ['b1', 'bb1']]
34
+ table = TTY::Table.new header, rows, :renderer => :basic
35
+ table.to_s.should == <<-EOS.normalize
36
+ aaa1 a2
37
+ b1 bb1
38
+ EOS
39
+ end
20
40
  end
21
41
  end
@@ -15,6 +15,8 @@ describe TTY::Table, '#renderer' do
15
15
  TTY::Table.renderer = basic_renderer
16
16
  end
17
17
 
18
+ it { should respond_to(:render) }
19
+
18
20
  it 'sets basic renderer' do
19
21
  TTY::Table.renderer.should be TTY::Table::Renderer::Basic
20
22
  end
@@ -34,4 +36,9 @@ describe TTY::Table, '#renderer' do
34
36
  table = TTY::Table.new
35
37
  table.renderer.should be_kind_of(unicode_renderer)
36
38
  end
39
+
40
+ it 'delegates to renderer' do
41
+ table = TTY::Table.new
42
+ table.render( [['a']] ).should == 'a'
43
+ end
37
44
  end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Table::Validatable do
6
+ let(:described_class) { Class.new { include TTY::Table::Validatable } }
7
+ let(:rows) { [['a1', 'a2'], ['b1']] }
8
+ subject { described_class.new }
9
+
10
+ it 'raises no exception' do
11
+ rows[1] << ['b2']
12
+ expect { subject.assert_row_sizes(rows) }.not_to raise_error
13
+ end
14
+
15
+ it 'raises exception for mismatched rows' do
16
+ expect { subject.assert_row_sizes(rows) }.
17
+ to raise_error(TTY::Table::DimensionMismatchError)
18
+ end
19
+ end
@@ -0,0 +1,94 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TTY::Terminal, '#size' do
6
+ let(:default_width) { 80 }
7
+ let(:default_height) { 24 }
8
+
9
+ it { should be_instance_of(described_class) }
10
+
11
+ it { should respond_to(:width) }
12
+
13
+ it { should respond_to(:height) }
14
+
15
+ its(:default_width) { should == default_width }
16
+
17
+ its(:default_height) { should == default_height }
18
+
19
+ context '#width' do
20
+ it 'sets the env variable' do
21
+ ENV.stub(:[]).with('TTY_COLUMNS').and_return '100'
22
+ subject.width.should == 100
23
+ end
24
+
25
+ it 'is not unix system' do
26
+ TTY::System.stub(:unix?) { false }
27
+ subject.should_receive(:default_width)
28
+ subject.width
29
+ end
30
+
31
+ it 'is unix system' do
32
+ TTY::System.stub(:unix?) { true }
33
+ subject.should_receive(:dynamic_width)
34
+ subject.width
35
+ end
36
+
37
+ it 'cannot determine width' do
38
+ ENV.stub(:[]) { raise }
39
+ subject.should_receive(:default_width)
40
+ subject.width
41
+ end
42
+ end
43
+
44
+ context '#height' do
45
+ it 'sets the env variable' do
46
+ ENV.stub(:[]).with('TTY_LINES').and_return '50'
47
+ subject.height.should == 50
48
+ end
49
+
50
+ it 'is not unix system' do
51
+ TTY::System.stub(:unix?) { false }
52
+ subject.should_receive(:default_height)
53
+ subject.height
54
+ end
55
+
56
+ it 'is unix system' do
57
+ TTY::System.stub(:unix?) { true }
58
+ subject.should_receive(:dynamic_height)
59
+ subject.height
60
+ end
61
+
62
+ it 'cannot determine width' do
63
+ ENV.stub(:[]) { raise }
64
+ subject.should_receive(:default_height)
65
+ subject.height
66
+ end
67
+ end
68
+
69
+ context '#dynamic_width' do
70
+ it 'uses stty' do
71
+ subject.should_receive(:dynamic_width_stty) { 100 }
72
+ subject.dynamic_width
73
+ end
74
+
75
+ it 'uses tput' do
76
+ subject.stub(:dynamic_width_stty).and_return 0
77
+ subject.should_receive(:dynamic_width_tput) { 100 }
78
+ subject.dynamic_width
79
+ end
80
+ end
81
+
82
+ context '#dynamic_height' do
83
+ it 'uses stty' do
84
+ subject.should_receive(:dynamic_height_stty) { 100 }
85
+ subject.dynamic_height
86
+ end
87
+
88
+ it 'uses tput' do
89
+ subject.stub(:dynamic_height_stty).and_return 0
90
+ subject.should_receive(:dynamic_height_tput) { 100 }
91
+ subject.dynamic_height
92
+ end
93
+ end
94
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-30 00:00:00.000000000 Z
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2160191220 !ruby/object:Gem::Requirement
16
+ requirement: &2152405380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2160191220
24
+ version_requirements: *2152405380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2160190780 !ruby/object:Gem::Requirement
27
+ requirement: &2152404940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2160190780
35
+ version_requirements: *2152404940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &2160190360 !ruby/object:Gem::Requirement
38
+ requirement: &2152404520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160190360
46
+ version_requirements: *2152404520
47
47
  description: Toolbox for developing CLI clients
48
48
  email:
49
49
  - ''
@@ -62,20 +62,34 @@ files:
62
62
  - Rakefile
63
63
  - lib/tty.rb
64
64
  - lib/tty/color.rb
65
- - lib/tty/support/.utils.rb.swo
65
+ - lib/tty/support/conversion.rb
66
+ - lib/tty/support/delegatable.rb
66
67
  - lib/tty/support/utils.rb
68
+ - lib/tty/system.rb
67
69
  - lib/tty/table.rb
70
+ - lib/tty/table/error.rb
68
71
  - lib/tty/table/renderer.rb
69
72
  - lib/tty/table/renderer/basic.rb
70
73
  - lib/tty/table/renderer/color.rb
71
74
  - lib/tty/table/renderer/unicode.rb
75
+ - lib/tty/table/validatable.rb
76
+ - lib/tty/terminal.rb
72
77
  - lib/tty/version.rb
73
78
  - spec/spec_helper.rb
74
79
  - spec/tty/color_spec.rb
80
+ - spec/tty/support/conversion_spec.rb
81
+ - spec/tty/support/delegatable_spec.rb
82
+ - spec/tty/support/fixtures/classes.rb
83
+ - spec/tty/system/platform_spec.rb
84
+ - spec/tty/table/access_spec.rb
75
85
  - spec/tty/table/each_spec.rb
86
+ - spec/tty/table/eql_spec.rb
87
+ - spec/tty/table/initialize_spec.rb
88
+ - spec/tty/table/properties_spec.rb
76
89
  - spec/tty/table/renderer/basic_spec.rb
77
90
  - spec/tty/table/renderer_spec.rb
78
- - spec/tty/table/table_spec.rb
91
+ - spec/tty/table/validatable_spec.rb
92
+ - spec/tty/terminal/size_spec.rb
79
93
  - tty.gemspec
80
94
  homepage: http://github.com/peter-murach/tty
81
95
  licenses: []
@@ -104,8 +118,17 @@ summary: Toolbox for developing CLI clients
104
118
  test_files:
105
119
  - spec/spec_helper.rb
106
120
  - spec/tty/color_spec.rb
121
+ - spec/tty/support/conversion_spec.rb
122
+ - spec/tty/support/delegatable_spec.rb
123
+ - spec/tty/support/fixtures/classes.rb
124
+ - spec/tty/system/platform_spec.rb
125
+ - spec/tty/table/access_spec.rb
107
126
  - spec/tty/table/each_spec.rb
127
+ - spec/tty/table/eql_spec.rb
128
+ - spec/tty/table/initialize_spec.rb
129
+ - spec/tty/table/properties_spec.rb
108
130
  - spec/tty/table/renderer/basic_spec.rb
109
131
  - spec/tty/table/renderer_spec.rb
110
- - spec/tty/table/table_spec.rb
132
+ - spec/tty/table/validatable_spec.rb
133
+ - spec/tty/terminal/size_spec.rb
111
134
  has_rdoc: