vedeu 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13eafb5c54e1925996315cb27013efe95164525c
4
- data.tar.gz: 8c428666c70339168afde09da41801203f505c12
3
+ metadata.gz: db7557217b4f94e3fcfea2f541421306550f35a4
4
+ data.tar.gz: 2a8dbc1907f3c2b48b9f24ee342d974686949ef3
5
5
  SHA512:
6
- metadata.gz: ade908fc69f911bccd2d8403ebd6a25066ef04e6d416e9db4e67e2154d85c81a6c6a14cd441d133c36d418e205d0e4e709c71e18f07325582e8445703d86fee5
7
- data.tar.gz: c732a46881adfb49a33c294c2c690db0edefa4263070cecb063a2cdb686c96ab17a2b931f34b1cfac7c2235104ad2f18b2b3849ef03eb05d9dd8c4c000fef904
6
+ metadata.gz: be86100e63189b39cbdb342ab8799e67f03a58b0b62f92fd165d4a70dcc3306da0639536cbc7cf8985dd63b699082a52d4f2021a13fa41f54658c0c1f9086b37
7
+ data.tar.gz: 3b7f9ea1aec43791928f0afbd3fac58f91f7cd2d269dca02f3d5e2f7b80bda87de406090d2a8c90c71513aa2957da88a9ab99be33e71ad8efe5fd8330dadedb9
data/lib/vedeu/all.rb CHANGED
@@ -44,6 +44,7 @@ require 'vedeu/null/menu'
44
44
  require 'vedeu/null/view'
45
45
 
46
46
  require 'vedeu/geometry/area'
47
+ require 'vedeu/geometry/generic_coordinate'
47
48
  require 'vedeu/geometry/coordinate'
48
49
  require 'vedeu/geometry/dimension'
49
50
  require 'vedeu/geometry/geometry'
@@ -46,173 +46,4 @@ module Vedeu
46
46
 
47
47
  end # Coordinate
48
48
 
49
- # Crudely corrects out of range values.
50
- #
51
- class GenericCoordinate
52
-
53
- # Return a new instance of Vedeu::GenericCoordinate.
54
- #
55
- # @param attributes [Hash]
56
- # @option attributes name [String]
57
- # @option attributes type [Symbol]
58
- # @option attributes offset [Fixnum]
59
- # @return [Vedeu::GenericCoordinate]
60
- def initialize(attributes = {})
61
- @attributes = defaults.merge!(attributes)
62
-
63
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
64
- end
65
-
66
- # Returns the maximum coordinate for an area.
67
- #
68
- # @example
69
- # # d = 2
70
- # # d_dn = 4
71
- # dn # => 6
72
- #
73
- # @return [Fixnum]
74
- def dn
75
- if d_dn <= 0
76
- 0
77
-
78
- else
79
- d + d_dn
80
-
81
- end
82
- end
83
- alias_method :xn, :dn
84
- alias_method :yn, :dn
85
-
86
- # Returns the coordinate for a given index.
87
- #
88
- # @example
89
- # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
90
- # position # => 4
91
- # position(-2) # => 4
92
- # position(2) # => 6
93
- # position(15) # => 13
94
- #
95
- # @return [Fixnum]
96
- def position
97
- pos = case
98
- when offset <= 0 then d
99
- when offset > dn_index then dn
100
- else
101
- d_range[offset]
102
- end
103
-
104
- pos = pos < bd ? bd : pos
105
- pos = pos > bdn ? bdn : pos
106
- pos
107
- end
108
- alias_method :x_position, :position
109
- alias_method :y_position, :position
110
-
111
- protected
112
-
113
- # @!attribute [r] name
114
- # @return [String]
115
- attr_reader :name
116
-
117
- # @!attribute [r] offset
118
- # @return [Fixnum]
119
- attr_reader :offset
120
-
121
- # @!attribute [r] type
122
- # @return [Symbol]
123
- attr_reader :type
124
-
125
- private
126
-
127
- # @see Vedeu::Borders#by_name
128
- def border
129
- @border ||= Vedeu.borders.by_name(name)
130
- end
131
-
132
- # Return the :x or :y value from the border.
133
- #
134
- # @return [Fixnum]
135
- def d
136
- border.send(coordinate_type[0])
137
- end
138
-
139
- # Return the :bx or :by value from the border.
140
- #
141
- # @return [Fixnum]
142
- def bd
143
- border.send(coordinate_type[1])
144
- end
145
-
146
- # Return the :bxn or :byn value from the border.
147
- #
148
- # @return [Fixnum]
149
- def bdn
150
- border.send(coordinate_type[2])
151
- end
152
-
153
- # Return the :width or :height value from the border.
154
- #
155
- # @return [Fixnum]
156
- def d_dn
157
- border.send(coordinate_type[3])
158
- end
159
-
160
- # Ascertain the correct methods to use for determining the coordinates.
161
- #
162
- # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type is not
163
- # given.
164
- # @return [Fixnum]
165
- def coordinate_type
166
- @_type ||= case type
167
- when :x then [:x, :bx, :bxn, :width]
168
- when :y then [:y, :by, :byn, :height]
169
- else
170
- fail Vedeu::Error::InvalidSyntax,
171
- 'Coordinate type not given, cannot continue.'
172
- end
173
- end
174
-
175
- # Returns the maximum index for an area.
176
- #
177
- # @example
178
- # # d_dn = 3
179
- # dn_index # => 2
180
- #
181
- # @return [Fixnum]
182
- def dn_index
183
- if d_dn < 1
184
- 0
185
-
186
- else
187
- d_dn - 1
188
-
189
- end
190
- end
191
-
192
- # Returns an array with all coordinates from d to dn.
193
- #
194
- # @example
195
- # # d_dn = 10
196
- # # d = 4
197
- # # dn = 14
198
- # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
199
- #
200
- # @return [Array]
201
- def d_range
202
- (d...dn).to_a
203
- end
204
-
205
- # The default values for a new instance of this class.
206
- #
207
- # @return [Hash]
208
- def defaults
209
- {
210
- name: '',
211
- offset: nil,
212
- type: :x,
213
- }
214
- end
215
-
216
- end # GenericCoordinate
217
-
218
49
  end # Vedeu
