tty 0.0.11 → 0.1.0

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.
Files changed (265) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +16 -7
  6. data/CHANGELOG.md +6 -0
  7. data/Gemfile +18 -1
  8. data/README.md +55 -28
  9. data/Rakefile +5 -9
  10. data/images/tty.png +0 -0
  11. data/lib/tty.rb +7 -1
  12. data/lib/tty/coercer/boolean.rb +6 -9
  13. data/lib/tty/coercer/float.rb +14 -17
  14. data/lib/tty/coercer/integer.rb +14 -17
  15. data/lib/tty/coercer/range.rb +6 -7
  16. data/lib/tty/logger.rb +23 -9
  17. data/lib/tty/plugins.rb +3 -6
  18. data/lib/tty/plugins/plugin.rb +4 -7
  19. data/lib/tty/shell.rb +20 -12
  20. data/lib/tty/shell/question.rb +41 -48
  21. data/lib/tty/shell/question/modifier.rb +5 -8
  22. data/lib/tty/shell/question/validation.rb +8 -7
  23. data/lib/tty/shell/reader.rb +28 -19
  24. data/lib/tty/shell/response.rb +26 -22
  25. data/lib/tty/shell/statement.rb +13 -9
  26. data/lib/tty/shell/suggestion.rb +17 -13
  27. data/lib/tty/support/coercion.rb +5 -6
  28. data/lib/tty/support/conversion.rb +7 -6
  29. data/lib/tty/support/delegatable.rb +5 -5
  30. data/lib/tty/support/unicode.rb +3 -4
  31. data/lib/tty/support/utils.rb +1 -2
  32. data/lib/tty/system.rb +13 -6
  33. data/lib/tty/system/editor.rb +21 -18
  34. data/lib/tty/system/which.rb +3 -5
  35. data/lib/tty/table.rb +18 -22
  36. data/lib/tty/table/border.rb +2 -4
  37. data/lib/tty/table/border/ascii.rb +3 -2
  38. data/lib/tty/table/border/null.rb +1 -3
  39. data/lib/tty/table/border/row_line.rb +1 -4
  40. data/lib/tty/table/border/unicode.rb +3 -2
  41. data/lib/tty/table/border_dsl.rb +21 -17
  42. data/lib/tty/table/border_options.rb +6 -5
  43. data/lib/tty/table/column_set.rb +11 -7
  44. data/lib/tty/table/columns.rb +19 -16
  45. data/lib/tty/table/error.rb +1 -3
  46. data/lib/tty/table/field.rb +30 -12
  47. data/lib/tty/table/header.rb +18 -9
  48. data/lib/tty/table/indentation.rb +1 -3
  49. data/lib/tty/table/operation/alignment.rb +8 -9
  50. data/lib/tty/table/operation/alignment_set.rb +6 -5
  51. data/lib/tty/table/operation/escape.rb +3 -3
  52. data/lib/tty/table/operation/filter.rb +3 -4
  53. data/lib/tty/table/operation/truncation.rb +3 -3
  54. data/lib/tty/table/operation/wrapped.rb +3 -4
  55. data/lib/tty/table/operations.rb +19 -22
  56. data/lib/tty/table/orientation.rb +5 -5
  57. data/lib/tty/table/orientation/horizontal.rb +9 -6
  58. data/lib/tty/table/orientation/vertical.rb +10 -7
  59. data/lib/tty/table/padder.rb +46 -8
  60. data/lib/tty/table/renderer.rb +21 -14
  61. data/lib/tty/table/renderer/ascii.rb +6 -5
  62. data/lib/tty/table/renderer/basic.rb +18 -19
  63. data/lib/tty/table/renderer/unicode.rb +11 -5
  64. data/lib/tty/table/row.rb +36 -20
  65. data/lib/tty/table/transformation.rb +6 -5
  66. data/lib/tty/table/validatable.rb +32 -17
  67. data/lib/tty/terminal.rb +26 -42
  68. data/lib/tty/terminal/color.rb +10 -12
  69. data/lib/tty/terminal/echo.rb +4 -7
  70. data/lib/tty/terminal/home.rb +3 -10
  71. data/lib/tty/terminal/pager.rb +11 -10
  72. data/lib/tty/terminal/pager/basic.rb +3 -6
  73. data/lib/tty/terminal/pager/system.rb +2 -5
  74. data/lib/tty/text.rb +7 -10
  75. data/lib/tty/text/distance.rb +2 -4
  76. data/lib/tty/text/truncation.rb +1 -3
  77. data/lib/tty/text/wrapping.rb +1 -3
  78. data/lib/tty/vector.rb +3 -5
  79. data/lib/tty/version.rb +2 -2
  80. data/spec/spec_helper.rb +4 -11
  81. data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
  82. data/spec/tty/coercer/float/coerce_spec.rb +6 -4
  83. data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
  84. data/spec/tty/coercer/range/coerce_spec.rb +12 -11
  85. data/spec/tty/logger/log_spec.rb +23 -0
  86. data/spec/tty/logger/new_spec.rb +14 -14
  87. data/spec/tty/logger/valid_level_spec.rb +6 -6
  88. data/spec/tty/plugins/find_spec.rb +4 -4
  89. data/spec/tty/plugins/load_spec.rb +4 -5
  90. data/spec/tty/plugins/plugin/load_spec.rb +10 -8
  91. data/spec/tty/plugins/plugin/new_spec.rb +7 -7
  92. data/spec/tty/shell/ask_spec.rb +6 -7
  93. data/spec/tty/shell/error_spec.rb +1 -2
  94. data/spec/tty/shell/print_table_spec.rb +1 -2
  95. data/spec/tty/shell/question/argument_spec.rb +1 -1
  96. data/spec/tty/shell/question/character_spec.rb +11 -3
  97. data/spec/tty/shell/question/default_spec.rb +3 -3
  98. data/spec/tty/shell/question/in_spec.rb +1 -1
  99. data/spec/tty/shell/question/initialize_spec.rb +8 -11
  100. data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
  101. data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
  102. data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
  103. data/spec/tty/shell/question/modify_spec.rb +1 -1
  104. data/spec/tty/shell/question/valid_spec.rb +4 -4
  105. data/spec/tty/shell/question/validate_spec.rb +4 -4
  106. data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
  107. data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
  108. data/spec/tty/shell/reader/getc_spec.rb +16 -14
  109. data/spec/tty/shell/response/read_bool_spec.rb +1 -1
  110. data/spec/tty/shell/response/read_char_spec.rb +1 -2
  111. data/spec/tty/shell/response/read_date_spec.rb +1 -1
  112. data/spec/tty/shell/response/read_email_spec.rb +1 -1
  113. data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
  114. data/spec/tty/shell/response/read_number_spec.rb +1 -2
  115. data/spec/tty/shell/response/read_range_spec.rb +2 -2
  116. data/spec/tty/shell/response/read_spec.rb +7 -7
  117. data/spec/tty/shell/response/read_string_spec.rb +2 -2
  118. data/spec/tty/shell/say_spec.rb +1 -1
  119. data/spec/tty/shell/statement/initialize_spec.rb +3 -3
  120. data/spec/tty/shell/suggest_spec.rb +1 -1
  121. data/spec/tty/shell/warn_spec.rb +1 -2
  122. data/spec/tty/support/coercion_spec.rb +10 -10
  123. data/spec/tty/support/conversion_spec.rb +9 -9
  124. data/spec/tty/support/delegatable_spec.rb +7 -5
  125. data/spec/tty/support/equatable_spec.rb +32 -34
  126. data/spec/tty/support/fixtures/classes.rb +4 -2
  127. data/spec/tty/system/editor/available_spec.rb +12 -12
  128. data/spec/tty/system/editor/build_spec.rb +8 -16
  129. data/spec/tty/system/editor/command_spec.rb +3 -2
  130. data/spec/tty/system/editor/executables_spec.rb +3 -3
  131. data/spec/tty/system/editor/invoke_spec.rb +10 -14
  132. data/spec/tty/system/editor/open_spec.rb +9 -7
  133. data/spec/tty/system/platform_spec.rb +32 -13
  134. data/spec/tty/system/which/which_spec.rb +9 -9
  135. data/spec/tty/system/which_spec.rb +4 -4
  136. data/spec/tty/table/access_spec.rb +24 -21
  137. data/spec/tty/table/add_row_spec.rb +2 -2
  138. data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
  139. data/spec/tty/table/border/new_spec.rb +5 -4
  140. data/spec/tty/table/border/null/rendering_spec.rb +12 -12
  141. data/spec/tty/table/border/options/from_spec.rb +2 -3
  142. data/spec/tty/table/border/options/new_spec.rb +4 -5
  143. data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
  144. data/spec/tty/table/border_options/new_spec.rb +20 -0
  145. data/spec/tty/table/border_options/update_spec.rb +18 -0
  146. data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
  147. data/spec/tty/table/column_set/total_width_spec.rb +2 -2
  148. data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
  149. data/spec/tty/table/columns/enforce_spec.rb +2 -2
  150. data/spec/tty/table/columns/widths_spec.rb +2 -0
  151. data/spec/tty/table/data_spec.rb +3 -3
  152. data/spec/tty/table/each_spec.rb +9 -11
  153. data/spec/tty/table/each_with_index_spec.rb +8 -9
  154. data/spec/tty/table/empty_spec.rb +3 -3
  155. data/spec/tty/table/eql_spec.rb +6 -6
  156. data/spec/tty/table/field/equality_spec.rb +11 -11
  157. data/spec/tty/table/field/length_spec.rb +4 -4
  158. data/spec/tty/table/field/lines_spec.rb +3 -3
  159. data/spec/tty/table/field/new_spec.rb +7 -7
  160. data/spec/tty/table/field/width_spec.rb +6 -4
  161. data/spec/tty/table/filter_spec.rb +3 -3
  162. data/spec/tty/table/header/call_spec.rb +3 -3
  163. data/spec/tty/table/header/height_spec.rb +1 -1
  164. data/spec/tty/table/header/new_spec.rb +5 -5
  165. data/spec/tty/table/header/set_spec.rb +9 -4
  166. data/spec/tty/table/header/to_ary_spec.rb +4 -4
  167. data/spec/tty/table/header_spec.rb +3 -4
  168. data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
  169. data/spec/tty/table/initialize_spec.rb +13 -13
  170. data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
  171. data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
  172. data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
  173. data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
  174. data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
  175. data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
  176. data/spec/tty/table/operation/escape/call_spec.rb +1 -1
  177. data/spec/tty/table/operation/filter/call_spec.rb +1 -1
  178. data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
  179. data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
  180. data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
  181. data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
  182. data/spec/tty/table/operations/new_spec.rb +1 -1
  183. data/spec/tty/table/options_spec.rb +8 -8
  184. data/spec/tty/table/orientation_spec.rb +15 -13
  185. data/spec/tty/table/padder/parse_spec.rb +1 -1
  186. data/spec/tty/table/padder/to_s_spec.rb +14 -0
  187. data/spec/tty/table/padding_spec.rb +1 -1
  188. data/spec/tty/table/properties_spec.rb +9 -8
  189. data/spec/tty/table/render_spec.rb +8 -5
  190. data/spec/tty/table/render_with_spec.rb +5 -4
  191. data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
  192. data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
  193. data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
  194. data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
  195. data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
  196. data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
  197. data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
  198. data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
  199. data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
  200. data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
  201. data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
  202. data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
  203. data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
  204. data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
  205. data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
  206. data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
  207. data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
  208. data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
  209. data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
  210. data/spec/tty/table/renderer/border_spec.rb +21 -21
  211. data/spec/tty/table/renderer/render_spec.rb +7 -7
  212. data/spec/tty/table/renderer/select_spec.rb +4 -4
  213. data/spec/tty/table/renderer/style_spec.rb +19 -19
  214. data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
  215. data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
  216. data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
  217. data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
  218. data/spec/tty/table/renderer_spec.rb +1 -1
  219. data/spec/tty/table/rotate_spec.rb +27 -27
  220. data/spec/tty/table/row/access_spec.rb +3 -3
  221. data/spec/tty/table/row/call_spec.rb +4 -4
  222. data/spec/tty/table/row/data_spec.rb +5 -5
  223. data/spec/tty/table/row/each_spec.rb +1 -1
  224. data/spec/tty/table/row/equality_spec.rb +16 -16
  225. data/spec/tty/table/row/height_spec.rb +1 -1
  226. data/spec/tty/table/row/new_spec.rb +11 -11
  227. data/spec/tty/table/row/to_ary_spec.rb +3 -3
  228. data/spec/tty/table/to_s_spec.rb +8 -8
  229. data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
  230. data/spec/tty/table/validatable_spec.rb +14 -1
  231. data/spec/tty/terminal/color/code_spec.rb +3 -3
  232. data/spec/tty/terminal/color/remove_spec.rb +8 -9
  233. data/spec/tty/terminal/color/set_spec.rb +5 -6
  234. data/spec/tty/terminal/color_spec.rb +3 -5
  235. data/spec/tty/terminal/echo_spec.rb +3 -4
  236. data/spec/tty/terminal/home_spec.rb +12 -14
  237. data/spec/tty/terminal/page_spec.rb +5 -4
  238. data/spec/tty/terminal/pager/available_spec.rb +11 -11
  239. data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
  240. data/spec/tty/terminal/pager/command_spec.rb +2 -2
  241. data/spec/tty/terminal/pager/executables_spec.rb +3 -3
  242. data/spec/tty/terminal/pager/page_spec.rb +8 -10
  243. data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
  244. data/spec/tty/terminal/size_spec.rb +39 -36
  245. data/spec/tty/text/distance/distance_spec.rb +13 -13
  246. data/spec/tty/text/distance/initialize_spec.rb +4 -4
  247. data/spec/tty/text/distance_spec.rb +2 -2
  248. data/spec/tty/text/truncate_spec.rb +2 -3
  249. data/spec/tty/text/truncation/initialize_spec.rb +9 -9
  250. data/spec/tty/text/truncation/truncate_spec.rb +14 -14
  251. data/spec/tty/text/wrap_spec.rb +2 -3
  252. data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
  253. data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
  254. data/spec/tty/tty_spec.rb +22 -0
  255. data/spec/tty/vector/new_spec.rb +7 -7
  256. data/tasks/console.rake +10 -0
  257. data/tasks/coverage.rake +11 -0
  258. data/tasks/metrics/cane.rake +2 -0
  259. data/tasks/metrics/flog.rake +2 -0
  260. data/tasks/metrics/heckle.rake +15 -0
  261. data/tasks/metrics/reek.rake +2 -0
  262. data/tasks/spec.rake +29 -0
  263. data/tty.gemspec +5 -12
  264. metadata +34 -91
  265. data/.rvmrc +0 -34
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,19 +1,19 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
5
  describe TTY::Table::Renderer::Basic, '#render' do
