vedeu 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/.travis.yml +2 -1
  4. data/Guardfile +6 -5
  5. data/README.md +3 -30
  6. data/Rakefile +5 -5
  7. data/bin/vedeu_drb_client +1 -1
  8. data/bin/vedeu_drb_server +91 -89
  9. data/bin/vedeu_test +4 -0
  10. data/config/rubocop_enabled.yml +5 -10
  11. data/examples/borders_app.rb +2 -1
  12. data/examples/colours_app.rb +13 -8
  13. data/examples/configuration_app.rb +3 -2
  14. data/examples/cursor_app.rb +16 -11
  15. data/examples/drb_app.rb +88 -89
  16. data/examples/focus_app.rb +31 -32
  17. data/examples/geometry_app.rb +2 -1
  18. data/examples/hello_world.rb +2 -1
  19. data/examples/lines_app.rb +2 -1
  20. data/examples/material_colours_app.rb +126 -0
  21. data/examples/typed_commands/typed_commands_app.rb +5 -1
  22. data/examples/view_templates_app/view_templates_app.rb +6 -3
  23. data/lib/vedeu/all.rb +1 -1
  24. data/lib/vedeu/api.rb +18 -10
  25. data/lib/vedeu/application.rb +0 -1
  26. data/lib/vedeu/bindings.rb +77 -16
  27. data/lib/vedeu/buffers/all.rb +2 -5
  28. data/lib/vedeu/buffers/buffer.rb +69 -25
  29. data/lib/vedeu/buffers/display_buffer.rb +3 -7
  30. data/lib/vedeu/configuration/all.rb +3 -6
  31. data/lib/vedeu/configuration/api.rb +28 -4
  32. data/lib/vedeu/configuration/cli.rb +9 -9
  33. data/lib/vedeu/configuration/configuration.rb +11 -7
  34. data/lib/vedeu/cursor/all.rb +3 -6
  35. data/lib/vedeu/cursor/cursor.rb +22 -14
  36. data/lib/vedeu/cursor/move.rb +32 -22
  37. data/lib/vedeu/cursor/refresh_cursor.rb +1 -1
  38. data/lib/vedeu/debug.rb +2 -1
  39. data/lib/vedeu/distributed/client.rb +1 -7
  40. data/lib/vedeu/distributed/server.rb +0 -4
  41. data/lib/vedeu/distributed/subprocess.rb +1 -1
  42. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -1
  43. data/lib/vedeu/distributed/test_application.rb +3 -5
  44. data/lib/vedeu/distributed/uri.rb +2 -2
  45. data/lib/vedeu/dsl/all.rb +6 -6
  46. data/lib/vedeu/dsl/components/all.rb +0 -3
  47. data/lib/vedeu/dsl/components/border.rb +20 -12
  48. data/lib/vedeu/dsl/components/geometry.rb +68 -3
  49. data/lib/vedeu/dsl/components/keymap.rb +1 -2
  50. data/lib/vedeu/dsl/composition.rb +8 -1
  51. data/lib/vedeu/dsl/interface.rb +61 -11
  52. data/lib/vedeu/dsl/line.rb +12 -12
  53. data/lib/vedeu/dsl/shared/all.rb +4 -7
  54. data/lib/vedeu/dsl/shared/colour.rb +2 -2
  55. data/lib/vedeu/dsl/shared/text.rb +2 -35
  56. data/lib/vedeu/dsl/shared/use.rb +2 -2
  57. data/lib/vedeu/dsl/view.rb +4 -4
  58. data/lib/vedeu/events/all.rb +3 -5
  59. data/lib/vedeu/events/event.rb +5 -5
  60. data/lib/vedeu/geometry/all.rb +11 -16
  61. data/lib/vedeu/geometry/area.rb +2 -5
  62. data/lib/vedeu/geometry/canvas.rb +12 -16
  63. data/lib/vedeu/geometry/dimension.rb +20 -22
  64. data/lib/vedeu/geometry/geometry.rb +28 -30
  65. data/lib/vedeu/geometry/grid.rb +1 -1
  66. data/lib/vedeu/geometry/index_position.rb +7 -0
  67. data/lib/vedeu/geometry/null_geometry.rb +61 -0
  68. data/lib/vedeu/geometry/position.rb +0 -3
  69. data/lib/vedeu/geometry/position_index.rb +7 -0
  70. data/lib/vedeu/geometry/position_validator.rb +44 -33
  71. data/lib/vedeu/input/all.rb +5 -4
  72. data/lib/vedeu/input/keymap.rb +0 -1
  73. data/lib/vedeu/input/mapper.rb +1 -3
  74. data/lib/vedeu/launcher.rb +6 -7
  75. data/lib/vedeu/main_loop.rb +1 -2
  76. data/lib/vedeu/models/all.rb +1 -0
  77. data/lib/vedeu/models/cell.rb +5 -8
  78. data/lib/vedeu/models/char.rb +50 -15
  79. data/lib/vedeu/models/composition.rb +8 -1
  80. data/lib/vedeu/models/focus.rb +4 -4
  81. data/lib/vedeu/models/group.rb +3 -3
  82. data/lib/vedeu/models/interface.rb +62 -46
  83. data/lib/vedeu/models/line.rb +1 -1
  84. data/lib/vedeu/models/null.rb +48 -0
  85. data/lib/vedeu/models/stream.rb +5 -5
  86. data/lib/vedeu/output/all.rb +20 -30
  87. data/lib/vedeu/output/border.rb +93 -40
  88. data/lib/vedeu/output/clear.rb +100 -15
  89. data/lib/vedeu/output/colour.rb +56 -12
  90. data/lib/vedeu/output/compressor.rb +59 -0
  91. data/lib/vedeu/output/html_char.rb +4 -2
  92. data/lib/vedeu/output/null_border.rb +16 -4
  93. data/lib/vedeu/output/output.rb +13 -21
  94. data/lib/vedeu/output/presentation.rb +28 -23
  95. data/lib/vedeu/output/refresh.rb +2 -2
  96. data/lib/vedeu/output/renderers/all.rb +80 -3
  97. data/lib/vedeu/output/renderers/file_renderer.rb +38 -2
  98. data/lib/vedeu/output/renderers/html_renderer.rb +6 -4
  99. data/lib/vedeu/output/renderers/json_renderer.rb +52 -0
  100. data/lib/vedeu/output/renderers/null_renderer.rb +14 -0
  101. data/lib/vedeu/output/renderers/terminal_renderer.rb +2 -12
  102. data/lib/vedeu/output/style.rb +33 -3
  103. data/lib/vedeu/output/text.rb +98 -1
  104. data/lib/vedeu/output/translator.rb +30 -7
  105. data/lib/vedeu/output/viewport.rb +43 -79
  106. data/lib/vedeu/output/wordwrap.rb +4 -4
  107. data/lib/vedeu/repositories/all.rb +22 -179
  108. data/lib/vedeu/repositories/collection.rb +11 -13
  109. data/lib/vedeu/repositories/collections/all.rb +8 -0
  110. data/lib/vedeu/repositories/collections/chars.rb +9 -0
  111. data/lib/vedeu/repositories/collections/events.rb +9 -0
  112. data/lib/vedeu/repositories/collections/interfaces.rb +9 -0
  113. data/lib/vedeu/repositories/collections/keys.rb +9 -0
  114. data/lib/vedeu/repositories/collections/lines.rb +9 -0
  115. data/lib/vedeu/repositories/collections/streams.rb +9 -0
  116. data/lib/vedeu/repositories/model.rb +7 -2
  117. data/lib/vedeu/repositories/repositories/all.rb +14 -0
  118. data/lib/vedeu/repositories/repositories/background_colours.rb +14 -0
  119. data/lib/vedeu/repositories/repositories/borders.rb +38 -0
  120. data/lib/vedeu/repositories/repositories/buffers.rb +36 -0
  121. data/lib/vedeu/repositories/repositories/colours.rb +63 -0
  122. data/lib/vedeu/repositories/repositories/cursors.rb +29 -0
  123. data/lib/vedeu/repositories/repositories/events_repository.rb +24 -0
  124. data/lib/vedeu/repositories/repositories/foreground_colours.rb +14 -0
  125. data/lib/vedeu/repositories/repositories/geometries.rb +37 -0
  126. data/lib/vedeu/repositories/repositories/groups.rb +24 -0
  127. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +24 -0
  128. data/lib/vedeu/repositories/repositories/keymaps.rb +24 -0
  129. data/lib/vedeu/repositories/repositories/menus.rb +24 -0
  130. data/lib/vedeu/repositories/repository.rb +29 -47
  131. data/lib/vedeu/storage/all.rb +6 -0
  132. data/lib/vedeu/storage/associative_store.rb +47 -0
  133. data/lib/vedeu/storage/conveyor_store.rb +69 -0
  134. data/lib/vedeu/storage/fifo_store.rb +37 -0
  135. data/lib/vedeu/storage/store.rb +58 -0
  136. data/lib/vedeu/support/all.rb +5 -10
  137. data/lib/vedeu/support/common.rb +0 -8
  138. data/lib/vedeu/support/log.rb +13 -24
  139. data/lib/vedeu/support/template.rb +4 -1
  140. data/lib/vedeu/support/terminal.rb +10 -10
  141. data/lib/vedeu/support/trace.rb +15 -88
  142. data/lib/vedeu/support/visibility.rb +73 -0
  143. data/lib/vedeu.rb +37 -0
  144. data/test/lib/vedeu/api_test.rb +7 -3
  145. data/test/lib/vedeu/application_test.rb +9 -3
  146. data/test/lib/vedeu/bindings_test.rb +21 -0
  147. data/test/lib/vedeu/buffers/buffer_test.rb +110 -134
  148. data/test/lib/vedeu/buffers/display_buffer_test.rb +8 -0
  149. data/test/lib/vedeu/configuration/api_test.rb +5 -1
  150. data/test/lib/vedeu/configuration/configuration_test.rb +4 -6
  151. data/test/lib/vedeu/cursor/cursor_test.rb +25 -17
  152. data/test/lib/vedeu/cursor/move_test.rb +7 -7
  153. data/test/lib/vedeu/distributed/client_test.rb +1 -1
  154. data/test/lib/vedeu/distributed/subprocess_test.rb +3 -1
  155. data/test/lib/vedeu/distributed/uri_test.rb +5 -5
  156. data/test/lib/vedeu/dsl/components/geometry_test.rb +43 -0
  157. data/test/lib/vedeu/dsl/components/keymap_test.rb +1 -1
  158. data/test/lib/vedeu/dsl/composition_test.rb +6 -5
  159. data/test/lib/vedeu/dsl/interface_test.rb +81 -16
  160. data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -4
  161. data/test/lib/vedeu/dsl/shared/text_test.rb +87 -9
  162. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  163. data/test/lib/vedeu/events/event_test.rb +3 -1
  164. data/test/lib/vedeu/events/trigger_test.rb +8 -4
  165. data/test/lib/vedeu/geometry/dimension_test.rb +1 -1
  166. data/test/lib/vedeu/geometry/geometry_test.rb +5 -3
  167. data/test/lib/vedeu/geometry/index_position_test.rb +30 -7
  168. data/test/lib/vedeu/geometry/null_geometry_test.rb +57 -0
  169. data/test/lib/vedeu/geometry/position_index_test.rb +14 -0
  170. data/test/lib/vedeu/geometry/position_validator_test.rb +17 -3
  171. data/test/lib/vedeu/input/keymap_test.rb +3 -1
  172. data/test/lib/vedeu/input/mapper_test.rb +8 -4
  173. data/test/lib/vedeu/launcher_test.rb +1 -1
  174. data/test/lib/vedeu/models/cell_test.rb +10 -8
  175. data/test/lib/vedeu/models/char_test.rb +52 -28
  176. data/test/lib/vedeu/models/composition_test.rb +26 -4
  177. data/test/lib/vedeu/models/group_test.rb +11 -5
  178. data/test/lib/vedeu/models/interface_test.rb +32 -19
  179. data/test/lib/vedeu/models/line_test.rb +21 -25
  180. data/test/lib/vedeu/models/menu_test.rb +10 -6
  181. data/test/lib/vedeu/models/null_test.rb +66 -0
  182. data/test/lib/vedeu/models/stream_test.rb +13 -10
  183. data/test/lib/vedeu/output/border_test.rb +29 -8
  184. data/test/lib/vedeu/output/clear_test.rb +23 -4
  185. data/test/lib/vedeu/output/colour_test.rb +20 -4
  186. data/test/lib/vedeu/output/compressor_test.rb +43 -0
  187. data/test/lib/vedeu/output/html_char_test.rb +29 -17
  188. data/test/lib/vedeu/output/null_border_test.rb +2 -1
  189. data/test/lib/vedeu/output/output_test.rb +20 -30
  190. data/test/lib/vedeu/output/presentation_test.rb +39 -16
  191. data/test/lib/vedeu/output/refresh_test.rb +14 -10
  192. data/test/lib/vedeu/output/renderers/all_test.rb +96 -0
  193. data/test/lib/vedeu/output/renderers/file_renderer_test.rb +1 -1
  194. data/test/lib/vedeu/output/renderers/html_renderer_test.rb +13 -9
  195. data/test/lib/vedeu/output/renderers/json_renderer_test.rb +52 -0
  196. data/test/lib/vedeu/output/renderers/null_renderer_test.rb +19 -0
  197. data/test/lib/vedeu/output/style_test.rb +41 -1
  198. data/test/lib/vedeu/output/text_test.rb +61 -10
  199. data/test/lib/vedeu/output/translator_test.rb +14 -0
  200. data/test/lib/vedeu/output/viewport_test.rb +22 -3
  201. data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -3
  202. data/test/lib/vedeu/output/wordwrap_test.rb +58 -45
  203. data/test/lib/vedeu/repositories/collections/chars_test.rb +16 -0
  204. data/test/lib/vedeu/repositories/collections/events_test.rb +16 -0
  205. data/test/lib/vedeu/repositories/collections/interfaces_test.rb +16 -0
  206. data/test/lib/vedeu/repositories/collections/keys_test.rb +16 -0
  207. data/test/lib/vedeu/repositories/collections/lines_test.rb +16 -0
  208. data/test/lib/vedeu/repositories/collections/streams_test.rb +16 -0
  209. data/test/lib/vedeu/repositories/repositories/background_colours_test.rb +17 -0
  210. data/test/lib/vedeu/repositories/repositories/borders_test.rb +51 -0
  211. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +52 -0
  212. data/test/lib/vedeu/repositories/repositories/colours_test.rb +16 -0
  213. data/test/lib/vedeu/repositories/repositories/cursors_test.rb +39 -0
  214. data/test/lib/vedeu/repositories/repositories/events_repository_test.rb +17 -0
  215. data/test/lib/vedeu/repositories/repositories/foreground_colours_test.rb +17 -0
  216. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +42 -0
  217. data/test/lib/vedeu/repositories/repositories/groups_test.rb +17 -0
  218. data/test/lib/vedeu/repositories/repositories/interfaces_repositories_test.rb +17 -0
  219. data/test/lib/vedeu/repositories/repositories/keymaps_test.rb +17 -0
  220. data/test/lib/vedeu/repositories/repositories/menus_test.rb +17 -0
  221. data/test/lib/vedeu/repositories/repository_test.rb +16 -36
  222. data/test/lib/vedeu/storage/associative_store_test.rb +69 -0
  223. data/test/lib/vedeu/storage/conveyor_store_test.rb +135 -0
  224. data/test/lib/vedeu/storage/fifo_store_test.rb +47 -0
  225. data/test/lib/vedeu/storage/store_test.rb +123 -0
  226. data/test/lib/vedeu/support/common_test.rb +0 -9
  227. data/test/lib/vedeu/support/terminal_test.rb +78 -55
  228. data/test/lib/vedeu/support/visibility_test.rb +80 -0
  229. data/test/test_helper.rb +13 -11
  230. data/vedeu.gemspec +4 -3
  231. metadata +92 -32
  232. data/lib/vedeu/cursor/toggle.rb +0 -55
  233. data/lib/vedeu/exceptions.rb +0 -37
  234. data/lib/vedeu/geometry/centre.rb +0 -85
  235. data/lib/vedeu/geometry/content.rb +0 -70
  236. data/lib/vedeu/geometry/limit.rb +0 -58
  237. data/lib/vedeu/output/compositor.rb +0 -62
  238. data/lib/vedeu/repositories/collections.rb +0 -41
  239. data/lib/vedeu/support/coercions.rb +0 -60
  240. data/lib/vedeu/support/sentence.rb +0 -91
  241. data/lib/vedeu/support/visible.rb +0 -90
  242. data/test/lib/vedeu/cursor/toggle_test.rb +0 -63
  243. data/test/lib/vedeu/geometry/centre_test.rb +0 -58
  244. data/test/lib/vedeu/geometry/content_test.rb +0 -98
  245. data/test/lib/vedeu/geometry/limit_test.rb +0 -30
  246. data/test/lib/vedeu/output/compositor_test.rb +0 -48
  247. data/test/lib/vedeu/repositories/all_test.rb +0 -135
  248. data/test/lib/vedeu/repositories/collections_test.rb +0 -71
  249. data/test/lib/vedeu/support/coercions_test.rb +0 -84
  250. data/test/lib/vedeu/support/sentence_test.rb +0 -56
  251. data/test/lib/vedeu/support/visible_test.rb +0 -161