@@ -0,0 +1,172 @@
1
+ module Vedeu
2
+
3
+ # Crudely corrects out of range values.
4
+ #
5
+ class GenericCoordinate
6
+
7
+ # Return a new instance of Vedeu::GenericCoordinate.
8
+ #
9
+ # @param attributes [Hash]
10
+ # @option attributes name [String]
11
+ # @option attributes type [Symbol]
12
+ # @option attributes offset [Fixnum]
13
+ # @return [Vedeu::GenericCoordinate]
14
+ def initialize(attributes = {})
15
+ @attributes = defaults.merge!(attributes)
16
+
17
+ @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
18
+ end
19
+
20
+ # Returns the maximum coordinate for an area.
21
+ #
22
+ # @example
23
+ # # d = 2
24
+ # # d_dn = 4
25
+ # dn # => 6
26
+ #
27
+ # @return [Fixnum]
28
+ def dn
29
+ if d_dn <= 0
30
+ 0
31
+
32
+ else
33
+ d + d_dn
34
+
35
+ end
36
+ end
37
+ alias_method :xn, :dn
38
+ alias_method :yn, :dn
39
+
40
+ # Returns the coordinate for a given index.
41
+ #
42
+ # @example
43
+ # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
44
+ # position # => 4
45
+ # position(-2) # => 4
46
+ # position(2) # => 6
47
+ # position(15) # => 13
48
+ #
49
+ # @return [Fixnum]
50
+ def position
51
+ pos = case
52
+ when offset <= 0 then d
53
+ when offset > dn_index then dn
54
+ else
55
+ d_range[offset]
56
+ end
57
+
58
+ pos = pos < bd ? bd : pos
59
+ pos = pos > bdn ? bdn : pos
60
+ pos
61
+ end
62
+ alias_method :x_position, :position
63
+ alias_method :y_position, :position
64
+
65
+ protected
66
+
67
+ # @!attribute [r] name
68
+ # @return [String]
69
+ attr_reader :name
70
+
71
+ # @!attribute [r] offset
72
+ # @return [Fixnum]
73
+ attr_reader :offset
74
+
75
+ # @!attribute [r] type
76
+ # @return [Symbol]
77
+ attr_reader :type
78
+
79
+ private
80
+
81
+ # @see Vedeu::Borders#by_name
82
+ def border
83
+ @border ||= Vedeu.borders.by_name(name)
84
+ end
85
+
86
+ # Return the :x or :y value from the border.
87
+ #
88
+ # @return [Fixnum]
89
+ def d
90
+ border.send(coordinate_type[0])
91
+ end
92
+
93
+ # Return the :bx or :by value from the border.
94
+ #
95
+ # @return [Fixnum]
96
+ def bd
97
+ border.send(coordinate_type[1])
98
+ end
99
+
100
+ # Return the :bxn or :byn value from the border.
101
+ #
102
+ # @return [Fixnum]
103
+ def bdn
104
+ border.send(coordinate_type[2])
105
+ end
106
+
107
+ # Return the :width or :height value from the border.
108
+ #
109
+ # @return [Fixnum]
110
+ def d_dn
111
+ border.send(coordinate_type[3])
112
+ end
113
+
114
+ # Ascertain the correct methods to use for determining the coordinates.
115
+ #
116
+ # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type is not
117
+ # given.
118
+ # @return [Fixnum]
119
+ def coordinate_type
120
+ @_type ||= case type
121
+ when :x then [:x, :bx, :bxn, :width]
122
+ when :y then [:y, :by, :byn, :height]
123
+ else
124
+ fail Vedeu::Error::InvalidSyntax,
125
+ 'Coordinate type not given, cannot continue.'
126
+ end
127
+ end
128
+
129
+ # Returns the maximum index for an area.
130
+ #
131
+ # @example
132
+ # # d_dn = 3
133
+ # dn_index # => 2
134
+ #
135
+ # @return [Fixnum]
136
+ def dn_index
137
+ if d_dn < 1
138
+ 0
139
+
140
+ else
141
+ d_dn - 1
142
+
143
+ end
144
+ end
145
+
146
+ # Returns an array with all coordinates from d to dn.
147
+ #
148
+ # @example
149
+ # # d_dn = 10
150
+ # # d = 4
151
+ # # dn = 14
152
+ # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
153
+ #
154
+ # @return [Array]
155
+ def d_range
156
+ (d...dn).to_a
157
+ end
158
+
159
+ # The default values for a new instance of this class.
160
+ #
161
+ # @return [Hash]
162
+ def defaults
163
+ {
164
+ name: '',
165
+ offset: nil,
166
+ type: :x,
167
+ }
168
+ end
169
+
170
+ end # GenericCoordinate
171
+
172
+ end # Vedeu
@@ -137,7 +137,12 @@ module Vedeu
137
137
 