6
6
  let(:header) { ['h1', 'h2', 'h3'] }
7
- let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
- let(:table) { TTY::Table.new header, rows }
7
+ let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
+ let(:table) { TTY::Table.new header, rows }
9
9
 
10
- subject { described_class.new(table) }
10
+ subject(:renderer) { described_class.new(table) }
11
11
 
12
12
  context 'with rows' do
13
13
  let(:table) { TTY::Table.new rows }
14
14
 
15
15
  it 'displays table without styling' do
16
- subject.render.should == <<-EOS.normalize
16
+ expect(renderer.render).to eq <<-EOS.normalize
17
17
  a1 a2 a3
18
18
  b1 b2 b3
19
19
  EOS
@@ -22,7 +22,7 @@ describe TTY::Table::Renderer::Basic, '#render' do
22
22
 
23
23
  context 'with header and rows' do
24
24
  it 'displays table with header' do
25
- subject.render.should == <<-EOS.normalize
25
+ expect(renderer.render).to eq <<-EOS.normalize
26
26
  h1 h2 h3
27
27
  a1 a2 a3
28
28
  b1 b2 b3
@@ -35,7 +35,7 @@ describe TTY::Table::Renderer::Basic, '#render' do
35
35
  let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
36
36
 
37
37
  it 'displays table according to widths' do