@@ -0,0 +1,123 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ class StoreTestClass
6
+ include Vedeu::Store
7
+
8
+ attr_reader :model
9
+
10
+ def initialize(model = nil, storage = {})
11
+ @model = model
12
+ @storage = storage
13
+ end
14
+
15
+ private
16
+
17
+ def in_memory
18
+ {}
19
+ end
20
+ end
21
+
22
+ describe Store do
23
+
24
+ let(:described) { Vedeu::Store }
25
+ let(:instance) { Vedeu::StoreTestClass.new(model, storage) }
26
+ let(:model) {}
27
+ let(:storage) {}
28
+
29
+ describe 'alias methods' do
30
+ it { instance.must_respond_to(:registered?) }
31
+ end
32
+
33
+ describe '#each' do
34
+ subject { instance.each }
35
+
36
+ it { subject.must_be_instance_of(Enumerator) }
37
+ end
38
+
39
+ describe '#empty?' do
40
+ subject { instance.empty? }
41
+
42
+ context 'when empty' do
43
+ it { subject.must_equal(true) }
44
+ end
45
+
46
+ context 'when not empty' do
47
+ let(:storage) { [:item] }
48
+
49
+ it { subject.must_equal(false) }
50
+ end
51
+ end
52
+
53
+ describe '#exists?' do
54
+ let(:_name) {}
55
+
56
+ subject { instance.exists?(_name) }
57
+
58
+ context 'when empty' do
59
+ let(:_name) { 'terbium' }
60
+
61
+ it { subject.must_equal(false) }
62
+ end
63
+
64
+ context 'with no name' do
65
+ it { subject.must_equal(false) }
66
+ end
67
+
68
+ context 'with empty name' do
69
+ let(:_name) { '' }
70
+
71
+ it { subject.must_equal(false) }
72
+ end
73
+
74
+ context 'when the model does not exist' do
75
+ let(:storage) { { 'samarium' => [:some_model_data] } }
76
+ let(:_name) { 'terbium' }
77
+
78
+ it { subject.must_equal(false) }
79
+ end
80
+
81
+ context 'when the model exists' do
82
+ let(:storage) { { 'samarium' => [:some_model_data] } }
83
+ let(:_name) { 'samarium' }
84
+
85
+ it { subject.must_equal(true) }
86
+ end
87
+ end
88
+
89
+ describe '#reset' do
90
+ it 'returns a Hash' do
91
+ instance.reset.must_be_instance_of(Hash)
92
+ end
93
+
94
+ it 'resets the repository' do
95
+ instance.reset.must_equal({})
96
+ end
97
+ end
98
+
99
+ describe '#size' do
100
+ subject { instance.size }
101
+
102
+ context 'when empty' do
103
+ it { subject.must_equal(0) }
104
+ end
105
+
106
+ context 'when not empty' do
107
+ let(:storage) { [:item] }
108
+
109
+ it { subject.must_equal(1) }
110
+ end
111
+ end
112
+
113
+ describe '#storage' do
114
+ subject { instance.storage }
115
+
116
+ it { subject.must_equal({}) }
117
+
118
+ it { instance.must_respond_to(:all) }
119
+ end
120
+
121
+ end # Store
122
+
123
+ end # Vedeu
@@ -45,15 +45,6 @@ module Vedeu
45
45
  end