138
138
  # @return [Vedeu::Area]
139
139
  def area
140
- @area = Vedeu::Area.from_attributes(
140
+ @area = Vedeu::Area.from_attributes(area_attributes)
141
+ end
142
+
143
+ # @return [Hash<Symbol => Fixnum, Boolean>]
144
+ def area_attributes
145
+ {
141
146
  y: _y,
142
147
  yn: _yn,
143
148
  y_yn: _height,
@@ -148,7 +153,7 @@ module Vedeu
148
153
  x_default: Vedeu.width,
149
154
  centred: centred,
150
155
  maximised: maximised,
151
- )
156
+ }
152
157
  end
153
158
 
154
159
  # Returns the row/line start position for the interface.
@@ -154,13 +154,7 @@ module Vedeu
154
154
  #
155
155
  # @return [Array<String|void>]
156
156
  def lines
157
- @lines ||= if present?(data)
158
- Vedeu::Editor::Lines.coerce(data)
159
-
160
- else
161
- defaults[:data]
162
-
163
- end
157
+ @lines ||= Vedeu::Editor::Lines.coerce(data)
164
158
  end
165
159
 
166
160
  # Render the document content in the terminal.
@@ -15,9 +15,9 @@ module Vedeu
15
15
  # @option attributes value [String]
16
16
  # @return [Vedeu::Escape]
17
17
  def initialize(attributes = {})
18
- @attributes = defaults.merge!(attributes)
19
-
20
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
18
+ defaults.merge!(attributes).each do |key, value|
19
+ instance_variable_set("@#{key}", value)
20
+ end
21
21
  end
22
22
 
23
23
  # @return [NilClass]
@@ -12,9 +12,12 @@ module Vedeu
12
12
  new(value: value, x: x, y: y).write
13
13
  end
14
14
 
15
+ # Returns a new instance of Vedeu::Direct.
16
+ #
15
17
  # @param value [String]
16
18
  # @param x [Fixnum]
17
19
  # @param y [Fixnum]
20
+ # @return [Vedeu::Direct]
18
21
  def initialize(value:, x:, y:)
19
22
  @value = value || ''
20
23
  @x = x || 1
@@ -11,6 +11,7 @@ module Vedeu
11
11
  # Returns a new instance of Vedeu::Renderers::EscapeSequence.
12
12
  #
13
13
  # @param options [Hash]
14
+ # @return [Vedeu::Renderers::EscapeSequence]
14
15
  def initialize(options = {})
15
16
  @options = options || {}
16
17
  end
@@ -24,18 +24,15 @@ module Vedeu
24
24
  def render(output)
25
25
  @options[:content] = output
26
26
 
27
- if write_file?
28
- super(Vedeu::Templating::Template.parse(self, template))
29
-
30
- else
31
- Vedeu::Templating::Template.parse(self, template)
32
-
33
- end
27
+ super(Vedeu::Templating::Template.parse(self, template))
34
28
  end