38
- subject.render.should == <<-EOS.normalize
38
+ expect(renderer.render).to eq <<-EOS.normalize
39
39
  h1 h2
40
40
  aaa1 a2
41
41
  b1 bb1
@@ -47,7 +47,7 @@ describe TTY::Table::Renderer::Basic, '#render' do
47
47
  let(:header) { ['header1', 'header2', 'header3'] }
48
48
 
49
49
  it 'header greater than row sizes' do
50
- subject.render.should == <<-EOS.normalize
50
+ expect(renderer.render).to eq <<-EOS.normalize
51
51
  header1 header2 header3
52
52
  a1 a2 a3
53
53
  b1 b2 b3
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -31,7 +31,7 @@ describe TTY::Table::Renderer::Basic, 'with separator' do
31
31
 
32
32
  it "renders each row" do
33
33
  renderer.border.separator= :each_row
34
- renderer.render.should == <<-EOS.normalize
34
+ expect(renderer.render).to eq <<-EOS.normalize
35
35
  h1 h2 h3
36
36
 
37
37
  a1 a2 a3
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -7,13 +7,13 @@ describe TTY::Table::Renderer::Basic, 'truncation' do
7
7
  let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
8
8
  let(:table) { TTY::Table.new header, rows }
9
9
 
10
- subject { described_class.new(table, options) }
10
+ subject(:renderer) { described_class.new(table, options) }
11
11
 