46
46
  end
47
47
 
48
- describe '#to_sentence' do
49
- let(:array) { ['hydrogen', 'helium', 'lithium'] }
50
-
51
- subject { described.to_sentence(array) }
52
-
53
- it { subject.must_be_instance_of(String) }
54
- it { subject.must_equal('hydrogen, helium and lithium') }
55
- end
56
-
57
48
  end # Common
58
49
 
59
50
  end # Vedeu
@@ -35,7 +35,7 @@ module Vedeu
35
35
  Configuration.stub(:terminal_mode, :raw) do
36
36
  capture_io do
37
37
  Terminal.open do
38
- print "Hello from raw mode!"
38
+ print 'Hello from raw mode!'
39
39
  end
40
40
  end.must_equal(['Hello from raw mode!', ''])
41
41
  end
@@ -45,7 +45,7 @@ module Vedeu
45
45
  Configuration.stub(:terminal_mode, :cooked) do
46
46
  capture_io do
47
47
  Terminal.open do
48
- print "Hello from cooked mode!"
48
+ print 'Hello from cooked mode!'
49
49
  end
50
50
  end.must_equal(['Hello from cooked mode!', ''])
51
51
  end
@@ -53,6 +53,8 @@ module Vedeu
53
53
  end
54
54
 
55
55
  describe '.input' do