35
29
 
36
30
  # @return [String]
37
31
  def html_body
32
+ return '' if content.is_a?(Vedeu::Escape)
33
+
38
34
  out = ''
35
+
39
36
  Array(content).each do |line|
40
37
  out << "#{start_row_tag}\n"
41
38
  line.each do |char|
@@ -24,10 +24,7 @@ module Vedeu
24
24
  # @param value [Object|NilClass]
25
25
  # @return [Object]
26
26
  def self.coerce(value)
27
- if value.nil?
28
- new
29
-
30
- elsif value.is_a?(self)
27
+ if value.is_a?(self)
31
28
  value
32
29
 
33
30
  else
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.3'
4
+ VERSION = '0.6.4'
5
5
 
6
6
  end
@@ -50,8 +50,6 @@ module Vedeu
50
50
  it { instance.must_respond_to(:render) }
51
51
  end
52
52
 
53
-
54
-
55
53
  end # ApplicationView
56
54
 
57
55
  end # Vedeu
@@ -396,139 +396,14 @@ module Vedeu
396
396
  end
397
397
 
398
398
  describe '#render' do
399
- let(:attributes) {
400
- {
401
- bottom_left: 'C',
402
- bottom_right: 'D',
403
- enabled: enabled,
404
- horizontal: 'H',
405
- name: 'Border#render',
406
- show_top: top,
407
- show_bottom: bottom,
408
- show_left: left,
409
- show_right: right,
410
- top_left: 'A',
411
- top_right: 'B',
412
- vertical: 'V'
413
- }
414
- }
415
- let(:enabled) { false }
416
- let(:top) { false }
417
- let(:bottom) { false }
418
- let(:left) { false }
419
- let(:right) { false }
420
- let(:visibility) { true }
421
- let(:geometry) {
422
- Vedeu::Geometry.new(name: 'Border#render', x: 1, xn: 4, y: 1, yn: 4)
423
- }
424
- let(:interface) { Vedeu::Interface.new(visible: visibility) }
425
-
426
- before { Vedeu.interfaces.stubs(:by_name).returns(interface) }
399
+ before { Vedeu::RenderBorder.stubs(:with) }
427
400
 
428
401
  subject { instance.render }
429
402
 
430
- it { subject.must_be_instance_of(Array) }
431
-
432
- context 'when the interface is not visible' do
433
- let(:visibility) { false }
434
-
435
- it { subject.must_equal([]) }
436
- end
437
-
438
- context 'when the border is not enabled' do
439
- it { subject.must_equal([]) }
440
- end
441
-
442
- context 'when the border is enabled' do
443
- let(:enabled) { true }
444
-
445
- context 'top' do
446
- let(:top) { true }
447
-
448
- it { subject.size.must_equal(4) }
449
- end
450
-
451
- context 'right' do
452
- let(:right) { true }
453
-
454
- it { subject.size.must_equal(4) }
455
- end
456
-
457
- context 'bottom' do
458
- let(:bottom) { true }
459
-
460
- it { subject.size.must_equal(4) }
461
- end
462
-
463
- context 'left' do
464
- let(:left) { true }
465
-
466
- it { subject.size.must_equal(4) }
467
- end
468
-
469
- context 'top and right' do
470
- let(:top) { true }
471
- let(:right) { true }
472
-
473
- it { subject.size.must_equal(7) }
474
- end
475
-
476
- context 'top and right and bottom' do
477
- let(:top) { true }
478
- let(:right) { true }
479
- let(:bottom) { true }
480
-
481
- it { subject.size.must_equal(10) }
482
- end
483
-
484
- context 'top and bottom' do
485
- let(:top) { true }
486
- let(:bottom) { true }
487
-
488
- it { subject.size.must_equal(8) }
489
- end
490
-
491
- context 'top and left' do
492
- let(:top) { true }
493
- let(:left) { true }
494
-
495
- it { subject.size.must_equal(7) }
496
- end
497
-
498
- context 'right and bottom' do
499
- let(:right) { true }
500
- let(:bottom) { true }
501
-
502
- it { subject.size.must_equal(7) }
503
- end
504
-
505
- context 'right and left' do
506
- let(:right) { true }
507
- let(:left) { true }
508
-
509
- it { subject.size.must_equal(8) }
510
- end
511
-
512
- context 'bottom and left' do
513
- let(:bottom) { true }
514
- let(:left) { true }
515
-
516
- it { subject.size.must_equal(7) }
517
- end
518
-
519
- context 'all' do
520
- let(:top) { true }
521
- let(:right) { true }
522
- let(:bottom) { true }
523
- let(:left) { true }
524
-
525
- it { subject.size.must_equal(12) }
526
- end
527
-
528
- context 'none' do
529
- it { subject.size.must_equal(0) }
530
- end
531
- end
403
+ it {
404
+ Vedeu::RenderBorder.expects(:with).with(instance)
405
+ subject
406
+ }
532
407
  end