12
12
  context 'without column widths' do
13
13
  let(:options) { {} }
14
14
 
15
15
  it "doesn't shorten the fields" do
16
- subject.render.should == <<-EOS.normalize
16
+ expect(renderer.render).to eq <<-EOS.normalize
17
17
  header1 head2 h3
18
18
  a1111111 a222 a3333333
19
19
  b111 b2222222 b333333
@@ -25,7 +25,7 @@ describe TTY::Table::Renderer::Basic, 'truncation' do
25
25
  let(:options) { { column_widths: [3, 5, 7] } }
26
26
 
27
27
  it 'shortens the fields' do
28
- subject.render.should == <<-EOS.normalize
28
+ expect(renderer.render).to eq <<-EOS.normalize
29
29
  he… head2 h3
30
30
  a1… a222 a33333…
31
31
  b1… b222… b333333
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -7,13 +7,13 @@ describe TTY::Table::Renderer::Basic, 'wrapping' do
7
7
  let(:rows) { [['a1111111', 'a222', 'a3333333'], ['b111', 'b2222222', 'b333333']]}
8
8
  let(:table) { TTY::Table.new header, rows }
9
9
 
10
- subject { described_class.new(table, options) }
10
+ subject(:renderer) { described_class.new(table, options) }
11
11
 