56
+ subject { Terminal.input }
57
+
56
58
  context 'when the terminal is in cooked mode' do
57
59
  let(:mode) { :cooked }
58
60
  let(:input) { "Some input\r\n" }
@@ -62,8 +64,6 @@ module Vedeu
62
64
  IO.console.stubs(:gets).returns(input)
63
65
  end
64
66
 
65
- subject { Terminal.input }
66
-
67
67
  it { subject.must_equal('Some input') }
68
68
  end
69
69
 
@@ -78,8 +78,6 @@ module Vedeu
78
78
  IO.console.stubs(:read_nonblock)
79
79
  end
80
80
 
81
- subject { Terminal.input }
82
-
83
81
  it { subject.must_be_instance_of(String) }
84
82
  end
85
83
  end
@@ -95,20 +93,22 @@ module Vedeu
95
93
  context 'when there are multiple values' do
96
94
  let(:value) { ['Some output...', 'more output...', 'even more...'] }
97
95
 
98
- it { subject.must_equal(['Some output...', 'more output...', 'even more...']) }
96
+ it { subject.must_equal(['Some output...',
97
+ 'more output...',
98
+ 'even more...']) }
99
99
  end
100
100
  end
101
101
 
102
102
  describe '.resize' do
103
103
  before { Vedeu.interfaces.reset }