533
408
 
534
409
  end # Border
@@ -2,4 +2,21 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- end
5
+ module Error
6
+
7
+ describe OutOfRange do
8
+
9
+ let(:described) { Vedeu::Error::OutOfRange }
10
+ let(:instance) { described.new }
11
+
12
+ describe '#message' do
13
+ subject { instance.message }
14
+
15
+ it { subject.must_be_instance_of(String) }
16
+ end
17
+
18
+ end # OutOfRange
19
+
20
+ end # Error
21
+
22
+ end # Vedeu
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe GenericCoordinate do
6
+
7
+ let(:described) { Vedeu::GenericCoordinate }
8
+ let(:instance) { described.new(attributes) }
9
+ let(:attributes) {
10
+ {
11
+ name: _name,
12
+ offset: offset,
13
+ type: type,
14
+ }
15
+ }
16
+ let(:_name) {}
17
+ let(:offset) {}
18
+ let(:type) {}
19
+
20
+ describe '#initialize' do
21
+ it { instance.must_be_instance_of(described) }
22
+ it { instance.instance_variable_get('@name').must_equal(_name) }
23
+ it { instance.instance_variable_get('@offset').must_equal(offset) }
24
+ it { instance.instance_variable_get('@type').must_equal(type) }
25
+ end
26
+
27
+ describe '#dn' do
28
+ subject { instance.dn }
29
+
30
+ # it { skip }
31
+ end
32
+
33
+ describe '#position' do
34
+ subject { instance.position }
35
+
36
+ # it { skip }
37
+ end
38
+
39
+ end # GenericCoordinate
40
+
41
+ end # Vedeu
@@ -152,28 +152,17 @@ module Vedeu
152
152
  end
153
153
 
154
154
  describe '#lines' do
155
- subject { instance.lines }
156
-
157
- context 'when the data is empty' do
158
- let(:data) {}
159
- let(:expected) {
160
- Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new])
161
- }
162
-
163
- it { subject.must_equal(expected) }
164
- end
155
+ let(:expected) {
156
+ Vedeu::Editor::Lines.new([
157
+ Vedeu::Editor::Line.new('Hydrogen'),
158
+ Vedeu::Editor::Line.new('Helium'),
159
+ Vedeu::Editor::Line.new('Lithium'),
160
+ ])
161
+ }
165
162
 
166
- context 'when the data is not empty' do
167
- let(:expected) {
168
- Vedeu::Editor::Lines.new([
169
- Vedeu::Editor::Line.new('Hydrogen'),
170
- Vedeu::Editor::Line.new('Helium'),
171
- Vedeu::Editor::Line.new('Lithium'),
172
- ])
173
- }
163
+ subject { instance.lines }
174
164
 
175
- it { subject.must_equal(expected) }
176
- end
165
+ it { subject.must_equal(expected) }
177
166
  end
178
167
 
179
168
  describe '#render' do
@@ -33,6 +33,10 @@ module Vedeu
33
33
  subject
34
34
  instance.instance_variable_get('@visible').must_equal(false)
35
35
  }
36
+
37
+ it { Vedeu::ToggleableTestClass.must_respond_to(:hide_cursor) }
38
+ it { Vedeu::ToggleableTestClass.must_respond_to(:hide_group) }
39
+ it { Vedeu::ToggleableTestClass.must_respond_to(:hide_interface) }
36
40
  end
37
41
 
38
42
  describe '#show' do
@@ -42,11 +46,19 @@ module Vedeu
42
46
  subject
43
47
  instance.instance_variable_get('@visible').must_equal(true)
44
48
  }
49
+
50
+ it { Vedeu::ToggleableTestClass.must_respond_to(:show_cursor) }
51
+ it { Vedeu::ToggleableTestClass.must_respond_to(:show_group) }
52
+ it { Vedeu::ToggleableTestClass.must_respond_to(:show_interface) }
45
53
  end
46
54
 
47
55
  describe '#toggle' do
48
56
  subject { instance.toggle }
49
57
 
58
+ it { Vedeu::ToggleableTestClass.must_respond_to(:toggle_cursor) }
59
+ it { Vedeu::ToggleableTestClass.must_respond_to(:toggle_group) }
60
+ it { Vedeu::ToggleableTestClass.must_respond_to(:toggle_interface) }
61
+
50
62
  context 'when the model is visible' do