12
12
  context 'without column widths' do
13
13
  let(:options) { {multiline: true} }
14
14
 
15
15
  it 'doesn\'t wrap the fields' do
16
- subject.render.should == <<-EOS.normalize
16
+ expect(renderer.render).to eq <<-EOS.normalize
17
17
  header1 head2 h3
18
18
  a1111111 a222 a3333333
19
19
  b111 b2222222 b333333
@@ -25,7 +25,7 @@ describe TTY::Table::Renderer::Basic, 'wrapping' do
25
25
  let(:options) { { column_widths: [3, 5, 7], multiline: true} }
26
26
 
27
27
  it 'wraps the fields' do
28
- subject.render.should == <<-EOS.normalize
28
+ expect(renderer.render).to eq <<-EOS.normalize
29
29
  hea head2 h3
30
30
  der
31
31
  1
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -9,29 +9,29 @@ describe TTY::Table::Renderer, '#border' do
9
9
 
10
10
  let(:table) { TTY::Table.new(header, rows) }
11
11
 
12
- subject { described_class.select(renderer).new(table) }
12
+ subject(:renderer) { described_class.select(type).new(table) }
13
13
 
14
- context 'when default' do
15
- let(:renderer) { :basic }
16
- let(:border) { { :characters => {'top' => '-'}, :style => :red } }
14
+ context 'when basic renderer' do
15
+ let(:type) { :basic }
16
+ let(:border) { {characters: {'top' => '-'}, style: :red} }
17
17
 