104
104
 
105
- subject { Terminal.resize }
105
+ subject { described.resize }
106
106
 
107
107
  it { subject.must_be_instance_of(TrueClass) }
108
108
  end
109
109
 
110
110
  describe '.clear' do
111
- subject { Terminal.clear }
111
+ subject { described.clear }
112
112
 
113
113
  it 'clears the screen' do
114
114
  subject.must_equal(["\e[39m\e[49m\e[2J"])
@@ -116,138 +116,161 @@ module Vedeu
116
116
  end
117
117
 
118
118
  describe '.set_cursor_mode' do
119
+ subject { described.set_cursor_mode }
120
+
119
121
  it 'shows the cursor in cooked mode' do
120
- Terminal.cooked_mode!
121
- Terminal.set_cursor_mode.must_equal(["\e[?25h"])
122
+ described.cooked_mode!
123
+ subject.must_equal(["\e[?25h"])
122
124
  end
123
125
 
124
126
  it 'hides the cursor in raw mode' do
125
- Terminal.raw_mode!
126
- Terminal.set_cursor_mode.must_equal(nil)
127
+ described.raw_mode!
128
+ subject.must_equal(nil)
127
129
  end
128
130
  end
129
131
 
130
132
  describe '.raw_mode?' do
133
+ subject { described.raw_mode? }
134
+
131
135
  it 'returns true if the terminal is in raw mode' do
