rambling-trie 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.md +68 -29
- data/lib/rambling/trie/comparable.rb +2 -3
- data/lib/rambling/trie/compressible.rb +3 -5
- data/lib/rambling/trie/compressor.rb +2 -12
- data/lib/rambling/trie/configuration/properties.rb +8 -14
- data/lib/rambling/trie/configuration/provider_collection.rb +19 -27
- data/lib/rambling/trie/container.rb +28 -42
- data/lib/rambling/trie/enumerable.rb +4 -2
- data/lib/rambling/trie/nodes/compressed.rb +4 -5
- data/lib/rambling/trie/nodes/missing.rb +1 -2
- data/lib/rambling/trie/nodes/node.rb +21 -34
- data/lib/rambling/trie/nodes/raw.rb +2 -2
- data/lib/rambling/trie/readers/plain_text.rb +10 -6
- data/lib/rambling/trie/readers/reader.rb +19 -0
- data/lib/rambling/trie/readers.rb +1 -1
- data/lib/rambling/trie/serializers/file.rb +1 -1
- data/lib/rambling/trie/serializers/marshal.rb +12 -20
- data/lib/rambling/trie/serializers/serializer.rb +27 -0
- data/lib/rambling/trie/serializers/yaml.rb +10 -16
- data/lib/rambling/trie/serializers/zip.rb +9 -5
- data/lib/rambling/trie/serializers.rb +1 -1
- data/lib/rambling/trie/stringifyable.rb +1 -1
- data/lib/rambling/trie/version.rb +1 -1
- data/lib/rambling/trie.rb +19 -22
- data/rambling-trie.gemspec +9 -5
- data/spec/integration/rambling/trie_spec.rb +49 -20
- data/spec/lib/rambling/trie/comparable_spec.rb +29 -39
- data/spec/lib/rambling/trie/compressor_spec.rb +17 -14
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +25 -7
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +44 -16
- data/spec/lib/rambling/trie/container_spec.rb +202 -327
- data/spec/lib/rambling/trie/enumerable_spec.rb +18 -10
- data/spec/lib/rambling/trie/inspectable_spec.rb +9 -3
- data/spec/lib/rambling/trie/nodes/compressed_spec.rb +6 -0
- data/spec/lib/rambling/trie/nodes/node_spec.rb +1 -1
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +32 -27
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +11 -1
- data/spec/lib/rambling/trie/readers/reader_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/file_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/serializer_spec.rb +21 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +24 -16
- data/spec/lib/rambling/trie/stringifyable_spec.rb +17 -13
- data/spec/lib/rambling/trie_spec.rb +107 -45
- data/spec/spec_helper.rb +16 -9
- data/spec/support/shared_examples/a_compressible_trie.rb +9 -3
- data/spec/support/shared_examples/a_container_partial_word.rb +17 -0
- data/spec/support/shared_examples/a_container_scan.rb +14 -0
- data/spec/support/shared_examples/a_container_word.rb +43 -0
- data/spec/support/shared_examples/a_container_words_within.rb +44 -0
- data/spec/support/shared_examples/a_serializable_trie.rb +5 -9
- data/spec/support/shared_examples/a_serializer.rb +37 -14
- data/spec/support/shared_examples/a_trie_data_structure.rb +24 -10
- data/spec/support/shared_examples/a_trie_node.rb +22 -14
- data/spec/support/shared_examples/a_trie_node_implementation.rb +40 -43
- metadata +25 -9
@@ -6,32 +6,60 @@ require 'zip'
|
|
6
6
|
describe Rambling::Trie do
|
7
7
|
let(:assets_path) { File.join ::SPEC_ROOT, 'assets' }
|
8
8
|
|
9
|
+
describe '::VERSION' do
|
10
|
+
let(:root_path) { File.join ::SPEC_ROOT, '..' }
|
11
|
+
let(:readme_path) { File.join root_path, 'README.md' }
|
12
|
+
let(:readme) { File.read readme_path }
|
13
|
+
let(:changelog_path) { File.join root_path, 'CHANGELOG.md' }
|
14
|
+
let(:changelog) { File.read changelog_path }
|
15
|
+
|
16
|
+
let(:changelog_versions) do
|
17
|
+
matches = []
|
18
|
+
changelog.scan %r{^## (\d+\.\d+\.\d+)} do |match|
|
19
|
+
matches << match[0]
|
20
|
+
end
|
21
|
+
matches
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'matches with the version in the README badge' do
|
25
|
+
match = %r{\?version=(?<version>.*)$}.match readme
|
26
|
+
expect(match['version']).to eq Rambling::Trie::VERSION
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is the version before the one at the top of the CHANGELOG' do
|
30
|
+
changelog_version = Gem::Version.new changelog_versions.first
|
31
|
+
lib_version = Gem::Version.new "#{Rambling::Trie::VERSION}.0"
|
32
|
+
expect(changelog_version).to eq lib_version.bump
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is included in the CHANGELOG diffs' do
|
36
|
+
changelog_versions.shift
|
37
|
+
expect(changelog_versions.first).to eq Rambling::Trie::VERSION
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
9
41
|
context 'when providing words directly' do
|
10
42
|
it_behaves_like 'a compressible trie' do
|
11
|
-
let(:trie) {
|
43
|
+
let(:trie) { described_class.create }
|
12
44
|
let(:words) { %w(a couple of words for our full trie integration test) }
|
13
45
|
|
14
|
-
before
|
15
|
-
trie.concat words
|
16
|
-
end
|
46
|
+
before { trie.concat words }
|
17
47
|
end
|
18
48
|
end
|
19
49
|
|
20
50
|
context 'when provided with words with unicode characters' do
|
21
51
|
it_behaves_like 'a compressible trie' do
|
22
|
-
let(:trie) {
|
23
|
-
let
|
52
|
+
let(:trie) { described_class.create }
|
53
|
+
let :words do
|
24
54
|
%w(poquísimas palabras para nuestra prueba de integración completa 🙃)
|
25
55
|
end
|
26
56
|
|
27
|
-
before
|
28
|
-
trie.concat words
|
29
|
-
end
|
57
|
+
before { trie.concat words }
|
30
58
|
end
|
31
59
|
end
|
32
60
|
|
33
61
|
context 'when provided with a filepath' do
|
34
|
-
let(:trie) {
|
62
|
+
let(:trie) { described_class.create filepath }
|
35
63
|
let(:words) { File.readlines(filepath).map(&:chomp) }
|
36
64
|
|
37
65
|
context 'with english words' do
|
@@ -53,34 +81,35 @@ describe Rambling::Trie do
|
|
53
81
|
|
54
82
|
context 'when serialized with Ruby marshal format (default)' do
|
55
83
|
it_behaves_like 'a serializable trie' do
|
56
|
-
let(:trie_to_serialize) {
|
57
|
-
let(:
|
84
|
+
let(:trie_to_serialize) { described_class.create words_filepath }
|
85
|
+
let(:file_format) { :marshal }
|
58
86
|
end
|
59
87
|
end
|
60
88
|
|
61
89
|
context 'when serialized with YAML' do
|
62
90
|
it_behaves_like 'a serializable trie' do
|
63
|
-
let(:trie_to_serialize) {
|
64
|
-
let(:
|
91
|
+
let(:trie_to_serialize) { described_class.create words_filepath }
|
92
|
+
let(:file_format) { :yml }
|
65
93
|
end
|
66
94
|
end
|
67
95
|
|
68
96
|
context 'when serialized with zipped Ruby marshal format' do
|
97
|
+
let!(:original_on_exists_proc) { ::Zip.on_exists_proc }
|
98
|
+
let!(:original_continue_on_exists_proc) { ::Zip.continue_on_exists_proc }
|
99
|
+
|
69
100
|
before do
|
70
|
-
@original_on_exists_proc = ::Zip.on_exists_proc
|
71
|
-
@original_continue_on_exists_proc = ::Zip.continue_on_exists_proc
|
72
101
|
::Zip.on_exists_proc = true
|
73
102
|
::Zip.continue_on_exists_proc = true
|
74
103
|
end
|
75
104
|
|
76
105
|
after do
|
77
|
-
::Zip.on_exists_proc =
|
78
|
-
::Zip.continue_on_exists_proc =
|
106
|
+
::Zip.on_exists_proc = original_on_exists_proc
|
107
|
+
::Zip.continue_on_exists_proc = original_continue_on_exists_proc
|
79
108
|
end
|
80
109
|
|
81
110
|
it_behaves_like 'a serializable trie' do
|
82
|
-
let(:trie_to_serialize) {
|
83
|
-
let(:
|
111
|
+
let(:trie_to_serialize) { described_class.create words_filepath }
|
112
|
+
let(:file_format) { 'marshal.zip' }
|
84
113
|
end
|
85
114
|
end
|
86
115
|
end
|
@@ -4,93 +4,83 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Rambling::Trie::Comparable do
|
6
6
|
describe '#==' do
|
7
|
-
let(:
|
8
|
-
let(:
|
7
|
+
let(:node_one) { Rambling::Trie::Nodes::Raw.new }
|
8
|
+
let(:node_two) { Rambling::Trie::Nodes::Raw.new }
|
9
9
|
|
10
10
|
context 'when the nodes do not have the same letter' do
|
11
11
|
before do
|
12
|
-
|
13
|
-
|
12
|
+
node_one.letter = :a
|
13
|
+
node_two.letter = :b
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'returns false' do
|
17
|
-
expect(
|
17
|
+
expect(node_one).not_to eq node_two
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'when
|
21
|
+
context 'when nodes have same letter, not terminal and no children' do
|
22
22
|
before do
|
23
|
-
|
24
|
-
|
23
|
+
node_one.letter = :a
|
24
|
+
node_two.letter = :a
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'returns true' do
|
28
|
-
expect(
|
28
|
+
expect(node_one).to eq node_two
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'when the nodes have the same letter and are terminal' do
|
33
33
|
before do
|
34
|
-
|
35
|
-
|
34
|
+
node_one.letter = :a
|
35
|
+
node_one.terminal!
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
node_two.letter = :a
|
38
|
+
node_two.terminal!
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'returns true' do
|
42
|
-
expect(
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when the nodes have the same letter and are not terminal' do
|
47
|
-
before do
|
48
|
-
node_1.letter = :a
|
49
|
-
node_2.letter = :a
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns true' do
|
53
|
-
expect(node_1).to eq node_2
|
42
|
+
expect(node_one).to eq node_two
|
54
43
|
end
|
55
44
|
end
|
56
45
|
|
57
46
|
context 'when the nodes have the same letter but are not both terminal' do
|
58
47
|
before do
|
59
|
-
|
60
|
-
|
48
|
+
node_one.letter = :a
|
49
|
+
node_one.terminal!
|
61
50
|
|
62
|
-
|
51
|
+
node_two.letter = :a
|
63
52
|
end
|
53
|
+
|
64
54
|
it 'returns false' do
|
65
|
-
expect(
|
55
|
+
expect(node_one).not_to eq node_two
|
66
56
|
end
|
67
57
|
end
|
68
58
|
|
69
59
|
context 'when the nodes have the same letter and the same children' do
|
70
60
|
before do
|
71
|
-
|
72
|
-
add_words
|
61
|
+
node_one.letter = :t
|
62
|
+
add_words node_one, %w(hese hree hings)
|
73
63
|
|
74
|
-
|
75
|
-
add_words
|
64
|
+
node_two.letter = :t
|
65
|
+
add_words node_two, %w(hese hree hings)
|
76
66
|
end
|
77
67
|
|
78
68
|
it 'returns true' do
|
79
|
-
expect(
|
69
|
+
expect(node_one).to eq node_two
|
80
70
|
end
|
81
71
|
end
|
82
72
|
|
83
73
|
context 'when the nodes have the same letter but different children' do
|
84
74
|
before do
|
85
|
-
|
86
|
-
add_words
|
75
|
+
node_one.letter = :t
|
76
|
+
add_words node_one, %w(hese wo)
|
87
77
|
|
88
|
-
|
89
|
-
add_words
|
78
|
+
node_two.letter = :t
|
79
|
+
add_words node_two, %w(hese hree hings)
|
90
80
|
end
|
91
81
|
|
92
82
|
it 'returns false' do
|
93
|
-
expect(
|
83
|
+
expect(node_one).not_to eq node_two
|
94
84
|
end
|
95
85
|
end
|
96
86
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Rambling::Trie::Compressor do
|
6
|
-
let(:compressor) {
|
6
|
+
let(:compressor) { described_class.new }
|
7
7
|
|
8
8
|
describe '#compress' do
|
9
9
|
let(:node) { Rambling::Trie::Nodes::Raw.new }
|
@@ -16,9 +16,7 @@ describe Rambling::Trie::Compressor do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with at least one word' do
|
19
|
-
before
|
20
|
-
add_words node, %w(all the words)
|
21
|
-
end
|
19
|
+
before { add_words node, %w(all the words) }
|
22
20
|
|
23
21
|
it 'keeps the node letter nil' do
|
24
22
|
compressed = compressor.compress node
|
@@ -28,25 +26,25 @@ describe Rambling::Trie::Compressor do
|
|
28
26
|
end
|
29
27
|
|
30
28
|
context 'with a single word' do
|
31
|
-
before
|
32
|
-
add_word node, 'all'
|
33
|
-
end
|
29
|
+
before { add_word node, 'all' }
|
34
30
|
|
31
|
+
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
|
35
32
|
it 'compresses into a single node without children' do
|
36
33
|
compressed = compressor.compress node
|
34
|
+
compressed_node_a = compressed[:a]
|
37
35
|
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
36
|
+
expect(compressed_node_a.letter).to eq :all
|
37
|
+
expect(compressed_node_a.children.size).to eq 0
|
38
|
+
expect(compressed_node_a).to be_terminal
|
39
|
+
expect(compressed_node_a).to be_compressed
|
42
40
|
end
|
41
|
+
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
|
43
42
|
end
|
44
43
|
|
45
44
|
context 'with two words' do
|
46
|
-
before
|
47
|
-
add_words node, %w(all ask)
|
48
|
-
end
|
45
|
+
before { add_words node, %w(all ask) }
|
49
46
|
|
47
|
+
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
|
50
48
|
it 'compresses into corresponding three nodes' do
|
51
49
|
compressed = compressor.compress node
|
52
50
|
|
@@ -65,8 +63,10 @@ describe Rambling::Trie::Compressor do
|
|
65
63
|
expect(compressed[:a][:l]).to be_compressed
|
66
64
|
expect(compressed[:a][:s]).to be_compressed
|
67
65
|
end
|
66
|
+
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
|
68
67
|
end
|
69
68
|
|
69
|
+
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
|
70
70
|
it 'reassigns the parent nodes correctly' do
|
71
71
|
add_words node, %w(repay rest repaint)
|
72
72
|
compressed = compressor.compress node
|
@@ -91,7 +91,9 @@ describe Rambling::Trie::Compressor do
|
|
91
91
|
expect(compressed[:r][:p][:i].parent).to eq compressed[:r][:p]
|
92
92
|
expect(compressed[:r][:p][:i].children.size).to eq 0
|
93
93
|
end
|
94
|
+
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
|
94
95
|
|
96
|
+
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
|
95
97
|
it 'does not compress terminal nodes' do
|
96
98
|
add_words node, %w(you your yours)
|
97
99
|
compressed = compressor.compress node
|
@@ -104,5 +106,6 @@ describe Rambling::Trie::Compressor do
|
|
104
106
|
expect(compressed[:y][:r][:s].letter).to eq :s
|
105
107
|
expect(compressed[:y][:r][:s]).to be_compressed
|
106
108
|
end
|
109
|
+
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
|
107
110
|
end
|
108
111
|
end
|
@@ -3,13 +3,17 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Rambling::Trie::Configuration::Properties do
|
6
|
-
let(:properties) {
|
6
|
+
let(:properties) { described_class.new }
|
7
7
|
|
8
8
|
describe '.new' do
|
9
|
-
it 'configures the
|
9
|
+
it 'configures the serializer formats' do
|
10
10
|
serializers = properties.serializers
|
11
|
-
|
12
11
|
expect(serializers.formats).to match_array %i(marshal yaml yml zip)
|
12
|
+
end
|
13
|
+
|
14
|
+
# rubocop:disable RSpec/ExampleLength
|
15
|
+
it 'configures the serializer providers' do
|
16
|
+
serializers = properties.serializers
|
13
17
|
expect(serializers.providers.to_a).to match_array [
|
14
18
|
[:marshal, Rambling::Trie::Serializers::Marshal],
|
15
19
|
[:yaml, Rambling::Trie::Serializers::Yaml],
|
@@ -17,11 +21,15 @@ describe Rambling::Trie::Configuration::Properties do
|
|
17
21
|
[:zip, Rambling::Trie::Serializers::Zip],
|
18
22
|
]
|
19
23
|
end
|
24
|
+
# rubocop:enable RSpec/ExampleLength
|
20
25
|
|
21
|
-
it 'configures the
|
26
|
+
it 'configures the reader formats' do
|
22
27
|
readers = properties.readers
|
23
|
-
|
24
28
|
expect(readers.formats).to match_array %i(txt)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'configures the reader providers' do
|
32
|
+
readers = properties.readers
|
25
33
|
expect(readers.providers.to_a).to match_array [
|
26
34
|
[:txt, Rambling::Trie::Readers::PlainText],
|
27
35
|
]
|
@@ -44,14 +52,24 @@ describe Rambling::Trie::Configuration::Properties do
|
|
44
52
|
properties.readers.add :test, 'test'
|
45
53
|
end
|
46
54
|
|
47
|
-
|
55
|
+
# rubocop:disable RSpec/MultipleExpectations
|
56
|
+
it 'resets the serializers to initial values' do
|
48
57
|
expect(properties.serializers.formats).to include :test
|
49
|
-
expect(properties.readers.formats).to include :test
|
50
58
|
|
51
59
|
properties.reset
|
52
60
|
|
53
61
|
expect(properties.serializers.formats).not_to include :test
|
62
|
+
end
|
63
|
+
# rubocop:enable RSpec/MultipleExpectations
|
64
|
+
|
65
|
+
# rubocop:disable RSpec/MultipleExpectations
|
66
|
+
it 'resets the readers to initial values' do
|
67
|
+
expect(properties.readers.formats).to include :test
|
68
|
+
|
69
|
+
properties.reset
|
70
|
+
|
54
71
|
expect(properties.readers.formats).not_to include :test
|
55
72
|
end
|
73
|
+
# rubocop:enable RSpec/MultipleExpectations
|
56
74
|
end
|
57
75
|
end
|
@@ -4,15 +4,19 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Rambling::Trie::Configuration::ProviderCollection do
|
6
6
|
let(:configured_default) { nil }
|
7
|
-
let
|
7
|
+
let :configured_providers do
|
8
8
|
{ one: first_provider, two: second_provider }
|
9
9
|
end
|
10
10
|
|
11
|
-
let
|
12
|
-
|
11
|
+
let :first_provider do
|
12
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :first_provider
|
13
|
+
end
|
14
|
+
let :second_provider do
|
15
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :second_provider
|
16
|
+
end
|
13
17
|
|
14
|
-
let
|
15
|
-
|
18
|
+
let :provider_collection do
|
19
|
+
described_class.new(
|
16
20
|
:provider,
|
17
21
|
configured_providers,
|
18
22
|
configured_default,
|
@@ -46,25 +50,31 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
46
50
|
let(:providers) { provider_collection.providers }
|
47
51
|
|
48
52
|
before do
|
49
|
-
allow(providers)
|
53
|
+
allow(providers).to receive_messages(
|
50
54
|
:[] => 'value',
|
51
55
|
keys: %i(a b),
|
52
56
|
)
|
53
57
|
end
|
54
58
|
|
59
|
+
# rubocop:disable RSpec/MultipleExpectations
|
55
60
|
it 'delegates `#[]` to providers' do
|
56
61
|
expect(provider_collection[:key]).to eq 'value'
|
57
62
|
expect(providers).to have_received(:[]).with :key
|
58
63
|
end
|
64
|
+
# rubocop:enable RSpec/MultipleExpectations
|
59
65
|
|
66
|
+
# rubocop:disable RSpec/MultipleExpectations
|
60
67
|
it 'aliases `#formats` to `providers#keys`' do
|
61
68
|
expect(provider_collection.formats).to eq %i(a b)
|
62
69
|
expect(providers).to have_received :keys
|
63
70
|
end
|
71
|
+
# rubocop:enable RSpec/MultipleExpectations
|
64
72
|
end
|
65
73
|
|
66
74
|
describe '#add' do
|
67
|
-
let
|
75
|
+
let :provider do
|
76
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :provider
|
77
|
+
end
|
68
78
|
|
69
79
|
before do
|
70
80
|
provider_collection.add :three, provider
|
@@ -76,7 +86,9 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
76
86
|
end
|
77
87
|
|
78
88
|
describe '#default=' do
|
79
|
-
let
|
89
|
+
let :other_provider do
|
90
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :other_provider
|
91
|
+
end
|
80
92
|
|
81
93
|
context 'when the given value is in the providers list' do
|
82
94
|
it 'changes the default provider' do
|
@@ -106,43 +118,59 @@ describe Rambling::Trie::Configuration::ProviderCollection do
|
|
106
118
|
expect(provider_collection.default).to be_nil
|
107
119
|
end
|
108
120
|
|
121
|
+
# rubocop:disable RSpec/MultipleExpectations
|
109
122
|
it 'raises an ArgumentError for any other provider' do
|
110
123
|
expect do
|
111
124
|
provider_collection.default = other_provider
|
112
125
|
end.to raise_error ArgumentError
|
113
126
|
expect(provider_collection.default).to be_nil
|
114
127
|
end
|
128
|
+
# rubocop:enable RSpec/MultipleExpectations
|
115
129
|
end
|
116
130
|
end
|
117
131
|
|
118
132
|
describe '#resolve' do
|
119
133
|
context 'when the file extension is one of the providers' do
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
[
|
135
|
+
['hola.one', :first_provider],
|
136
|
+
['hola.two', :second_provider],
|
137
|
+
].each do |test_params|
|
138
|
+
filepath, provider = test_params
|
139
|
+
|
140
|
+
it 'returns the corresponding provider' do
|
141
|
+
provider_instance = public_send provider
|
142
|
+
expect(provider_collection.resolve filepath).to eq provider_instance
|
143
|
+
end
|
123
144
|
end
|
124
145
|
end
|
125
146
|
|
126
147
|
context 'when the file extension is not one of the providers' do
|
127
|
-
|
128
|
-
|
129
|
-
|
148
|
+
%w(hola.unknown hola).each do |filepath|
|
149
|
+
it 'returns the default provider' do
|
150
|
+
expect(provider_collection.resolve filepath).to eq first_provider
|
151
|
+
end
|
130
152
|
end
|
131
153
|
end
|
132
154
|
end
|
133
155
|
|
134
156
|
describe '#reset' do
|
135
157
|
let(:configured_default) { second_provider }
|
136
|
-
let
|
158
|
+
let :provider do
|
159
|
+
instance_double 'Rambling::Trie::Serializers::Marshal', :provider
|
160
|
+
end
|
137
161
|
|
138
162
|
before do
|
139
163
|
provider_collection.add :three, provider
|
140
164
|
provider_collection.default = provider
|
141
165
|
end
|
142
166
|
|
143
|
-
it 'resets to back to the initially configured values' do
|
167
|
+
it 'resets to back to the initially configured values (:three => nil)' do
|
144
168
|
provider_collection.reset
|
145
169
|
expect(provider_collection[:three]).to be_nil
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'resets to back to the initially configured default' do
|
173
|
+
provider_collection.reset
|
146
174
|
expect(provider_collection.default).to eq second_provider
|
147
175
|
end
|
148
176
|
end
|