51
63
  let(:visible) { true }
52
64
 
@@ -15,8 +15,6 @@ module Vedeu
15
15
  }
16
16
  let(:_name) { 'null_geometry' }
17
17
 
18
- before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
19
-
20
18
  describe '#initialize' do
21
19
  it { instance.must_be_instance_of(described) }
22
20
  it {
@@ -62,26 +60,38 @@ module Vedeu
62
60
  end
63
61
 
64
62
  describe '#height' do
63
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
64
+
65
65
  it { instance.height.must_equal(25) }
66
66
  end
67
67
 
68
68
  describe '#width' do
69
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
70
+
69
71
  it { instance.width.must_equal(40) }
70
72
  end
71
73
 
72
74
  describe '#x' do
75
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
76
+
73
77
  it { instance.x.must_equal(1) }
74
78
  end
75
79
 
76
80
  describe '#xn' do
81
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
82
+
77
83
  it { instance.xn.must_equal(40) }
78
84
  end
79
85
 
80
86
  describe '#y' do
87
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
88
+
81
89
  it { instance.y.must_equal(1) }
82
90
  end
83
91
 
84
92
  describe '#yn' do
93
+ before { Vedeu::Terminal.stubs(:size).returns([25, 40]) }
94
+
85
95
  it { instance.yn.must_equal(25) }
86
96
  end
87
97
 
@@ -65,6 +65,10 @@ module Vedeu
65
65
  it { instance.instance_variable_get('@options').must_equal(options) }
66
66
  end
67
67
 
68
+ describe '#content' do
69
+ it { instance.must_respond_to(:content) }
70
+ end
71
+
68
72
  describe '#prune' do
69
73
  let(:text) { text_line }
70
74
 
@@ -184,8 +188,8 @@ module Vedeu
184
188
  end
185
189
  end
186
190
 
187
- describe '#content' do
188
- subject { instance.content }
191
+ describe '.for' do
192
+ subject { described.for(text, options) }
189
193
 
190
194
  it { subject.must_be_instance_of(Vedeu::Views::Lines) }
191
195
 
@@ -53,12 +53,16 @@ module Vedeu
53
53
  let(:char) {}
54
54
 
55
55
  subject { described.store(char) }
56
+
57
+ it { subject.must_equal(char) }
56
58
  end
57
59
 
58
60
  describe '#stores' do
59
61
  let(:chars) {}
60
62
 
61
63
  subject { described.stores(chars) }
64
+
65
+ it { subject.must_equal([]) }
62
66
  end
63
67
 
64
68
  describe '#write' do
@@ -82,7 +86,11 @@ module Vedeu
82
86
  end
83
87
 
84
88
  describe '#reprocess' do
89
+ before { Vedeu::Terminal.stubs(:clear) }
90
+
85
91
  subject { described.reprocess }
92
+
93
+ it { subject.must_equal(['']) }
86
94
  end
87
95
 
88
96
  describe '#reset' do
@@ -0,0 +1,201 @@
1
+ require 'yaml'
2
+
3
+ module Minitest
4
+ module Reporters
5
+
6
+ class MeanTimeReporter < DefaultReporter
7
+
8
+ # @param options [Hash]
9
+ # @option previous_runs_filename [String] Contains the times for each test
10
+ # by description. Defaults to '/tmp/minitest_reporters_previous_run'.
11
+ # @option report_filename [String] Contains the parsed results for the
12
+ # last test run. Defaults to '/tmp/minitest_reporters_report'.
13
+ # @return [Minitest::Reporters::MeanTimeReporter]
14
+ def initialize(options = {})
15
+ super
16
+
17
+ @all_suite_times = []
18
+ end
19
+
20
+ # Copies the suite times from the
21
+ # {Minitest::Reporters::DefaultReporter#after_suite} method, making them
22
+ # available to this class.
23
+ #
24
+ # @return [Hash<String => Float>]
25
+ def after_suite(suite)
26
+ super
27
+
28
+ @all_suite_times = @suite_times
29
+ end
30
+
31
+ # Runs the {Minitest::Reporters::DefaultReporter#report} method and then
32
+ # enhances it by storing the results to the 'previous_runs_filename' and
33
+ # outputs the parsed results to both the 'report_filename' and the
34
+ # terminal.
35
+ #
36
+ def report
37
+ super
38
+
39
+ create_or_update_previous_runs!
40
+
41
+ create_new_report!
42
+ end
43
+
44
+ protected
45
+
46
+ attr_accessor :all_suite_times
47
+
48
+ private
49
+
50
+ # @return [Hash<String => Float>]
51
+ def current_run
52
+ Hash[all_suite_times]
53
+ end
54
+
55
+ # @return [Hash] Sets default values for the filenames used by this class.
56
+ def defaults
57
+ {
58
+ previous_runs_filename: '/tmp/minitest_reporters_previous_run',
59
+ report_filename: '/tmp/minitest_reporters_report',
60
+ }
61
+ end
62
+
63
+ # Added to the top of the report file to be helpful.
64
+ #
65
+ # @return [String]
66
+ def report_header
67
+ "Samples: #{samples}\n\n"
68
+ end
69
+
70
+ # The report itself. Displays statistic about all runs, ideal for use with
71
+ # the Unix 'head' command. Listed in slowest average descending order.
72
+ #
73
+ # @return [String]
74
+ def report_body
75
+ previous_run.each_with_object([]) do |(description, timings), obj|
76
+ size = timings.size
77
+ sum = timings.inject { |total, x| total + x }
78
+ avg = (sum / size).round(9).to_s.ljust(12)
79
+ min = timings.min.to_s.ljust(12)
80
+ max = timings.max.to_s.ljust(12)
81
+
82
+ obj << "#{avg_label} #{avg} " \
83
+ "#{min_label} #{min} " \
84
+ "#{max_label} #{max} " \
85
+ "#{des_label} #{description}\n"
86
+ end.sort.reverse.join
87
+ end
88
+
89
+ # @return [Hash]
90
+ def options
91
+ defaults.merge!(@options)
92
+ end
93
+
94
+ # @return [Hash<String => Array<Float>]
95
+ def previous_run
96
+ @previous_run ||= YAML.load_file(previous_runs_filename)
97
+ end
98
+
99
+ # @return [String] The path to the file which contains all the durations
100
+ # for each test run. The previous runs file is in YAML format, using the
101
+ # test name for the key and an array containing the time taken to run
102
+ # this test for values.
103
+ #
104
+ # @return [String]
105
+ def previous_runs_filename
106
+ options[:previous_runs_filename]
107
+ end
108
+
109
+ # Returns a boolean indicating whether a previous runs file exists.
110
+ #
111
+ # @return [Boolean]
112
+ def previously_ran?
113
+ File.exist?(previous_runs_filename)
114
+ end
115
+
116
+ # @return [String] The path to the file which contains the parsed test
117
+ # results. The results file contains a line for each test with the
118
+ # average time of the test, the minimum time the test took to run,
119
+ # the maximum time the test took to run and a description of the test
120
+ # (which is the test name as emitted by Minitest).
121
+ def report_filename
122
+ options[:report_filename]
123
+ end
124
+
125
+ # A barbaric way to find out how many runs are in the previous runs file;
126
+ # this method takes the first test listed, and counts its samples
127
+ # trusting (naively) all runs to be the same number of samples. This will
128
+ # produce incorrect averages when new tests are added, so it is advised
129
+ # to restart the statistics by removing the 'previous runs' file.
130
+ #
131
+ # @return [Fixnum]
132
+ def samples
133
+ return 1 unless previous_run.first[1].is_a?(Array)
134
+
135
+ previous_run.first[1].size
136
+ end
137
+
138
+ # Creates a new 'previous runs' file, or updates the existing one with
139
+ # the latest timings.
140
+ #
141
+ # @return [void]
142
+ def create_or_update_previous_runs!
143
+ if previously_ran?
144
+ current_run.each do |description, elapsed|
145
+ new_times = if previous_run["#{description}"]
146
+ Array(previous_run["#{description}"]) << elapsed
147
+
148
+ else
149
+ Array(elapsed)
150
+
151
+ end
152
+
153
+ previous_run.store("#{description}", new_times)
154
+ end
155
+
156
+ File.write(previous_runs_filename, previous_run.to_yaml)
157
+
158
+ else
159
+
160
+ File.write(previous_runs_filename, current_run.to_yaml)
161
+
162
+ end
163
+ end
164
+
165
+ # Creates a new report file in the 'report_filename'. This file contains
166
+ # a line for each test of the following example format:
167
+ #
168
+ # Avg: 0.0555555 Min: 0.0498765 Max: 0.0612345 Description: The test name
169
+ #
170
+ # Note however the timings are to 9 decimal places, and padded to 12
171
+ # characters and each label is coloured, Avg (yellow), Min (green),
172
+ # Max (red) and Description (blue). It looks pretty!
173
+ #
174
+ # @return [void]
175
+ def create_new_report!
176
+ File.write(report_filename, report_header + report_body)
177
+ end
178
+
179
+ # @return [String] A yellow 'Avg:' label.
180
+ def avg_label
181
+ "\e[33mAvg:\e[39m"
182
+ end
183
+
184
+ # @return [String] A blue 'Description:' label.
185
+ def des_label
186
+ "\e[34mDescription:\e[39m"
187
+ end
188
+
189
+ # @return [String] A red 'Max:' label.
190
+ def max_label
191
+ "\e[31mMax:\e[39m"
192
+ end
193
+
194
+ # @return [String] A green 'Min:' label.
195
+ def min_label
196
+ "\e[32mMin:\e[39m"
197
+ end
198
+
199
+ end
200
+ end
201
+ end
data/test/test_helper.rb CHANGED
@@ -88,11 +88,15 @@ require 'vedeu'
88
88
  require 'support/helpers/model_test_class'
89
89
 
90
90
  # require 'minitest/reporters'
91
+ # require 'support/average_duration_reporter'
91
92
  # Minitest::Reporters.use!(
92
- # # commented out by default (makes tests slower)
93
- # # Minitest::Reporters::DefaultReporter.new({ color: true,
94
- # # slow_suite_count: 3 }),
95
- # # Minitest::Reporters::SpecReporter.new
93
+ # commented out by default (makes tests slower)
94
+ # Minitest::Reporters::MeanTimeReporter.new({
95
+ # previous_runs_filename: "/tmp/reports/durations",
96
+ # report_filename: "/tmp/reports/durations_results"})
97
+ # Minitest::Reporters::DefaultReporter.new({ color: true,
98
+ # slow_suite_count: 15 }),
99
+ # Minitest::Reporters::SpecReporter.new
96
100
  # )
97
101
 
98
102
  def test_configuration
data/vedeu.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'guard', '2.13.0'
24
24
  spec.add_development_dependency 'guard-minitest', '2.4.4'
25
25
  spec.add_development_dependency 'minitest', '5.8.0'
26
- spec.add_development_dependency 'minitest-reporters', '1.0.20'
26
+ spec.add_development_dependency 'minitest-reporters', '1.1.0'
27
27
  spec.add_development_dependency 'mocha', '1.1.0'
28
28
  spec.add_development_dependency 'pry', '0.10.1'
29
29
  spec.add_development_dependency 'rubocop', '0.34.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.20
61
+ version: 1.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.0.20
68
+ version: 1.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -342,6 +342,7 @@ files:
342
342
  - lib/vedeu/geometry/area.rb
343
343
  - lib/vedeu/geometry/coordinate.rb
344
344
  - lib/vedeu/geometry/dimension.rb
345
+ - lib/vedeu/geometry/generic_coordinate.rb
345
346
  - lib/vedeu/geometry/geometries.rb
346
347
  - lib/vedeu/geometry/geometry.rb
347
348
  - lib/vedeu/geometry/grid.rb
@@ -521,6 +522,7 @@ files:
521
522
  - test/lib/vedeu/geometry/area_test.rb
522
523
  - test/lib/vedeu/geometry/coordinate_test.rb
523
524
  - test/lib/vedeu/geometry/dimension_test.rb
525
+ - test/lib/vedeu/geometry/generic_coordinate_test.rb
524
526
  - test/lib/vedeu/geometry/geometries_test.rb
525
527
  - test/lib/vedeu/geometry/geometry_test.rb
526
528
  - test/lib/vedeu/geometry/grid_test.rb
@@ -625,6 +627,7 @@ files:
625
627
  - test/lib/vedeu/terminal/terminal_test.rb
626
628
  - test/lib/vedeu_test.rb
627
629
  - test/support/all_seeds.sh
630
+ - test/support/average_duration_reporter.rb
628
631
  - test/support/coverage.rb
629
632
  - test/support/helpers/model_test_class.rb
630
633
  - test/support/stats.sh
@@ -727,6 +730,7 @@ test_files:
727
730
  - test/lib/vedeu/geometry/area_test.rb
728
731
  - test/lib/vedeu/geometry/coordinate_test.rb
729
732
  - test/lib/vedeu/geometry/dimension_test.rb
733
+ - test/lib/vedeu/geometry/generic_coordinate_test.rb
730
734
  - test/lib/vedeu/geometry/geometries_test.rb
731
735
  - test/lib/vedeu/geometry/geometry_test.rb
732
736
  - test/lib/vedeu/geometry/grid_test.rb
@@ -831,6 +835,7 @@ test_files:
831
835
  - test/lib/vedeu/terminal/terminal_test.rb
832
836
  - test/lib/vedeu_test.rb
833
837
  - test/support/all_seeds.sh
838
+ - test/support/average_duration_reporter.rb
834
839
  - test/support/coverage.rb
835
840
  - test/support/helpers/model_test_class.rb
836
841
  - test/support/stats.sh