132
- Terminal.raw_mode!
133
- Terminal.raw_mode?.must_equal(true)
136
+ described.raw_mode!
137
+ subject.must_equal(true)
134
138
  end
135
139
 
136
140
  it 'returns false if the terminal is not in raw mode' do
137
- Terminal.cooked_mode!
138
- Terminal.raw_mode?.must_equal(false)
141
+ described.cooked_mode!
142
+ subject.must_equal(false)
139
143
  end
140
144
  end
141
145
 
142
146
  describe '.cooked_mode?' do
147
+ subject { described.cooked_mode? }
148
+
143
149
  it 'returns true if the terminal is in cooked mode' do
144
- Terminal.cooked_mode!
145
- Terminal.cooked_mode?.must_equal(true)
150
+ described.cooked_mode!
151
+ subject.must_equal(true)
146
152
  end
147
153
 
148
154
  it 'returns false if the terminal is not in cooked mode' do
149
- Terminal.raw_mode!
150
- Terminal.cooked_mode?.must_equal(false)
155
+ described.raw_mode!
156
+ subject.must_equal(false)
151
157
  end
152
158
  end
153
159
 
154
160
  describe '.switch_mode!' do
161
+ subject { described.switch_mode! }
162
+
155
163
  it 'returns a Symbol' do
156
- Terminal.switch_mode!.must_be_instance_of(Symbol)
164
+ subject.must_be_instance_of(Symbol)
157
165
  end
158
166
 
159
167
  it 'returns :cooked if previously :raw' do
160
- Terminal.raw_mode!
161
- Terminal.switch_mode!.must_equal(:cooked)
168
+ described.raw_mode!
169
+ subject.must_equal(:cooked)
162
170
  end
163
171
 
164
172
  it 'returns :raw if previously :cooked' do
