vedeu 0.0.30 → 0.0.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -4
- data/lib/vedeu/configuration.rb +2 -2
- data/lib/vedeu/launcher.rb +2 -2
- data/lib/vedeu/models/command.rb +1 -1
- data/lib/vedeu/models/interface.rb +4 -0
- data/lib/vedeu/output/interface_renderer.rb +1 -1
- data/lib/vedeu/output/template.rb +23 -0
- data/lib/vedeu/output/text_adaptor.rb +1 -1
- data/lib/vedeu/process/process.rb +5 -1
- data/lib/vedeu/repository/command_repository.rb +3 -5
- data/lib/vedeu/repository/event_repository.rb +27 -0
- data/lib/vedeu/repository/interface_repository.rb +8 -6
- data/lib/vedeu/repository/storage.rb +2 -0
- data/lib/vedeu/support/esc.rb +2 -1
- data/lib/vedeu/support/geometry.rb +11 -23
- data/lib/vedeu/support/parser.rb +1 -1
- data/lib/vedeu/support/queue.rb +3 -1
- data/lib/vedeu.rb +18 -1
- data/test/example_app/bin/app +9 -0
- data/test/example_app/lib/app.rb +63 -0
- data/test/lib/vedeu/application_test.rb +6 -36
- data/test/lib/vedeu/configuration_test.rb +5 -31
- data/test/lib/vedeu/input/input_test.rb +4 -16
- data/test/lib/vedeu/launcher_test.rb +6 -15
- data/test/lib/vedeu/models/background_test.rb +5 -21
- data/test/lib/vedeu/models/colour_test.rb +18 -49
- data/test/lib/vedeu/models/command_test.rb +19 -83
- data/test/lib/vedeu/models/composition_test.rb +78 -175
- data/test/lib/vedeu/models/foreground_test.rb +4 -21
- data/test/lib/vedeu/models/interface_collection_test.rb +13 -45
- data/test/lib/vedeu/models/interface_test.rb +71 -195
- data/test/lib/vedeu/models/line_collection_test.rb +13 -52
- data/test/lib/vedeu/models/line_test.rb +17 -61
- data/test/lib/vedeu/models/presentation_test.rb +6 -19
- data/test/lib/vedeu/models/stream_collection_test.rb +10 -42
- data/test/lib/vedeu/models/stream_test.rb +16 -54
- data/test/lib/vedeu/models/style_collection_test.rb +1 -10
- data/test/lib/vedeu/output/interface_renderer_test.rb +7 -38
- data/test/lib/vedeu/output/output_test.rb +1 -18
- data/test/lib/vedeu/output/template.rb +20 -0
- data/test/lib/vedeu/output/text_adaptor_test.rb +9 -46
- data/test/lib/vedeu/process/process_test.rb +36 -38
- data/test/lib/vedeu/repository/command_repository_test.rb +16 -45
- data/test/lib/vedeu/repository/interface_repository_test.rb +36 -74
- data/test/lib/vedeu/repository/repository_test.rb +9 -33
- data/test/lib/vedeu/repository/storage_test.rb +7 -42
- data/test/lib/vedeu/support/esc_test.rb +46 -130
- data/test/lib/vedeu/support/event_repository_test.rb +31 -0
- data/test/lib/vedeu/support/exit_test.rb +1 -9
- data/test/lib/vedeu/support/geometry_test.rb +81 -105
- data/test/lib/vedeu/support/parser_test.rb +10 -54
- data/test/lib/vedeu/support/parsing/hash_parser_test.rb +18 -33
- data/test/lib/vedeu/support/parsing/json_parser_test.rb +4 -23
- data/test/lib/vedeu/support/queue_test.rb +33 -57
- data/test/lib/vedeu/support/terminal_test.rb +21 -52
- data/test/lib/vedeu/support/translator_test.rb +16 -33
- data/test/lib/vedeu/support/wordwrap_test.rb +29 -46
- data/test/lib/vedeu_test.rb +3 -5
- data/test/support/template.erb +3 -0
- data/test/test_helper.rb +1 -12
- data/vedeu.gemspec +8 -10
- metadata +26 -38
- data/lib/vedeu/support/events.rb +0 -21
- data/lib/vedeu/version.rb +0 -3
- data/test/lib/vedeu/support/events_test.rb +0 -45
- data/test/lib/vedeu/version_test.rb +0 -12
- data/test/support/output_1.json +0 -9
- data/test/support/output_1.rb +0 -14
@@ -3,73 +3,35 @@ require_relative '../../../../lib/vedeu/models/stream'
|
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
describe Stream do
|
6
|
-
|
7
|
-
|
8
|
-
let(:attributes) {
|
9
|
-
{
|
10
|
-
style: 'normal',
|
11
|
-
colour: { foreground: '#ff0000', background: '#000000' },
|
12
|
-
text: 'Some text'
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
describe '#initialize' do
|
17
|
-
let(:subject) { described_instance }
|
18
|
-
|
19
|
-
it 'returns a Stream instance' do
|
20
|
-
subject.must_be_instance_of(Stream)
|
21
|
-
end
|
6
|
+
it 'has a colour attribute' do
|
7
|
+
Stream.new({ colour: { foreground: '#ff0000', background: '#000000' } }).colour.must_be_instance_of(Colour)
|
22
8
|
end
|
23
9
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
it 'has a colour attribute' do
|
28
|
-
subject.must_be_instance_of(Colour)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#text' do
|
33
|
-
let(:subject) { described_instance.text }
|
34
|
-
|
35
|
-
it 'returns a String' do
|
36
|
-
subject.must_be_instance_of(String)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'has a text attribute' do
|
40
|
-
subject.must_equal('Some text')
|
41
|
-
end
|
10
|
+
it 'has a text attribute' do
|
11
|
+
Stream.new({ text: 'Some text' }).text.must_equal('Some text')
|
42
12
|
end
|
43
13
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
it 'has a style attribute' do
|
48
|
-
subject.must_be_instance_of(String)
|
49
|
-
end
|
14
|
+
it 'has a style attribute' do
|
15
|
+
Stream.new({ style: 'normal' }).style.must_equal("\e[24m\e[21m\e[27m")
|
50
16
|
end
|
51
17
|
|
52
18
|
describe '#to_s' do
|
53
|
-
let(:subject) { described_instance.to_s }
|
54
|
-
|
55
19
|
it 'returns a String' do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
20
|
+
Stream.new({
|
21
|
+
style: 'normal',
|
22
|
+
colour: { foreground: '#ff0000', background: '#000000' },
|
23
|
+
text: 'Some text'
|
24
|
+
}).to_s.must_equal("\e[38;5;196m\e[48;5;16m\e[24m\e[21m\e[27mSome text")
|
61
25
|
end
|
62
26
|
end
|
63
27
|
|
64
28
|
describe '#to_json' do
|
65
|
-
let(:subject) { described_instance.to_json }
|
66
|
-
|
67
|
-
it 'returns a String' do
|
68
|
-
subject.must_be_instance_of(String)
|
69
|
-
end
|
70
|
-
|
71
29
|
it 'returns a String' do
|
72
|
-
|
30
|
+
Stream.new({
|
31
|
+
style: 'normal',
|
32
|
+
colour: { foreground: '#ff0000', background: '#000000' },
|
33
|
+
text: 'Some text'
|
34
|
+
}).to_json.must_equal("{\"colour\":{\"foreground\":\"\\u001b[38;5;196m\",\"background\":\"\\u001b[48;5;16m\"},\"style\":\"\\u001b[24m\\u001b[21m\\u001b[27m\",\"text\":\"Some text\"}")
|
73
35
|
end
|
74
36
|
end
|
75
37
|
end
|
@@ -4,18 +4,9 @@ require_relative '../../../../lib/vedeu/models/stream'
|
|
4
4
|
|
5
5
|
module Vedeu
|
6
6
|
describe StyleCollection do
|
7
|
-
let(:described_class) { StyleCollection }
|
8
|
-
|
9
7
|
describe '#coerce' do
|
10
|
-
let(:subject) { Vedeu::Stream.new({ style: style }).style }
|
11
|
-
let(:style) {}
|
12
|
-
|
13
|
-
it 'returns a String' do
|
14
|
-
subject.must_be_instance_of(String)
|
15
|
-
end
|
16
|
-
|
17
8
|
it 'returns an empty string' do
|
18
|
-
|
9
|
+
Stream.new({ style: {} }).style.must_equal('')
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
@@ -4,53 +4,22 @@ require_relative '../../../../lib/vedeu/models/interface'
|
|
4
4
|
|
5
5
|
module Vedeu
|
6
6
|
describe InterfaceRenderer do
|
7
|
-
let(:described_class) { InterfaceRenderer }
|
8
|
-
let(:described_instance) { described_class.new(interface) }
|
9
|
-
let(:interface) { Interface.new(attributes) }
|
10
|
-
let(:attributes) { { name: 'dummy', width: 20, height: 2 } }
|
11
|
-
|
12
|
-
describe '#initialize' do
|
13
|
-
let(:subject) { described_instance }
|
14
|
-
|
15
|
-
it 'returns an InterfaceRenderer instance' do
|
16
|
-
subject.must_be_instance_of(InterfaceRenderer)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'sets an instance variable' do
|
20
|
-
subject.instance_variable_get("@interface").must_equal(interface)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
7
|
describe '.clear' do
|
25
|
-
let(:subject) { described_class.clear(interface) }
|
26
|
-
|
27
|
-
it 'returns a String' do
|
28
|
-
subject.must_be_instance_of(String)
|
29
|
-
end
|
30
|
-
|
31
8
|
it 'returns the escape sequence to clear the whole interface' do
|
32
|
-
|
9
|
+
interface = Interface.new({ name: 'dummy', width: 20, height: 2 })
|
10
|
+
InterfaceRenderer.clear(interface).must_equal("\e[1;1H \e[1;1H\e[2;1H \e[2;1H")
|
33
11
|
end
|
34
12
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it 'returns the escape sequence to clear the whole interface' do
|
39
|
-
subject.must_equal("\e[38;5;46m\e[48;5;226m\e[1;1H \e[1;1H\e[2;1H \e[2;1H")
|
40
|
-
end
|
13
|
+
it 'returns the escape sequence to clear the whole interface with specified colours' do
|
14
|
+
interface = Interface.new({ name: 'dummy', width: 20, height: 2, colour: { foreground: '#00ff00', background: '#ffff00' } })
|
15
|
+
InterfaceRenderer.clear(interface).must_equal("\e[38;5;46m\e[48;5;226m\e[1;1H \e[1;1H\e[2;1H \e[2;1H")
|
41
16
|
end
|
42
17
|
end
|
43
18
|
|
44
19
|
describe '.render' do
|
45
|
-
let(:subject) { described_class.render(interface) }
|
46
|
-
let(:attributes) { { name: 'dummy', width: 20, height: 2, lines: "Some text..." } }
|
47
|
-
|
48
|
-
it 'returns a String' do
|
49
|
-
subject.must_be_instance_of(String)
|
50
|
-
end
|
51
|
-
|
52
20
|
it 'returns the content for the interface' do
|
53
|
-
|
21
|
+
interface = Interface.new({ name: 'dummy', width: 20, height: 2, lines: 'InterfaceRenderer.render' })
|
22
|
+
InterfaceRenderer.render(interface).must_equal("\e[1;1HInterfaceRenderer.render")
|
54
23
|
end
|
55
24
|
end
|
56
25
|
end
|
@@ -3,26 +3,9 @@ require_relative '../../../../lib/vedeu/output/output'
|
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
describe Output do
|
6
|
-
let(:described_module) { Output }
|
7
|
-
let(:output) {}
|
8
|
-
|
9
|
-
before do
|
10
|
-
InterfaceRepository.create({
|
11
|
-
name: 'dummy',
|
12
|
-
width: 15,
|
13
|
-
height: 2,
|
14
|
-
cursor: true
|
15
|
-
})
|
16
|
-
Terminal.stubs(:output).returns(output)
|
17
|
-
end
|
18
|
-
|
19
|
-
after { InterfaceRepository.reset }
|
20
|
-
|
21
6
|
describe '.render' do
|
22
|
-
let(:subject) { described_module.render }
|
23
|
-
|
24
7
|
it 'returns an Array' do
|
25
|
-
|
8
|
+
Output.render.must_be_instance_of(Array)
|
26
9
|
end
|
27
10
|
end
|
28
11
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../../../test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Template do
|
5
|
+
describe '#parse' do
|
6
|
+
object = OpenStruct.new(value: 'Hello from variable!')
|
7
|
+
|
8
|
+
it 'parses the template when the template file was found' do
|
9
|
+
path = '/../../../test/support/template.erb'
|
10
|
+
Template.new(object, path).parse.must_match(/This is the test template/)
|
11
|
+
Template.new(object, path).parse.must_match(/Hello from variable!/)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'raises an exception when the template file cannot be found' do
|
15
|
+
path = '/some/wrong/path/template.erb'
|
16
|
+
proc { Template.new(object, path).parse }.must_raise(Errno::ENOENT)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,57 +3,20 @@ require_relative '../../../../lib/vedeu/output/text_adaptor'
|
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
describe TextAdaptor do
|
6
|
-
let(:described_class) { TextAdaptor }
|
7
|
-
let(:text) { '' }
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
let(:subject) { described_class.new(text) }
|
11
|
-
|
12
|
-
it 'returns an TextAdaptor instance' do
|
13
|
-
subject.must_be_instance_of(TextAdaptor)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'sets an instance variable' do
|
17
|
-
subject.instance_variable_get('@text').must_equal(text)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
6
|
describe '.adapt' do
|
22
|
-
|
23
|
-
|
24
|
-
it 'returns an Array' do
|
25
|
-
subject.must_be_instance_of(Array)
|
7
|
+
it 'returns an empty collection when processing an empty string' do
|
8
|
+
TextAdaptor.adapt('').must_be_empty
|
26
9
|
end
|
27
10
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
it 'returns an empty collection' do
|
32
|
-
subject.must_be_empty
|
33
|
-
end
|
11
|
+
it 'returns a single line' do
|
12
|
+
text = "This is a single line of text.\n"
|
13
|
+
TextAdaptor.adapt(text).size.must_equal(1)
|
34
14
|
end
|
35
15
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
subject.first.must_be_instance_of(Line)
|
41
|
-
|
42
|
-
subject.size.must_equal(1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when processing multiple lines' do
|
47
|
-
let(:text) {
|
48
|
-
"Lorem ipsum dolor sit amet,\nConseactetur adipiscing.\n" \
|
49
|
-
"Curabitur aliquet, turpis id dui.\n\nConditum elemum.\n"
|
50
|
-
}
|
51
|
-
|
52
|
-
it 'returns a collection of Line objects' do
|
53
|
-
subject.first.must_be_instance_of(Line)
|
54
|
-
|
55
|
-
subject.size.must_equal(5)
|
56
|
-
end
|
16
|
+
it 'returns multiple lines' do
|
17
|
+
text = "Lorem ipm olor sit aet,\nConsctetur adipiscing.\n" \
|
18
|
+
"Curitur aiquet, trpis id dui.\n\nCondum elemum.\n"
|
19
|
+
TextAdaptor.adapt(text).size.must_equal(5)
|
57
20
|
end
|
58
21
|
end
|
59
22
|
end
|
@@ -1,71 +1,69 @@
|
|
1
1
|
require_relative '../../../test_helper'
|
2
2
|
require_relative '../../../../lib/vedeu/process/process'
|
3
|
-
# require_relative '../../../../lib/vedeu/repository/interface_repository'
|
4
3
|
require_relative '../../../support/dummy_command'
|
5
4
|
require_relative '../../../../lib/vedeu/repository/command_repository'
|
6
5
|
|
7
6
|
module Vedeu
|
8
7
|
class QuitCommand
|
9
|
-
def self.dispatch
|
8
|
+
def self.dispatch
|
10
9
|
:stop
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
class TestCommand
|
15
|
-
def self.dispatch
|
16
|
-
|
14
|
+
def self.dispatch
|
15
|
+
{
|
16
|
+
'Process#evaluate' => 'TestCommand.dispatch'
|
17
|
+
}
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
class NoResultCommand
|
22
|
+
def self.dispatch
|
23
|
+
end
|
24
|
+
end
|
22
25
|
|
26
|
+
describe Process do
|
23
27
|
describe '.evaluate' do
|
24
|
-
|
28
|
+
it 'returns false when there is no input' do
|
29
|
+
Queue.reset
|
30
|
+
Process.evaluate.must_be_instance_of(FalseClass)
|
31
|
+
end
|
25
32
|
|
26
|
-
|
33
|
+
it 'raises an exception when the result is :stop' do
|
34
|
+
CommandRepository.reset
|
27
35
|
CommandRepository.create({
|
28
|
-
|
36
|
+
name: 'quit',
|
29
37
|
entity: QuitCommand,
|
30
38
|
keypress: 'q'
|
31
39
|
})
|
40
|
+
Queue.reset
|
41
|
+
Queue.enqueue('q')
|
42
|
+
proc { Process.evaluate }.must_raise(StopIteration)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns an Composition when there is a result' do
|
46
|
+
CommandRepository.reset
|
32
47
|
CommandRepository.create({
|
33
48
|
name: 'test',
|
34
49
|
entity: TestCommand,
|
35
50
|
keypress: 't'
|
36
51
|
})
|
37
|
-
Queue.
|
38
|
-
|
52
|
+
Queue.reset
|
53
|
+
Queue.enqueue('t')
|
54
|
+
Process.evaluate.must_be_instance_of(Composition)
|
39
55
|
end
|
40
56
|
|
41
|
-
|
57
|
+
it 'returns a NilClass when there is no result' do
|
42
58
|
CommandRepository.reset
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when there is input' do
|
54
|
-
context 'and the result is :stop' do
|
55
|
-
let(:input) { 'q' }
|
56
|
-
|
57
|
-
it 'raises an exception' do
|
58
|
-
proc { subject }.must_raise(StopIteration)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'and there is a result' do
|
63
|
-
let(:input) { 't' }
|
64
|
-
|
65
|
-
it 'returns an Composition' do
|
66
|
-
subject.must_be_instance_of(Composition)
|
67
|
-
end
|
68
|
-
end
|
59
|
+
CommandRepository.create({
|
60
|
+
name: 'no_result',
|
61
|
+
entity: NoResultCommand,
|
62
|
+
keypress: 'n'
|
63
|
+
})
|
64
|
+
Queue.reset
|
65
|
+
Queue.enqueue('n')
|
66
|
+
Process.evaluate.must_be_instance_of(NilClass)
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
@@ -4,9 +4,6 @@ require_relative '../../../../lib/vedeu/repository/command_repository'
|
|
4
4
|
|
5
5
|
module Vedeu
|
6
6
|
describe CommandRepository do
|
7
|
-
let(:described_class) { CommandRepository }
|
8
|
-
let(:input) {}
|
9
|
-
|
10
7
|
before do
|
11
8
|
CommandRepository.create({
|
12
9
|
name: 'apple',
|
@@ -21,66 +18,40 @@ module Vedeu
|
|
21
18
|
keyword: 'banana'
|
22
19
|
})
|
23
20
|
end
|
24
|
-
|
25
21
|
after { CommandRepository.reset }
|
26
22
|
|
27
23
|
describe '.by_input' do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
subject.must_be_instance_of(Command)
|
24
|
+
it 'returns the correct command when the command was found by keypress' do
|
25
|
+
CommandRepository.by_input('b').name.must_equal('banana')
|
26
|
+
CommandRepository.by_input('b').name.wont_equal('apple')
|
27
|
+
CommandRepository.by_input('b').keypress.must_equal('b')
|
33
28
|
end
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
it 'returns the correct command' do
|
41
|
-
subject.name.wont_equal('apple')
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns the correct command' do
|
45
|
-
subject.keypress.must_equal('b')
|
46
|
-
end
|
30
|
+
it 'returns the correct command when the command was found by keyword' do
|
31
|
+
CommandRepository.by_input('apple').keypress.must_equal('a')
|
32
|
+
CommandRepository.by_input('apple').keypress.wont_equal('b')
|
33
|
+
CommandRepository.by_input('apple').name.wont_equal('banana')
|
47
34
|
end
|
48
35
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
it 'returns the correct command' do
|
53
|
-
subject.keypress.must_equal('a')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns the correct command' do
|
57
|
-
subject.keypress.wont_equal('b')
|
58
|
-
end
|
36
|
+
it 'returns FalseClass when no command was found' do
|
37
|
+
CommandRepository.by_input('not_found').must_be_instance_of(FalseClass)
|
38
|
+
end
|
59
39
|
|
60
|
-
|
61
|
-
|
62
|
-
end
|
40
|
+
it 'returns FalseClass when there is no input' do
|
41
|
+
CommandRepository.by_input('').must_be_instance_of(FalseClass)
|
63
42
|
end
|
64
43
|
end
|
65
44
|
|
66
45
|
describe '.create' do
|
67
|
-
let(:subject) { described_class.create(attributes) }
|
68
|
-
let(:attributes) { {} }
|
69
|
-
|
70
46
|
it 'returns a Command' do
|
71
|
-
|
47
|
+
skip
|
48
|
+
CommandRepository.create({}).must_be_instance_of(Command)
|
72
49
|
end
|
73
50
|
end
|
74
51
|
|
75
52
|
describe '.entity' do
|
76
|
-
let(:subject) { described_class.entity }
|
77
|
-
|
78
|
-
it 'returns a Class instance' do
|
79
|
-
subject.must_be_instance_of(Class)
|
80
|
-
end
|
81
|
-
|
82
53
|
it 'returns Command' do
|
83
|
-
|
54
|
+
CommandRepository.entity.must_equal(Command)
|
84
55
|
end
|
85
56
|
end
|
86
57
|
end
|
@@ -3,112 +3,74 @@ require_relative '../../../../lib/vedeu/repository/interface_repository'
|
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
describe InterfaceRepository do
|
6
|
-
let(:described_class) { InterfaceRepository }
|
7
|
-
|
8
|
-
before do
|
9
|
-
InterfaceRepository.create({
|
10
|
-
name: 'dummy',
|
11
|
-
width: 15,
|
12
|
-
height: 2
|
13
|
-
})
|
14
|
-
end
|
15
|
-
after { InterfaceRepository.reset }
|
16
|
-
|
17
6
|
describe '.create' do
|
18
|
-
|
19
|
-
|
20
|
-
{
|
7
|
+
it 'returns an Interface' do
|
8
|
+
InterfaceRepository.create({
|
21
9
|
name: 'dummy',
|
22
10
|
width: 15,
|
23
11
|
height: 2
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
it 'returns an Interface' do
|
28
|
-
subject.must_be_instance_of(Interface)
|
12
|
+
}).must_be_instance_of(Interface)
|
29
13
|
end
|
30
14
|
end
|
31
15
|
|
32
16
|
describe '.find' do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
17
|
+
it 'returns an Interface when the interface exists' do
|
18
|
+
InterfaceRepository.create({
|
19
|
+
name: 'dummy',
|
20
|
+
width: 15,
|
21
|
+
height: 2
|
22
|
+
})
|
23
|
+
InterfaceRepository.find('dummy').must_be_instance_of(Interface)
|
40
24
|
end
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
proc { subject }.must_raise(UndefinedInterface)
|
47
|
-
end
|
26
|
+
it 'raises an exception when the interface does not exist' do
|
27
|
+
InterfaceRepository.reset
|
28
|
+
proc { InterfaceRepository.find('dummy') }
|
29
|
+
.must_raise(UndefinedInterface)
|
48
30
|
end
|
49
31
|
end
|
50
32
|
|
51
33
|
describe '.update' do
|
52
|
-
let(:subject) { described_class.update(value, attributes) }
|
53
|
-
let(:value) { 'dummy' }
|
54
|
-
let(:attributes) { { name: 'dumber' } }
|
55
|
-
|
56
34
|
it 'returns an Interface' do
|
57
|
-
|
35
|
+
InterfaceRepository.update('dummy', { name: 'dumber' })
|
36
|
+
.must_be_instance_of(Interface)
|
58
37
|
end
|
59
38
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
39
|
+
it 'updates and returns the existing interface when the interface exists' do
|
40
|
+
InterfaceRepository.update('dummy', { name: 'dumber' }).name
|
41
|
+
.must_equal('dumber')
|
64
42
|
end
|
65
43
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
subject.name.must_equal('dumber')
|
71
|
-
end
|
44
|
+
it 'returns a new interface when the interface does not exist' do
|
45
|
+
InterfaceRepository.reset
|
46
|
+
InterfaceRepository.update('dummy', { name: 'dumber' }).name
|
47
|
+
.must_equal('dumber')
|
72
48
|
end
|
73
49
|
end
|
74
50
|
|
75
51
|
describe '.refresh' do
|
76
|
-
let(:subject) { described_class.refresh }
|
77
|
-
|
78
|
-
it 'returns an Array' do
|
79
|
-
subject.must_be_instance_of(Array)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '.by_layer' do
|
84
|
-
let(:subject) { described_class.by_layer }
|
85
|
-
|
86
|
-
before do
|
87
|
-
InterfaceRepository.reset
|
88
|
-
@case_a = InterfaceRepository.create({ name: 'a', width: 15, height: 2, z: 2 })
|
89
|
-
@case_b = InterfaceRepository.create({ name: 'b', width: 15, height: 2, z: 1 })
|
90
|
-
@case_c = InterfaceRepository.create({ name: 'c', width: 15, height: 2, z: 3 })
|
91
|
-
end
|
92
|
-
after { InterfaceRepository.reset }
|
93
|
-
|
94
52
|
it 'returns an Array' do
|
95
|
-
|
53
|
+
InterfaceRepository.refresh.must_be_instance_of(Array)
|
96
54
|
end
|
97
55
|
|
98
56
|
it 'returns the collection in order they should be drawn' do
|
99
|
-
|
57
|
+
InterfaceRepository.reset
|
58
|
+
InterfaceRepository.create({
|
59
|
+
name: 'a', width: 15, height: 2, z: 2
|
60
|
+
}).enqueue("a")
|
61
|
+
InterfaceRepository.create({
|
62
|
+
name: 'b', width: 15, height: 2, z: 1
|
63
|
+
}).enqueue("b")
|
64
|
+
InterfaceRepository.create({
|
65
|
+
name: 'c', width: 15, height: 2, z: 3
|
66
|
+
}).enqueue("c")
|
67
|
+
InterfaceRepository.refresh.must_equal(['b', 'a', 'c'])
|
100
68
|
end
|
101
69
|
end
|
102
70
|
|
103
71
|
describe '.entity' do
|
104
|
-
let(:subject) { described_class.entity }
|
105
|
-
|
106
|
-
it 'returns a Class instance' do
|
107
|
-
subject.must_be_instance_of(Class)
|
108
|
-
end
|
109
|
-
|
110
72
|
it 'returns Interface' do
|
111
|
-
|
73
|
+
InterfaceRepository.entity.must_equal(Interface)
|
112
74
|
end
|
113
75
|
end
|
114
76
|
end
|