18
18
  it 'specifies border in hash' do
19
- subject.border border
20
- expect(subject.border.characters['top']).to eql('-')
19
+ renderer.border(border)
20
+ expect(renderer.border.characters['top']).to eql('-')
21
21
  end
22
22
 
23
23
  it 'specifies border in characters attribute' do
24
- subject.border.characters = {'top' => '*'}
25
- expect(subject.border.characters['top']).to eql('*')
24
+ renderer.border.characters = {'top' => '*'}
25
+ expect(renderer.border.characters['top']).to eql('*')
26
26
  end
27
27
 
28
28
  it 'specifies border in block' do
29
- subject.border do
29
+ renderer.border do
30
30
  mid '='
31
31
  mid_mid ' '
32
32
  end
33
33
 
34
- subject.render.should == <<-EOS.normalize
34
+ expect(renderer.render).to eq <<-EOS.normalize
35
35
  h1 h2 h3
36
36
  == == ==
37
37
  a1 a2 a3
@@ -40,18 +40,18 @@ describe TTY::Table::Renderer, '#border' do
40
40
  end
41
41
  end
42
42
 
43
- context 'when ascii' do
44
- let(:renderer) { :ascii }
43
+ context 'when ascii renderer' do
44
+ let(:type) { :ascii }
45
45
 
46
46
  it 'specifies border in block' do
47
- subject.border do
47
+ renderer.border do
48
48
  mid '='
49
49
  mid_mid '='
50
50
  mid_left '='
51
51
  mid_right '='
52
52
  end
53
53
 
54
- subject.render.should == <<-EOS.normalize
54
+ expect(renderer.render).to eq <<-EOS.normalize
55
55
  +--+--+--+
56
56
  |h1|h2|h3|
57
57
  ==========
@@ -62,14 +62,14 @@ describe TTY::Table::Renderer, '#border' do
62
62
  end
63
63
 
64
64
  it 'specifies border as hash' do