165
- Terminal.cooked_mode!
166
- Terminal.switch_mode!.must_equal(:raw)
173
+ described.cooked_mode!
174
+ subject.must_equal(:raw)
167
175
  end
168
176
  end
169
177
 
170
178
  describe '.mode' do
179
+ subject { described.mode }
180
+
171
181
  before do
172
182
  Configuration.stubs(:terminal_mode).returns(:raw)
173
183
  Terminal.switch_mode! if Terminal.mode == :cooked
174
184
  end
175
185
 
186
+ it { subject.must_be_instance_of(Symbol) }
187
+
176
188
  it 'returns the configured terminal mode' do
177
- Terminal.mode.must_be_instance_of(Symbol)
178
- Terminal.mode.must_equal(:raw)
189
+ subject.must_equal(:raw)
179
190
  end
180
191
  end
181
192
 
182
193
  describe '.centre' do
194
+ subject { described.centre }
195
+
196
+ it { subject.must_be_instance_of(Array) }
197
+
183
198
  it 'returns the centre point on the terminal' do
184
- Terminal.centre.must_be_instance_of(Array)
185
- Terminal.centre.must_equal([12, 40])
199
+ subject.must_equal([12, 40])
186
200
  end
187
201
  end
188
202
 
189
203
  describe '.centre_y' do
204
+ subject { described.centre_y }
205
+
206
+ it { subject.must_be_instance_of(Fixnum) }
207
+
190
208
  it 'returns the centre `y` point on the terminal' do
191
- Terminal.centre_y.must_be_instance_of(Fixnum)
192
- Terminal.centre_y.must_equal(12)
209
+ subject.must_equal(12)
193
210
  end
194
211
  end
195
212
 
196
213
  describe '.centre_x' do
214
+ subject { described.centre_x }
215
+
216
+ it { subject.must_be_instance_of(Fixnum) }
217
+
197
218
  it 'returns the centre `x` point on the terminal' do
198
- Terminal.centre_x.must_be_instance_of(Fixnum)
199
- Terminal.centre_x.must_equal(40)
219
+ subject.must_equal(40)
200
220
  end
201
221
  end
202
222
 
203
223
  describe '.origin' do
204
- it 'returns 1' do
205
- Terminal.origin.must_be_instance_of(Fixnum)
206
- Terminal.origin.must_equal(1)
207
- end
224
+ subject { Terminal.origin }
208
225
 
209
- it { Terminal.must_respond_to(:x) }
210
- it { Terminal.must_respond_to(:y) }
226
+ it { subject.must_be_instance_of(Fixnum) }
227
+
228
+ it { subject.must_equal(1) }
211
229
  end
212
230
 
213
231
  describe '.width' do
232
+ subject { Terminal.width }
233
+
234
+ it { subject.must_be_instance_of(Fixnum) }
235
+
214
236
  context 'via method' do
215
- it 'returns the width of the terminal' do
216
- Terminal.width.must_be_instance_of(Fixnum)
217
- Terminal.width.must_equal(80)
237
+ it 'returns the width' do
238
+ subject.must_equal(80)
218
239
  end
219
240
  end
220
241
 
221
242
  context 'via API' do
222
- it 'returns the width of the terminal' do
243
+ it 'returns the width' do
223
244
  Vedeu.width.must_equal(80)
224
245
  end
225
246
  end
226
-
227
- it { Terminal.must_respond_to(:xn) }
228
247
  end
229
248
 
230
249
  describe '.height' do
250
+ subject { Terminal.height }
251
+
252
+ it { subject.must_be_instance_of(Fixnum) }
253
+
231
254
  context 'via method' do
232
- it 'returns the height of the terminal' do
233
- Terminal.height.must_be_instance_of(Fixnum)
234
- Terminal.height.must_equal(25)
255
+ it 'returns the height' do
256
+ subject.must_equal(25)
235
257
  end
236
258
  end
237
259
 
238
260
  context 'via API' do
239
- it 'returns the height of the terminal' do
261
+ it 'returns the height' do
240
262
  Vedeu.height.must_equal(25)
241
263
  end
242
264
  end
243
-
244
- it { Terminal.must_respond_to(:yn) }
245
265
  end
246
266
 
247
267
  describe '.size' do
248
- it 'returns the width and height of the terminal' do
249
- Terminal.size.must_be_instance_of(Array)
250
- Terminal.size.must_equal([25, 80])
268
+ subject { Terminal.size }
269
+
270
+ it { subject.must_be_instance_of(Array) }
271
+
272
+ it 'returns the width and height' do
273
+ subject.must_equal([25, 80])
251
274
  end
