LittleWeasel 5.0.4 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +16 -0
- data/.rubocop.yml +9 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +44 -32
- data/LittleWeasel.gemspec +5 -5
- data/lib/LittleWeasel/dictionary.rb +1 -1
- data/lib/LittleWeasel/errors/dictionary_file_too_large_error.rb +1 -1
- data/lib/LittleWeasel/metadata/metadata_observable_validatable.rb +1 -1
- data/lib/LittleWeasel/version.rb +1 -1
- data/spec/factories/dictionary.rb +27 -27
- data/spec/factories/dictionary_cache_service.rb +4 -6
- data/spec/factories/dictionary_creator_service.rb +1 -1
- data/spec/factories/dictionary_file_loader_service.rb +1 -1
- data/spec/factories/dictionary_hash.rb +26 -26
- data/spec/factories/dictionary_key.rb +1 -1
- data/spec/factories/dictionary_killer_service.rb +1 -1
- data/spec/factories/dictionary_manager.rb +1 -1
- data/spec/factories/dictionary_metadata.rb +1 -1
- data/spec/factories/dictionary_metadata_service.rb +1 -1
- data/spec/factories/numeric_filter.rb +1 -1
- data/spec/factories/preprocessed_word.rb +1 -1
- data/spec/factories/preprocessed_words.rb +1 -1
- data/spec/factories/single_character_word_filter.rb +1 -1
- data/spec/factories/word_results.rb +1 -1
- data/spec/lib/LittleWeasel/block_results_spec.rb +23 -23
- data/spec/lib/LittleWeasel/configure_spec.rb +3 -3
- data/spec/lib/LittleWeasel/dictionary_key_spec.rb +9 -9
- data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +29 -29
- data/spec/lib/LittleWeasel/dictionary_spec.rb +30 -29
- data/spec/lib/LittleWeasel/filters/en_us/currency_filter_spec.rb +26 -26
- data/spec/lib/LittleWeasel/filters/en_us/numeric_filter_spec.rb +17 -17
- data/spec/lib/LittleWeasel/filters/en_us/single_character_word_filter_spec.rb +8 -8
- data/spec/lib/LittleWeasel/filters/word_filter_managable_spec.rb +19 -19
- data/spec/lib/LittleWeasel/filters/word_filter_spec.rb +17 -17
- data/spec/lib/LittleWeasel/filters/word_filter_validatable_spec.rb +27 -12
- data/spec/lib/LittleWeasel/filters/word_filters_validatable_spec.rb +6 -6
- data/spec/lib/LittleWeasel/integraton_tests/dictionary_integration_spec.rb +23 -23
- data/spec/lib/LittleWeasel/metadata/dictionary_creator_servicable_spec.rb +7 -6
- data/spec/lib/LittleWeasel/metadata/dictionary_metadata_spec.rb +13 -13
- data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +17 -17
- data/spec/lib/LittleWeasel/metadata/metadata_observerable_spec.rb +1 -1
- data/spec/lib/LittleWeasel/modules/dictionary_file_loader_spec.rb +30 -30
- data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +21 -21
- data/spec/lib/LittleWeasel/modules/language_spec.rb +5 -5
- data/spec/lib/LittleWeasel/modules/locale_spec.rb +1 -1
- data/spec/lib/LittleWeasel/modules/region_spec.rb +5 -5
- data/spec/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor_spec.rb +8 -6
- data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_spec.rb +3 -3
- data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_validatable_spec.rb +14 -3
- data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_spec.rb +8 -10
- data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_validatable_spec.rb +6 -4
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +27 -28
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +25 -29
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_validatable_spec.rb +10 -2
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessors_validatable_spec.rb +4 -6
- data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +51 -49
- data/spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb +14 -14
- data/spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb +30 -30
- data/spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb +22 -22
- data/spec/lib/LittleWeasel/word_results_spec.rb +29 -32
- data/spec/lib/LittleWeasel/workflow/workflow_spec.rb +2 -2
- data/spec/spec_helper.rb +56 -56
- data/spec/support/factory_bot.rb +1 -2
- data/spec/support/file_helpers.rb +2 -2
- data/spec/support/general_helpers.rb +2 -1
- data/spec/support/shared_contexts.rb +13 -9
- data/spec/support/shared_examples.rb +10 -8
- metadata +26 -19
@@ -11,10 +11,10 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
11
11
|
|
12
12
|
let(:original_word_block) { 'Original word block' }
|
13
13
|
|
14
|
-
|
14
|
+
# .new
|
15
15
|
describe '.new' do
|
16
16
|
it 'instantiates an object' do
|
17
|
-
expect { subject }.
|
17
|
+
expect { subject }.not_to raise_error
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'initializes #word_results to an empty Array' do
|
@@ -26,7 +26,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
# <<
|
30
30
|
describe '<<' do
|
31
31
|
context 'with an invalid argument' do
|
32
32
|
it 'raises an error' do
|
@@ -42,7 +42,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
#success?
|
45
|
+
# success?
|
46
46
|
describe '#success?' do
|
47
47
|
before do
|
48
48
|
subject << ceate_word_results(word: 'word01', word_valid: true)
|
@@ -81,7 +81,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
#words_valid?
|
84
|
+
# words_valid?
|
85
85
|
describe '#words_valid?' do
|
86
86
|
before do
|
87
87
|
subject << ceate_word_results(word: 'word01', word_valid: true)
|
@@ -105,7 +105,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
#filters_match?
|
108
|
+
# filters_match?
|
109
109
|
describe '#filters_match?' do
|
110
110
|
before do
|
111
111
|
subject << ceate_word_results(word: 'word01', filters_matched: [:matched_filter])
|
@@ -129,7 +129,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
#preprocessed_words?
|
132
|
+
# preprocessed_words?
|
133
133
|
describe '#preprocessed_words?' do
|
134
134
|
before do
|
135
135
|
subject << ceate_word_results(word: word, preprocessed_words: preprocessed_words)
|
@@ -145,7 +145,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
#preprocessed_words_or_original_words
|
148
|
+
# preprocessed_words_or_original_words
|
149
149
|
describe '#preprocessed_words_or_original_words' do
|
150
150
|
context 'with all preprocessed words' do
|
151
151
|
before do
|
@@ -153,16 +153,16 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
153
153
|
subject << ceate_word_results(word: words[1], preprocessed_words: preprocessed_words[1])
|
154
154
|
end
|
155
155
|
|
156
|
-
let(:words) { %w
|
156
|
+
let(:words) { %w[word1 word2] }
|
157
157
|
let(:preprocessed_words) do
|
158
158
|
[
|
159
|
-
|
160
|
-
|
159
|
+
create(:preprocessed_words, original_word: words[0], with_word_processors: 1),
|
160
|
+
create(:preprocessed_words, original_word: words[1], with_word_processors: 2)
|
161
161
|
]
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'returns all the preprocessed words' do
|
165
|
-
expect(subject.preprocessed_words_or_original_words).to eq %w
|
165
|
+
expect(subject.preprocessed_words_or_original_words).to eq %w[word1-0 word2-0-1]
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -172,10 +172,10 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
172
172
|
subject << ceate_word_results(word: words[1])
|
173
173
|
end
|
174
174
|
|
175
|
-
let(:words) { %w
|
175
|
+
let(:words) { %w[word1 word2] }
|
176
176
|
|
177
177
|
it 'returns all the original words' do
|
178
|
-
expect(subject.preprocessed_words_or_original_words).to eq %w
|
178
|
+
expect(subject.preprocessed_words_or_original_words).to eq %w[word1 word2]
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
@@ -187,21 +187,21 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
187
187
|
subject << ceate_word_results(word: words[3], word_valid: true, preprocessed_words: preprocessed_words[1])
|
188
188
|
end
|
189
189
|
|
190
|
-
let(:words) { %w
|
190
|
+
let(:words) { %w[word0 word1 word2 word3] }
|
191
191
|
let(:preprocessed_words) do
|
192
192
|
[
|
193
|
-
|
194
|
-
|
193
|
+
create(:preprocessed_words, original_word: words[1], with_word_processors: 1),
|
194
|
+
create(:preprocessed_words, original_word: words[3], with_word_processors: 2)
|
195
195
|
]
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'returns all the original and preprocessed words' do
|
199
|
-
expect(subject.preprocessed_words_or_original_words).to eq %w
|
199
|
+
expect(subject.preprocessed_words_or_original_words).to eq %w[word0 word1-0 word2 word3-0-1]
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
#words_cached?
|
204
|
+
# words_cached?
|
205
205
|
describe '#words_cached?' do
|
206
206
|
before do
|
207
207
|
subject << ceate_word_results(word: words[0])
|
@@ -210,7 +210,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
210
210
|
subject << ceate_word_results(word: words[3])
|
211
211
|
end
|
212
212
|
|
213
|
-
let(:words) { %w
|
213
|
+
let(:words) { %w[word1 word2 word3 word4] }
|
214
214
|
|
215
215
|
context 'when all the words are cached' do
|
216
216
|
before do
|
@@ -218,7 +218,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
218
218
|
end
|
219
219
|
|
220
220
|
it 'returns true' do
|
221
|
-
expect(subject.words_cached?).to
|
221
|
+
expect(subject.words_cached?).to be true
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -231,7 +231,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'returns false' do
|
234
|
-
expect(subject.words_cached?).to
|
234
|
+
expect(subject.words_cached?).to be false
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
@@ -241,7 +241,7 @@ RSpec.describe LittleWeasel::BlockResults do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'returns false' do
|
244
|
-
expect(subject.words_cached?).to
|
244
|
+
expect(subject.words_cached?).to be false
|
245
245
|
end
|
246
246
|
end
|
247
247
|
end
|
@@ -31,12 +31,12 @@ RSpec.describe LittleWeasel do
|
|
31
31
|
|
32
32
|
describe '#word_block_regex' do
|
33
33
|
it 'set to the default regex to split work blocks by default' do
|
34
|
-
expect(subject.word_block_regex).to eq
|
34
|
+
expect(subject.word_block_regex).to eq(/[[[:word:]]'-]+/)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
# .configuration
|
40
40
|
describe '.configuration' do
|
41
41
|
context 'when passing a block' do
|
42
42
|
subject do
|
@@ -49,7 +49,7 @@ RSpec.describe LittleWeasel do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
let(:max_dictionary_file_megabytes) { 1_222_333 }
|
52
|
-
let(:metadata_observers) { %i
|
52
|
+
let(:metadata_observers) { %i[observer0 observer1] }
|
53
53
|
let(:word_block_regex) { :word_block_regex }
|
54
54
|
|
55
55
|
describe '#max_dictionary_file_megabytes=' do
|
@@ -9,15 +9,15 @@ RSpec.describe LittleWeasel::DictionaryKey, type: :class do
|
|
9
9
|
let(:region) {}
|
10
10
|
let(:tag) {}
|
11
11
|
|
12
|
-
|
12
|
+
# .new
|
13
13
|
describe '.new' do
|
14
14
|
context 'when passing valid arguments' do
|
15
15
|
let(:language) { :EN }
|
16
16
|
let(:region) { :us }
|
17
|
-
let(:tag) { :TAGGED}
|
17
|
+
let(:tag) { :TAGGED }
|
18
18
|
|
19
19
|
it 'instantiates the object' do
|
20
|
-
expect { subject }.
|
20
|
+
expect { subject }.not_to raise_error
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'normalizes language and converts it to lowercase' do
|
@@ -51,18 +51,18 @@ RSpec.describe LittleWeasel::DictionaryKey, type: :class do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
# .key
|
55
55
|
describe '.key' do
|
56
56
|
let(:language) { :xx }
|
57
57
|
let(:region) { :yy }
|
58
58
|
let(:tag) { :zz }
|
59
59
|
|
60
60
|
it 'returns the locale' do
|
61
|
-
expect(described_class.key
|
61
|
+
expect(described_class.key(language: language, region: region, tag: tag)).to eq 'xx-YY-zz'
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
#key
|
65
|
+
# key
|
66
66
|
describe '#key' do
|
67
67
|
context 'with no tag' do
|
68
68
|
context 'with language' do
|
@@ -77,7 +77,7 @@ RSpec.describe LittleWeasel::DictionaryKey, type: :class do
|
|
77
77
|
let(:language) { :EN }
|
78
78
|
let(:region) { :us }
|
79
79
|
|
80
|
-
it 'returns the key in the form of a locale String that includes language and region
|
80
|
+
it 'returns the key in the form of a locale String that includes language and region (e.g. "en-US")' do
|
81
81
|
expect(subject.key).to eq 'en-US'
|
82
82
|
end
|
83
83
|
end
|
@@ -98,14 +98,14 @@ RSpec.describe LittleWeasel::DictionaryKey, type: :class do
|
|
98
98
|
let(:language) { :EN }
|
99
99
|
let(:region) { :us }
|
100
100
|
|
101
|
-
it 'returns the key in the form of a locale String that includes language, region and the appended tag
|
101
|
+
it 'returns the key in the form of a locale String that includes language, region and the appended tag (e.g. "en-US-tag")' do
|
102
102
|
expect(subject.key).to eq 'en-US-tagged'
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
#to_s
|
108
|
+
# to_s
|
109
109
|
describe '#to_s' do
|
110
110
|
let(:language) { :en }
|
111
111
|
let(:region) { :us }
|
@@ -3,12 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::DictionaryManager do
|
6
|
-
include_context 'dictionary keys'
|
7
|
-
|
8
6
|
subject { create(:dictionary_manager) }
|
9
7
|
|
10
|
-
|
11
|
-
|
8
|
+
include_context 'dictionary keys'
|
9
|
+
|
10
|
+
let(:dictionary_cache_service) { create(:dictionary_cache_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache) }
|
11
|
+
let(:dictionary_metadata_service) { create(:dictionary_metadata_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata) }
|
12
12
|
let(:dictionary_key) { create(:dictionary_key, language: language, region: region, tag: tag) }
|
13
13
|
let(:dictionary_cache) { subject.dictionary_cache }
|
14
14
|
let(:dictionary_metadata) { subject.dictionary_metadata }
|
@@ -22,28 +22,28 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
22
22
|
dictionary_cache_service.dictionary_object.dictionary_metadata_object.observers.keys.first
|
23
23
|
end
|
24
24
|
|
25
|
-
before
|
25
|
+
before do
|
26
26
|
subject.init
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
# .new
|
30
30
|
describe '.new' do
|
31
31
|
it 'does not raise an error' do
|
32
32
|
expect { subject }.not_to raise_error
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
#dictionary_exist?
|
36
|
+
# dictionary_exist?
|
37
37
|
describe '#dictionary_exist?' do
|
38
38
|
let!(:expected_dictionary_object) do
|
39
39
|
subject.create_dictionary_from_memory(dictionary_key: dictionary_key,
|
40
|
-
|
40
|
+
dictionary_words: %w[My dictionary words])
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'when the dictionary exists' do
|
44
44
|
it 'returns true' do
|
45
|
-
expect(subject.dictionary_exist?
|
46
|
-
.to
|
45
|
+
expect(subject.dictionary_exist?(dictionary_key: dictionary_key))
|
46
|
+
.to be true
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,22 +51,22 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
51
51
|
let(:en_gb_dictionary_key) { dictionary_key_for(language: :en, region: :gb) }
|
52
52
|
|
53
53
|
it 'returns false' do
|
54
|
-
expect(subject.dictionary_exist?
|
55
|
-
.to
|
54
|
+
expect(subject.dictionary_exist?(dictionary_key: en_gb_dictionary_key))
|
55
|
+
.to be false
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
#dictionary_for
|
60
|
+
# dictionary_for
|
61
61
|
describe '#dictionary_for' do
|
62
62
|
let!(:expected_dictionary_object) do
|
63
63
|
subject.create_dictionary_from_memory(dictionary_key: dictionary_key,
|
64
|
-
|
64
|
+
dictionary_words: %w[My dictionary words])
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'when the dictionary exists' do
|
68
68
|
it 'returns the dictionary object' do
|
69
|
-
expect(subject.dictionary_for
|
69
|
+
expect(subject.dictionary_for(dictionary_key: dictionary_key))
|
70
70
|
.to be expected_dictionary_object
|
71
71
|
end
|
72
72
|
end
|
@@ -81,11 +81,11 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
#create_dictionary_from_file
|
84
|
+
# create_dictionary_from_file
|
85
85
|
describe '#create_dictionary_from_file' do
|
86
86
|
context 'when the dictionary DOES NOT exist' do
|
87
87
|
it 'creates a dictionary and returns a dictionary object' do
|
88
|
-
expect(subject.create_dictionary_from_file(dictionary_key: dictionary_key, file: file)).to
|
88
|
+
expect(subject.create_dictionary_from_file(dictionary_key: dictionary_key, file: file)).to be_a LittleWeasel::Dictionary
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -101,15 +101,15 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
#create_dictionary_from_memory
|
104
|
+
# create_dictionary_from_memory
|
105
105
|
describe '#create_dictionary_from_memory' do
|
106
106
|
let(:dictionary_words) { dictionary_words_for(dictionary_file_path: file) }
|
107
107
|
|
108
108
|
context 'when the dictionary reference does not exist and the dictionary is not cached' do
|
109
109
|
it 'adds a dictionary reference caches the dictionary and returns a dictionary object' do
|
110
|
-
expect(subject.create_dictionary_from_memory(dictionary_key: dictionary_key, dictionary_words: dictionary_words)).to
|
111
|
-
expect(dictionary_cache_service.dictionary_reference?).to
|
112
|
-
expect(dictionary_cache_service.dictionary_object?).to
|
110
|
+
expect(subject.create_dictionary_from_memory(dictionary_key: dictionary_key, dictionary_words: dictionary_words)).to be_a LittleWeasel::Dictionary
|
111
|
+
expect(dictionary_cache_service.dictionary_reference?).to be true
|
112
|
+
expect(dictionary_cache_service.dictionary_object?).to be true
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -125,7 +125,7 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
#kill
|
128
|
+
# kill
|
129
129
|
describe '#kill_dictionary' do
|
130
130
|
context 'dictionaries created from files' do
|
131
131
|
before do
|
@@ -135,9 +135,9 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
135
135
|
it 'removes the dictionary, file source reference and metadata from the dictionary cache' do
|
136
136
|
metadata_key # Capture this before we unload the dictionary
|
137
137
|
subject.kill_dictionary(dictionary_key: dictionary_key)
|
138
|
-
expect(dictionary_cache_service.dictionary_exist?).to
|
139
|
-
expect(dictionary_cache_service.dictionary_reference?).to
|
140
|
-
expect(dictionary_metadata_service.dictionary_metadata?(metadata_key: metadata_key)).to
|
138
|
+
expect(dictionary_cache_service.dictionary_exist?).to be false
|
139
|
+
expect(dictionary_cache_service.dictionary_reference?).to be false
|
140
|
+
expect(dictionary_metadata_service.dictionary_metadata?(metadata_key: metadata_key)).to be false
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'returns the dictionary manager instance' do
|
@@ -147,15 +147,15 @@ RSpec.describe LittleWeasel::DictionaryManager do
|
|
147
147
|
|
148
148
|
context 'dictionaries created from memory' do
|
149
149
|
before do
|
150
|
-
subject.create_dictionary_from_memory(dictionary_key: dictionary_key, dictionary_words: %w
|
150
|
+
subject.create_dictionary_from_memory(dictionary_key: dictionary_key, dictionary_words: %w[Abel Cain Deborah Elijah])
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'removes the dictionary, memory source reference and metadata from the dictionary cache' do
|
154
154
|
metadata_key # Capture this before we unload the dictionary
|
155
155
|
subject.kill_dictionary(dictionary_key: dictionary_key)
|
156
|
-
expect(dictionary_cache_service.dictionary_exist?).to
|
157
|
-
expect(dictionary_cache_service.dictionary_reference?).to
|
158
|
-
expect(dictionary_metadata_service.dictionary_metadata?(metadata_key: metadata_key)).to
|
156
|
+
expect(dictionary_cache_service.dictionary_exist?).to be false
|
157
|
+
expect(dictionary_cache_service.dictionary_reference?).to be false
|
158
|
+
expect(dictionary_metadata_service.dictionary_metadata?(metadata_key: metadata_key)).to be false
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'returns the dictionary manager instance' do
|
@@ -3,16 +3,17 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::Dictionary do
|
6
|
+
subject { create(:dictionary, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_words: dictionary_words, word_filters: word_filters) }
|
7
|
+
|
6
8
|
include_context 'dictionary keys'
|
7
9
|
include_context 'mock word filters'
|
8
10
|
|
9
11
|
DictionaryResultsHelpers = Support::GeneralHelpers::DictionaryResultsHelpers
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
before { dictionary_cache_service }
|
13
|
+
before do
|
14
|
+
LittleWeasel.configure(&:reset)
|
15
|
+
dictionary_cache_service
|
16
|
+
end
|
16
17
|
|
17
18
|
let(:dictionary_cache_service) { create(:dictionary_cache_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_file_source: dictionary_key.key) }
|
18
19
|
let(:dictionary_key) { dictionary_key_for(language: :en, region: :us, tag: :big) }
|
@@ -29,11 +30,11 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
29
30
|
[word_results.present?, word_results&.word_valid]
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
+
# .new
|
33
34
|
describe '.new' do
|
34
35
|
context 'with a valid dictionary words Array' do
|
35
36
|
it 'instantiates without error' do
|
36
|
-
expect { subject }.
|
37
|
+
expect { subject }.not_to raise_error
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -82,23 +83,23 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
+
# .to_hash
|
86
87
|
describe '.to_hash' do
|
87
88
|
let(:expected_hash) do
|
88
89
|
{
|
89
|
-
'this' => true,
|
90
|
-
'is' => true,
|
91
|
-
'a' => true,
|
92
|
-
'test' => true
|
90
|
+
'this' => true, # rubocop:disable Style/StringHashKeys
|
91
|
+
'is' => true, # rubocop:disable Style/StringHashKeys
|
92
|
+
'a' => true, # rubocop:disable Style/StringHashKeys
|
93
|
+
'test' => true # rubocop:disable Style/StringHashKeys
|
93
94
|
}
|
94
95
|
end
|
95
96
|
|
96
97
|
it 'returns a Hash of dictionary words' do
|
97
|
-
expect(described_class.to_hash(dictionary_words: %w
|
98
|
+
expect(described_class.to_hash(dictionary_words: %w[this is a test])).to eq expected_hash
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
|
-
#detached?
|
102
|
+
# detached?
|
102
103
|
describe '#detached?' do
|
103
104
|
before do
|
104
105
|
subject
|
@@ -109,8 +110,8 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
109
110
|
context 'when the dictionary object is in the dictionary cache' do
|
110
111
|
it 'returns false' do
|
111
112
|
dictionary_cache_service
|
112
|
-
expect(dictionary_cache_service.dictionary_object?).to
|
113
|
-
expect(subject.detached?).to
|
113
|
+
expect(dictionary_cache_service.dictionary_object?).to be true
|
114
|
+
expect(subject.detached?).to be false
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
@@ -122,20 +123,20 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
122
123
|
end
|
123
124
|
|
124
125
|
it 'returns true' do
|
125
|
-
expect(dictionary_cache_service.dictionary_object?).to
|
126
|
-
expect(subject.detached?).to
|
126
|
+
expect(dictionary_cache_service.dictionary_object?).to be false
|
127
|
+
expect(subject.detached?).to be true
|
127
128
|
end
|
128
129
|
end
|
129
130
|
end
|
130
131
|
|
131
|
-
#key
|
132
|
+
# key
|
132
133
|
describe '#key' do
|
133
134
|
it 'returns the expected key' do
|
134
135
|
expect(subject.key).to eq dictionary_key.key
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
|
-
#count
|
139
|
+
# count
|
139
140
|
describe '#count' do
|
140
141
|
before do
|
141
142
|
subject.word_results('badword')
|
@@ -146,7 +147,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
149
|
-
#count_all_words
|
150
|
+
# count_all_words
|
150
151
|
describe '#count_all_words' do
|
151
152
|
before do
|
152
153
|
subject.word_results('badword')
|
@@ -157,7 +158,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
160
|
-
#count_invalid_words
|
161
|
+
# count_invalid_words
|
161
162
|
describe '#count_invalid_words' do
|
162
163
|
before do
|
163
164
|
subject.word_results('badword')
|
@@ -168,7 +169,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
168
169
|
end
|
169
170
|
end
|
170
171
|
|
171
|
-
#word_results
|
172
|
+
# word_results
|
172
173
|
describe '#word_results' do
|
173
174
|
context 'when argument word is INVALID' do
|
174
175
|
context 'when not a String' do
|
@@ -183,19 +184,19 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
183
184
|
context 'when searching for words in the dictionary' do
|
184
185
|
context 'when the word is found' do
|
185
186
|
it 'returns true' do
|
186
|
-
expect(subject.word_results('dog').success?).to
|
187
|
+
expect(subject.word_results('dog').success?).to be true
|
187
188
|
end
|
188
189
|
end
|
189
190
|
|
190
191
|
context 'when the word is not found' do
|
191
192
|
it 'returns false' do
|
192
|
-
expect(subject.word_results('badword').success?).to
|
193
|
+
expect(subject.word_results('badword').success?).to be false
|
193
194
|
end
|
194
195
|
end
|
195
196
|
end
|
196
197
|
end
|
197
198
|
|
198
|
-
#block_results
|
199
|
+
# block_results
|
199
200
|
describe '#block_results' do
|
200
201
|
context 'when nil is passed' do
|
201
202
|
it 'raises an error' do
|
@@ -250,7 +251,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
250
251
|
context 'when a word is not found' do
|
251
252
|
context 'when the max_invalid_words_bytesize threashold has not been exceeded' do
|
252
253
|
it 'adds the word to the cache' do
|
253
|
-
expect { subject.word_results('badword') }.to change
|
254
|
+
expect { subject.word_results('badword') }.to change(subject, :count_all_words).by(1)
|
254
255
|
end
|
255
256
|
end
|
256
257
|
|
@@ -265,7 +266,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
265
266
|
subject.word_results('IWillBeCached02')
|
266
267
|
subject.word_results('IWontBeCached01')
|
267
268
|
subject.word_results('IWontBeCached02')
|
268
|
-
end.to change
|
269
|
+
end.to change(subject, :count_all_words).by(2)
|
269
270
|
end
|
270
271
|
end
|
271
272
|
end
|
@@ -282,7 +283,7 @@ RSpec.describe LittleWeasel::Dictionary do
|
|
282
283
|
subject.word_results('IWillBeCached02')
|
283
284
|
subject.word_results('IWontBeCached01')
|
284
285
|
subject.word_results('IWontBeCached02')
|
285
|
-
end.
|
286
|
+
end.not_to(change(subject, :count_all_words))
|
286
287
|
end
|
287
288
|
end
|
288
289
|
end
|
@@ -5,48 +5,48 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::EnUs::CurrencyFilter do
|
6
6
|
subject { described_class.new }
|
7
7
|
|
8
|
-
#filter_match?
|
8
|
+
# filter_match?
|
9
9
|
describe 'filter_match?' do
|
10
|
+
let(:word) { 1 }
|
11
|
+
|
10
12
|
context 'when word is currency' do
|
11
13
|
it 'returns true' do
|
12
|
-
expect(subject.filter_match?('-$1.00')).to
|
13
|
-
expect(subject.filter_match?('-$1')).to
|
14
|
-
expect(subject.filter_match?('$0')).to
|
15
|
-
expect(subject.filter_match?('$1')).to
|
16
|
-
expect(subject.filter_match?('$100')).to
|
17
|
-
expect(subject.filter_match?('$100.10')).to
|
18
|
-
expect(subject.filter_match?('$123456')).to
|
19
|
-
expect(subject.filter_match?('+$110.09')).to
|
20
|
-
expect(subject.filter_match?('-$1,000.09')).to
|
21
|
-
expect(subject.filter_match?('$1000000.00')).to
|
22
|
-
expect(subject.filter_match?('$1100000.10')).to
|
23
|
-
expect(subject.filter_match?('$120000.01')).to
|
24
|
-
expect(subject.filter_match?('$1,000,000.01')).to
|
14
|
+
expect(subject.filter_match?('-$1.00')).to be true
|
15
|
+
expect(subject.filter_match?('-$1')).to be true
|
16
|
+
expect(subject.filter_match?('$0')).to be true
|
17
|
+
expect(subject.filter_match?('$1')).to be true
|
18
|
+
expect(subject.filter_match?('$100')).to be true
|
19
|
+
expect(subject.filter_match?('$100.10')).to be true
|
20
|
+
expect(subject.filter_match?('$123456')).to be true
|
21
|
+
expect(subject.filter_match?('+$110.09')).to be true
|
22
|
+
expect(subject.filter_match?('-$1,000.09')).to be true
|
23
|
+
expect(subject.filter_match?('$1000000.00')).to be true
|
24
|
+
expect(subject.filter_match?('$1100000.10')).to be true
|
25
|
+
expect(subject.filter_match?('$120000.01')).to be true
|
26
|
+
expect(subject.filter_match?('$1,000,000.01')).to be true
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
context 'when word has decimals, but not 2 decimal places' do
|
29
31
|
it 'returns false' do
|
30
|
-
expect(subject.filter_match?('-$1.1')).to
|
31
|
-
expect(subject.filter_match?('$0.1')).to
|
32
|
-
expect(subject.filter_match?('$100.9')).to
|
33
|
-
expect(subject.filter_match?('+$100.2')).to
|
34
|
-
expect(subject.filter_match?('$1000000.0')).to
|
35
|
-
expect(subject.filter_match?('$1000000.1')).to
|
36
|
-
expect(subject.filter_match?('$1000000.5')).to
|
32
|
+
expect(subject.filter_match?('-$1.1')).to be false
|
33
|
+
expect(subject.filter_match?('$0.1')).to be false
|
34
|
+
expect(subject.filter_match?('$100.9')).to be false
|
35
|
+
expect(subject.filter_match?('+$100.2')).to be false
|
36
|
+
expect(subject.filter_match?('$1000000.0')).to be false
|
37
|
+
expect(subject.filter_match?('$1000000.1')).to be false
|
38
|
+
expect(subject.filter_match?('$1000000.5')).to be false
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
context 'when word is NOT currency' do
|
41
43
|
it 'returns false' do
|
42
|
-
expect(subject.filter_match?
|
43
|
-
expect(subject.filter_match?
|
44
|
-
expect(subject.filter_match?
|
44
|
+
expect(subject.filter_match?('a')).to be false
|
45
|
+
expect(subject.filter_match?(:a)).to be false
|
46
|
+
expect(subject.filter_match?(Object.new)).to be false
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
let(:word) { 1 }
|
49
|
-
|
50
50
|
context 'when #filter_match? returns true' do
|
51
51
|
before { allow(subject.class).to receive(:filter_match?).and_return(true) }
|
52
52
|
|