65
- subject.border({ :characters => {
65
+ renderer.border({characters: {
66
66
  'mid' => '=',
67
67
  'mid_mid' => '=',
68
68
  'mid_left' => '=',
69
69
  'mid_right' => '=',
70
70
  }})
71
71
 
72
- subject.render.should == <<-EOS.normalize
72
+ expect(renderer.render).to eq <<-EOS.normalize
73
73
  +--+--+--+
74
74
  |h1|h2|h3|
75
75
  ==========
@@ -80,18 +80,18 @@ describe TTY::Table::Renderer, '#border' do
80
80
  end
81
81
  end
82
82
 
83
- context 'when unicode' do
84
- let(:renderer) { :unicode }
83
+ context 'when unicode renderer' do
84
+ let(:type) { :unicode }
85
85
 
86
86
  it 'specifies border in block' do
87
- subject.border do
87
+ renderer.border do
88
88
  mid '='
89
89
  mid_mid '='
90
90
  mid_left '='
91
91
  mid_right '='
92
92
  end
93
93
 
94
- subject.render.should == <<-EOS.normalize
94
+ expect(renderer.render).to eq <<-EOS.normalize
95
95
  ┌──┬──┬──┐
96
96
  │h1│h2│h3│
97
97
  ==========
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -11,26 +11,26 @@ describe TTY::Table::Renderer, '#render' do
11
11
 
12
12
  context 'when default' do
13
13
  let(:renderer) { double(:renderer).as_null_object }
14
- let(:renderer_class) { double(:renderer_class) }
14
+ let(:renderer_class) { double(:renderer_class).as_null_object }
15
15
  let(:yielded) { [] }
16
16
  let(:block) { proc { |render| yielded << render } }
17
17
 
18
- before { described_class.stub(:select).and_return(renderer_class) }
18
+ before { allow(described_class).to receive(:select).and_return(renderer_class) }
19
19
 
20
20
  it 'creates renderer' do
21
- expect(renderer_class).to receive(:new).with(table, {}).and_return(renderer)
22
21
  subject
22
+ expect(renderer_class).to have_received(:new).with(table, {})
23
23
  end
24
24
 
25
25
  it 'yields renderer' do
26
- renderer_class.stub(:new).and_return(renderer)
26
+ allow(renderer_class).to receive(:new).and_return(renderer)
27
27
  expect { subject }.to change { yielded}.from([]).to([renderer])
28
28
  end
29
29
 
30
30
  it 'calls render' do
31
- renderer_class.stub(:new).and_return(renderer)
32
- expect(renderer).to receive(:render)
31
+ allow(renderer_class).to receive(:new).and_return(renderer)
33
32
  subject
33
+ expect(renderer).to have_received(:render)
34
34
  end
35
35
  end
36
36
  end
@@ -1,9 +1,9 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
5
  describe TTY::Table::Renderer, '#select' do
6
- let(:klass) { ::Class.new }
6
+ let(:klass) { ::Class.new }
7
7
  let(:instance) { described_class }
8
8
 
9
9
  subject { instance.select(renderer) }
@@ -11,12 +11,12 @@ describe TTY::Table::Renderer, '#select' do
11
11
  context 'with basic' do
12
12
  let(:renderer) { :basic }
13
13
 
14
- it { should be(TTY::Table::Renderer::Basic) }
14
+ it { is_expected.to be(TTY::Table::Renderer::Basic) }
15
15
  end
16
16
 
17
17
  context 'with unicode' do
18
18
  let(:renderer) { :unicode }
19
19
 
20
- it { should be(TTY::Table::Renderer::Unicode) }
20
+ it { is_expected.to be(TTY::Table::Renderer::Unicode) }
21
21
  end
22
22
  end
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -7,23 +7,23 @@ describe TTY::Table::Renderer, 'with style' do
7
7
  let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
8
  let(:table) { TTY::Table.new(header, rows) }
9
9
 
10
- subject { described_class.select(renderer).new(table) }
10
+ subject(:renderer) { described_class.select(type).new(table) }
11
11
 
12
- context 'when default' do
13
- let(:renderer) { :basic }
12
+ context 'when basic renderer' do
13
+ let(:type) { :basic }
14
14
 
15
15
  it "sets through hash" do
16
- subject.border style: :red
17
- expect(subject.border.style).to eql(:red)
16
+ renderer.border(style: :red)
17
+ expect(renderer.border.style).to eql(:red)
18
18
  end
19
19
 
20
20
  it "sets through attribute" do
21
- subject.border.style = :red
22
- expect(subject.border.style).to eql :red
21
+ renderer.border.style = :red
22
+ expect(renderer.border.style).to eql :red
23
23
  end
24
24
 
25
25
  it "renders without color" do
26
- subject.render.should == <<-EOS.normalize
26
+ expect(renderer.render).to eq <<-EOS.normalize
27
27
  h1 h2 h3
28
28
  a1 a2 a3
29
29
  b1 b2 b3
@@ -31,14 +31,14 @@ describe TTY::Table::Renderer, 'with style' do
31
31
  end
32
32
  end
33
33
 
34
- context 'when ascii' do
35
- let(:renderer) { :ascii }
36
- let(:red) { "\e[31m" }
34
+ context 'when ascii renderer' do
35
+ let(:type) { :ascii }
36
+ let(:red) { "\e[31m" }
37
37
  let(:clear) { "\e[0m" }
38
38
 
39
39
  it "renders border in color" do
40
- subject.border.style= :red
41
- subject.render.should == <<-EOS.normalize
40
+ renderer.border.style= :red
41
+ expect(renderer.render).to eq <<-EOS.normalize
42
42
  #{red}+--+--+--+#{clear}
43
43
  #{red}|#{clear}h1#{red}|#{clear}h2#{red}|#{clear}h3#{red}|#{clear}
44
44
  #{red}+--+--+--+#{clear}
@@ -49,14 +49,14 @@ describe TTY::Table::Renderer, 'with style' do
49
49
  end
50
50
  end
51
51
 
52
- context 'when unicode' do
53
- let(:renderer) { :unicode }
54
- let(:red) { "\e[31m" }
52
+ context 'when unicode renderer' do
53
+ let(:type) { :unicode }
54
+ let(:red) { "\e[31m" }
55
55
  let(:clear) { "\e[0m" }
56
56
 
57
57
  it "renders each row" do
58
- subject.border.style= :red
59
- subject.render.should == <<-EOS.normalize
58
+ renderer.border.style= :red
59
+ expect(renderer.render).to eq <<-EOS.normalize
60
60
  #{red}┌──┬──┬──┐#{clear}
61
61
  #{red}│#{clear}h1#{red}│#{clear}h2#{red}│#{clear}h3#{red}│#{clear}
62
62
  #{red}├──┼──┼──┤#{clear}
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -7,13 +7,13 @@ describe TTY::Table::Renderer::Unicode, '#render' do
7
7
  let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
8
8
  let(:table) { TTY::Table.new header, rows }
9
9
 
10
- subject { described_class.new(table) }
10
+ subject(:renderer) { described_class.new(table) }
11
11
 
12
12
  context 'with rows only' do
13
13
  let(:table) { TTY::Table.new rows }
14
14
 
15
15
  it 'display table rows' do
16
- subject.render.should == <<-EOS.normalize
16
+ expect(renderer.render).to eq <<-EOS.normalize
17
17
  ┌──┬──┬──┐
18
18
  │a1│a2│a3│
19
19
  │b1│b2│b3│
@@ -24,7 +24,7 @@ describe TTY::Table::Renderer::Unicode, '#render' do
24
24
 
25
25
  context 'with header' do
26
26
  it 'displays table with header' do
27
- subject.render.should == <<-EOS.normalize
27
+ expect(renderer.render).to eq <<-EOS.normalize
28
28
  ┌──┬──┬──┐
29
29
  │h1│h2│h3│
30
30
  ├──┼──┼──┤
@@ -40,7 +40,7 @@ describe TTY::Table::Renderer::Unicode, '#render' do
40
40
  let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
41
41
 
42
42
  it 'displays table according to widths' do
43
- subject.render.should == <<-EOS.normalize
43
+ expect(renderer.render).to eq <<-EOS.normalize
44
44
  ┌────┬───┐
45
45
  │h1 │h2 │
46
46
  ├────┼───┤
@@ -55,7 +55,7 @@ describe TTY::Table::Renderer::Unicode, '#render' do
55
55
  let(:header) { ['header1', 'header2', 'header3'] }
56
56
 
57
57
  it 'header greater than row sizes' do
58
- subject.render.to_s.should == <<-EOS.normalize
58
+ expect(renderer.render).to eq <<-EOS.normalize
59
59
  ┌───────┬───────┬───────┐
60
60
  │header1│header2│header3│
61
61
  ├───────┼───────┼───────┤