252
275
  end
253
276
 
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ class VisibilityTestModel
6
+ attr_accessor :visible
7
+ alias_method :visible?, :visible
8
+
9
+ def initialize(visible = true)
10
+ @visible = visible
11
+ end
12
+
13
+ def store
14
+ self
15
+ end
16
+ end
17
+
18
+ describe Visibility do
19
+
20
+ let(:described) { Vedeu::Visibility }
21
+ let(:instance) { described.new(model) }
22
+ let(:model) { VisibilityTestModel.new(visible) }
23
+ let(:visible) { true }
24
+
25
+ describe '#initialize' do
26
+ it { instance.must_be_instance_of(Vedeu::Visibility) }
27
+ it { instance.instance_variable_get('@model').must_equal(model) }
28
+ end
29
+
30
+ describe '.show' do
31
+ subject { described.show(model) }
32
+
33
+ it { subject.must_equal(model) }
34
+
35
+ it { subject; instance.state.must_equal(:visible) }
36
+ end
37
+
38
+ describe '.hide' do
39
+ subject { described.hide(model) }
40
+
41
+ it { subject.must_equal(model) }
42
+
43
+ it { subject; instance.state.must_equal(:invisible) }
44
+ end
45
+
46
+ describe '.toggle' do
47
+ subject { described.toggle(model) }
48
+
49
+ it { subject.must_equal(model) }
50
+
51
+ context 'when the model is visible' do
52
+ it { subject; instance.state.must_equal(:invisible) }
53
+ end
54
+
55
+ context 'when the model is not visible' do
56
+ let(:visible) { false }
57
+
58
+ it { subject; instance.state.must_equal(:visible) }
59
+ end
60
+ end
61
+
62
+ describe '#state' do
63
+ subject { instance.state }
64
+
65
+ it { subject.must_be_instance_of(Symbol) }
66
+
67
+ context 'when the model is visible' do
68
+ it { subject.must_equal(:visible) }
69
+ end
70
+
71
+ context 'when the model is not visible' do
72
+ let(:visible) { false }
73
+
74
+ it { subject.must_equal(:invisible) }
75
+ end
76
+ end
77
+
78
+ end # Visibility
79
+
80
+ end # Vedeu
data/test/test_helper.rb CHANGED
@@ -37,6 +37,17 @@ require 'mocha/setup'
37
37
  require 'vedeu'
38
38
  require 'support/helpers/all'
39
39
 
40
+ # require 'minitest/reporters'
41
+ # Minitest::Reporters.use!(
42
+ # # commented out by default (makes tests slower)
43
+ # # Minitest::Reporters::DefaultReporter.new({ color: true, slow_count: 5 }),
44
+ # # Minitest::Reporters::SpecReporter.new
45
+ # )
46
+
47
+ # trace method execution with (optionally) local variables
48
+ # require 'vedeu/support/log'
49
+ # Vedeu::Trace.call({ watched: 'call', klass: /^Vedeu/ })
50
+
40
51
  def test_configuration
41
52
  Vedeu::Configuration.reset!
42
53
 
@@ -50,17 +61,8 @@ def test_configuration
50
61
  # will be logged, otherwise every `Vedeu.log` will be logged.
51
62
  log '/tmp/vedeu_test_helper.log'
52
63
  end
64
+
65
+ Vedeu::Repositories.reset!
53
66
  end
54
67
 
55
68
  test_configuration
56
-
57
- # require 'minitest/reporters'
58
- # Minitest::Reporters.use!(
59
- # # commented out by default (makes tests slower)
60
- # # Minitest::Reporters::DefaultReporter.new({ color: true, slow_count: 5 }),
61
- # # Minitest::Reporters::SpecReporter.new
62
- # )
63
-
64
- # trace method execution with (optionally) local variables
65
- # require 'vedeu/support/log'
66
- # Vedeu::Trace.call({ watched: 'call', klass: /^Vedeu/ })
data/vedeu.gemspec CHANGED
@@ -4,11 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.4.13'
7
+ spec.version = '0.4.14'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
- spec.summary = %q{A terminal case of wonderland.}
11
- spec.description = %q{A GUI framework written in Ruby for building terminal/console applications.}
10
+ spec.summary = 'A terminal case of wonderland.'
11
+ spec.description = 'A GUI framework written in Ruby for building ' \
12
+ 'terminal/console applications.'
12
13
  spec.homepage = 'https://github.com/gavinlaking/vedeu'
13
14
  spec.license = 'MIT'
14
15