LittleWeasel 5.0.5 → 5.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +27 -16
- data/LittleWeasel.gemspec +5 -5
- 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 +25 -19
@@ -3,11 +3,11 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
6
|
+
subject { create(:dictionary_metadata_service, dictionary_key: dictionary_key, dictionary_metadata: dictionary_metadata, dictionary_cache: dictionary_cache) }
|
7
|
+
|
6
8
|
include_context 'dictionary cache'
|
7
9
|
include_context 'dictionary keys'
|
8
10
|
|
9
|
-
subject { create(:dictionary_metadata_service, dictionary_key: dictionary_key, dictionary_metadata: dictionary_metadata, dictionary_cache: dictionary_cache) }
|
10
|
-
|
11
11
|
let(:en_us_dictionary_key) { dictionary_key_for(language: :en, region: :us) }
|
12
12
|
let(:en_gb_dictionary_key) { dictionary_key_for(language: :en, region: :gb) }
|
13
13
|
let(:es_es_dictionary_key) { dictionary_key_for(language: :es, region: :es) }
|
@@ -37,7 +37,7 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe 'class methods' do
|
40
|
-
|
40
|
+
# .init
|
41
41
|
describe '.init' do
|
42
42
|
context 'with a valid dictionary metadata argument' do
|
43
43
|
it 'initializes the dictionary metadata' do
|
@@ -57,20 +57,20 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
# .init?
|
61
61
|
describe '.init?' do
|
62
62
|
context 'with a valid dictionary metadata argument' do
|
63
63
|
context 'when the dictionary metadata is in an initialized state' do
|
64
64
|
let(:dictionary_metadata) { {} }
|
65
65
|
|
66
66
|
it 'returns true' do
|
67
|
-
expect(described_class.init?(dictionary_metadata: dictionary_metadata)).to
|
67
|
+
expect(described_class.init?(dictionary_metadata: dictionary_metadata)).to be true
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'when the dictionary metadata is NOT in an initialized state' do
|
72
72
|
it 'returns false' do
|
73
|
-
expect(described_class.init?(dictionary_metadata: dictionary_metadata)).to
|
73
|
+
expect(described_class.init?(dictionary_metadata: dictionary_metadata)).to be false
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -83,11 +83,11 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
# .new
|
87
87
|
describe '.new' do
|
88
88
|
context 'when the arguments are valid' do
|
89
89
|
it 'instantiates without errors' do
|
90
|
-
expect { subject }.
|
90
|
+
expect { subject }.not_to raise_error
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -96,11 +96,11 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
96
96
|
it_behaves_like 'the dictionary_metadata is invalid'
|
97
97
|
end
|
98
98
|
|
99
|
-
#init
|
99
|
+
# init
|
100
100
|
describe '#init' do
|
101
101
|
let(:expected_dictionary_metadata) do
|
102
102
|
{
|
103
|
-
0 => { :
|
103
|
+
0 => { metadata_key: nil },
|
104
104
|
1 => { metadata_key1: :metadata_object1 }
|
105
105
|
}
|
106
106
|
end
|
@@ -135,7 +135,7 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
#dictionary_metadata?
|
138
|
+
# dictionary_metadata?
|
139
139
|
describe '#dictionary_metadata?' do
|
140
140
|
before do
|
141
141
|
allow(subject).to receive(:dictionary_id).and_return(0)
|
@@ -143,7 +143,7 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
143
143
|
|
144
144
|
context 'when there is dictionary metadata associated with the dictionary for the metadata_key' do
|
145
145
|
it 'returns true' do
|
146
|
-
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to
|
146
|
+
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to be true
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -156,19 +156,19 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'returns false' do
|
159
|
-
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to
|
159
|
+
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to be false
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
context 'when there is no dictionary metadata for the metadata_key' do
|
164
164
|
let(:dictionary_metadata) do
|
165
165
|
{
|
166
|
-
0 => { :
|
166
|
+
0 => { wrong_metadata_key: :metadata_object }
|
167
167
|
}
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'returns false' do
|
171
|
-
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to
|
171
|
+
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to be false
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -180,13 +180,13 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'returns false' do
|
183
|
-
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to
|
183
|
+
expect(subject.dictionary_metadata?(metadata_key: metadata_key)).to be false
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
#get_dictionary_metadata
|
189
|
+
# get_dictionary_metadata
|
190
190
|
describe '#get_dictionary_metadata' do
|
191
191
|
before do
|
192
192
|
allow(subject).to receive(:dictionary_id!).and_return(0)
|
@@ -217,19 +217,19 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
217
217
|
end
|
218
218
|
|
219
219
|
it 'returns false' do
|
220
|
-
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to
|
220
|
+
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to be_nil
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
224
|
context 'when there is no dictionary metadata for the metadata_key' do
|
225
225
|
let(:dictionary_metadata) do
|
226
226
|
{
|
227
|
-
0 => { :
|
227
|
+
0 => { wrong_metadata_key: :metadata_object0 }
|
228
228
|
}
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'returns false' do
|
232
|
-
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to
|
232
|
+
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to be_nil
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -241,13 +241,13 @@ RSpec.describe LittleWeasel::Services::DictionaryMetadataService do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'returns false' do
|
244
|
-
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to
|
244
|
+
expect(subject.get_dictionary_metadata(metadata_key: metadata_key)).to be_nil
|
245
245
|
end
|
246
246
|
end
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
#set_dictionary_metadata
|
250
|
+
# set_dictionary_metadata
|
251
251
|
describe '#set_dictionary_metadata' do
|
252
252
|
before do
|
253
253
|
allow(subject).to receive(:dictionary_id!).and_return(0)
|
@@ -19,11 +19,11 @@ RSpec.describe LittleWeasel::WordResults do
|
|
19
19
|
let(:word_cached) { false }
|
20
20
|
let(:word_valid) { false }
|
21
21
|
|
22
|
-
|
22
|
+
# .new
|
23
23
|
describe '.new' do
|
24
24
|
context 'with valid arguments' do
|
25
25
|
it 'instantiates the object' do
|
26
|
-
expect { subject }.
|
26
|
+
expect { subject }.not_to raise_error
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -70,7 +70,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
#original_word=
|
73
|
+
# original_word=
|
74
74
|
describe '#original_word=' do
|
75
75
|
let(:changed_value) { "#{original_word}-changed" }
|
76
76
|
|
@@ -81,7 +81,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
#filters_matched=
|
84
|
+
# filters_matched=
|
85
85
|
describe '#filters_matched=' do
|
86
86
|
let(:filters_matched) { [:filters_matched] }
|
87
87
|
let(:changed_value) { [:filters_matched_changed] }
|
@@ -93,7 +93,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
#word_cached=
|
96
|
+
# word_cached=
|
97
97
|
describe '#word_cached=' do
|
98
98
|
let(:changed_value) { !word_cached }
|
99
99
|
|
@@ -104,7 +104,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
#word_valid=
|
107
|
+
# word_valid=
|
108
108
|
describe '#word_valid=' do
|
109
109
|
let(:changed_value) { !word_valid }
|
110
110
|
|
@@ -115,7 +115,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
#preprocesed_words=
|
118
|
+
# preprocesed_words=
|
119
119
|
describe '#preprocesed_words=' do
|
120
120
|
let(:changed_value) do
|
121
121
|
create(:preprocessed_words, with_word_processors: 2, original_word: original_word)
|
@@ -123,18 +123,17 @@ RSpec.describe LittleWeasel::WordResults do
|
|
123
123
|
|
124
124
|
it 'sets @preprocesed_words' do
|
125
125
|
expect { subject.preprocessed_words = changed_value }.to \
|
126
|
-
change
|
126
|
+
change(subject, :preprocessed_words)
|
127
127
|
.from(preprocessed_words)
|
128
128
|
.to(changed_value)
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
#success?
|
132
|
+
# success?
|
133
133
|
describe '#success?' do
|
134
134
|
context 'when #filter_match? is false AND #word_valid? is false' do
|
135
135
|
before do
|
136
|
-
allow(subject).to
|
137
|
-
allow(subject).to receive(:word_valid?).and_return false
|
136
|
+
allow(subject).to receive_messages(filter_match?: false, word_valid?: false)
|
138
137
|
end
|
139
138
|
|
140
139
|
it 'returns false' do
|
@@ -145,8 +144,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
145
144
|
context 'when #filter_match? is true OR #word_valid? is true' do
|
146
145
|
context 'when #filter_match? is true' do
|
147
146
|
before do
|
148
|
-
allow(subject).to
|
149
|
-
allow(subject).to receive(:word_valid?).and_return false
|
147
|
+
allow(subject).to receive_messages(filter_match?: true, word_valid?: false)
|
150
148
|
end
|
151
149
|
|
152
150
|
it 'returns true' do
|
@@ -156,8 +154,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
156
154
|
|
157
155
|
context 'when #word_valid? is true' do
|
158
156
|
before do
|
159
|
-
allow(subject).to
|
160
|
-
allow(subject).to receive(:word_valid?).and_return true
|
157
|
+
allow(subject).to receive_messages(filter_match?: false, word_valid?: true)
|
161
158
|
end
|
162
159
|
|
163
160
|
it 'returns true' do
|
@@ -167,58 +164,58 @@ RSpec.describe LittleWeasel::WordResults do
|
|
167
164
|
end
|
168
165
|
end
|
169
166
|
|
170
|
-
#filter_match?
|
167
|
+
# filter_match?
|
171
168
|
describe '#filter_match?' do
|
172
|
-
|
169
|
+
describe '#when filters_matched is present' do
|
173
170
|
let(:filters_matched) { [:matched_filter] }
|
174
171
|
|
175
172
|
it 'returns true' do
|
176
|
-
expect(subject.filter_match?).to
|
173
|
+
expect(subject.filter_match?).to be true
|
177
174
|
end
|
178
175
|
end
|
179
176
|
|
180
|
-
|
177
|
+
describe '#when filters_matched is NOT present' do
|
181
178
|
it 'returns false' do
|
182
|
-
expect(subject.filter_match?).to
|
179
|
+
expect(subject.filter_match?).to be false
|
183
180
|
end
|
184
181
|
end
|
185
182
|
end
|
186
183
|
|
187
|
-
#word_cached?
|
184
|
+
# word_cached?
|
188
185
|
describe '#word_cached?' do
|
189
|
-
|
186
|
+
describe '#when word_cached is true' do
|
190
187
|
let(:word_cached) { true }
|
191
188
|
|
192
189
|
it 'returns true' do
|
193
|
-
expect(subject.word_cached?).to
|
190
|
+
expect(subject.word_cached?).to be true
|
194
191
|
end
|
195
192
|
end
|
196
193
|
|
197
|
-
|
194
|
+
describe '#when word_cached is false' do
|
198
195
|
it 'returns false' do
|
199
|
-
expect(subject.word_cached?).to
|
196
|
+
expect(subject.word_cached?).to be false
|
200
197
|
end
|
201
198
|
end
|
202
199
|
end
|
203
200
|
|
204
|
-
#word_valid?
|
201
|
+
# word_valid?
|
205
202
|
describe '#word_valid?' do
|
206
|
-
|
203
|
+
describe '#when word_valid is true' do
|
207
204
|
let(:word_valid) { true }
|
208
205
|
|
209
206
|
it 'returns true' do
|
210
|
-
expect(subject.word_valid?).to
|
207
|
+
expect(subject.word_valid?).to be true
|
211
208
|
end
|
212
209
|
end
|
213
210
|
|
214
|
-
|
211
|
+
describe '#when word_valid is false' do
|
215
212
|
it 'returns false' do
|
216
|
-
expect(subject.word_valid?).to
|
213
|
+
expect(subject.word_valid?).to be false
|
217
214
|
end
|
218
215
|
end
|
219
216
|
end
|
220
217
|
|
221
|
-
#preprocessed_word?
|
218
|
+
# preprocessed_word?
|
222
219
|
describe '#preprocessed_word?' do
|
223
220
|
subject do
|
224
221
|
create(:word_results,
|
@@ -250,7 +247,7 @@ RSpec.describe LittleWeasel::WordResults do
|
|
250
247
|
end
|
251
248
|
end
|
252
249
|
|
253
|
-
#preprocessed_word_or_original_word
|
250
|
+
# preprocessed_word_or_original_word
|
254
251
|
describe '#preprocessed_word_or_original_word' do
|
255
252
|
let(:original_word) { 'word' }
|
256
253
|
|
@@ -3,11 +3,11 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe 'Workflow tests' do
|
6
|
+
subject { LittleWeasel::DictionaryManager.new }
|
7
|
+
|
6
8
|
include_context 'dictionary cache'
|
7
9
|
include_context 'dictionary keys'
|
8
10
|
|
9
|
-
subject { LittleWeasel::DictionaryManager.new }
|
10
|
-
|
11
11
|
# This loads the BIG en-US-big dictionary
|
12
12
|
let(:en_us_dictionary_key) { dictionary_key_for(language: :en, region: :us, tag: :big) }
|
13
13
|
let(:en_gb_dictionary_key) { dictionary_key_for(language: :en, region: :gb) }
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pry-byebug'
|
2
4
|
require 'simplecov'
|
3
5
|
|
@@ -5,7 +7,7 @@ SimpleCov.start do
|
|
5
7
|
add_filter 'spec'
|
6
8
|
end
|
7
9
|
|
8
|
-
require File.expand_path(File.dirname(__FILE__)
|
10
|
+
require File.expand_path("#{File.dirname(__FILE__)}../../lib/LittleWeasel")
|
9
11
|
Dir[File.join('.', 'spec/support/**/*.rb')].each do |f|
|
10
12
|
require f
|
11
13
|
end
|
@@ -56,68 +58,66 @@ RSpec.configure do |config|
|
|
56
58
|
# triggering implicit auto-inclusion in groups with matching metadata.
|
57
59
|
config.shared_context_metadata_behavior = :apply_to_host_groups
|
58
60
|
|
59
|
-
# The settings below are suggested to provide a good initial experience
|
60
|
-
# with RSpec, but feel free to customize to your heart's content.
|
61
|
-
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# - http://
|
77
|
-
# - http://
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
|
105
|
-
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
Kernel.srand config.seed
|
111
|
-
=end
|
61
|
+
# The settings below are suggested to provide a good initial experience
|
62
|
+
# with RSpec, but feel free to customize to your heart's content.
|
63
|
+
# # This allows you to limit a spec run to individual examples or groups
|
64
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
65
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
66
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
67
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
68
|
+
# config.filter_run_when_matching :focus
|
69
|
+
#
|
70
|
+
# # Allows RSpec to persist some state between runs in order to support
|
71
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
72
|
+
# # you configure your source control system to ignore this file.
|
73
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
74
|
+
#
|
75
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
76
|
+
# # recommended. For more details, see:
|
77
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
78
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
79
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
80
|
+
# config.disable_monkey_patching!
|
81
|
+
#
|
82
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
83
|
+
# # be too noisy due to issues in dependencies.
|
84
|
+
# config.warnings = true
|
85
|
+
#
|
86
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
87
|
+
# # file, and it's useful to allow more verbose output when running an
|
88
|
+
# # individual spec file.
|
89
|
+
# if config.files_to_run.one?
|
90
|
+
# # Use the documentation formatter for detailed output,
|
91
|
+
# # unless a formatter has already been configured
|
92
|
+
# # (e.g. via a command-line flag).
|
93
|
+
# config.default_formatter = "doc"
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# # Print the 10 slowest examples and example groups at the
|
97
|
+
# # end of the spec run, to help surface which specs are running
|
98
|
+
# # particularly slow.
|
99
|
+
# config.profile_examples = 10
|
100
|
+
#
|
101
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
102
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
103
|
+
# # the seed, which is printed after each run.
|
104
|
+
# # --seed 1234
|
105
|
+
# config.order = :random
|
106
|
+
#
|
107
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
108
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
109
|
+
# # test failures related to randomization by passing the same `--seed` value
|
110
|
+
# # as the one that triggered the failure.
|
111
|
+
# Kernel.srand config.seed
|
112
112
|
|
113
113
|
# Enable both should and expect until the old specs are upgraded.
|
114
114
|
config.expect_with :rspec do |c|
|
115
|
-
c.syntax = %i[should
|
115
|
+
c.syntax = %i[should expect]
|
116
116
|
end
|
117
117
|
|
118
118
|
# Load support files
|
119
119
|
config.include Support::FileHelpers
|
120
120
|
config.include Support::GeneralHelpers
|
121
121
|
|
122
|
-
config.before
|
122
|
+
config.before { LittleWeasel.configure(&:reset) }
|
123
123
|
end
|
data/spec/support/factory_bot.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'factory_bot'
|
4
4
|
require_relative 'file_helpers'
|
5
5
|
|
6
|
-
FactoryBot::SyntaxRunner.
|
6
|
+
FactoryBot::SyntaxRunner.include Support::FileHelpers
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.include FactoryBot::Syntax::Methods
|
@@ -12,4 +12,3 @@ RSpec.configure do |config|
|
|
12
12
|
FactoryBot.find_definitions
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
@@ -23,12 +23,12 @@ module Support
|
|
23
23
|
Locale.new(language: language, region: region).locale
|
24
24
|
end
|
25
25
|
|
26
|
-
def region_dictionary_path
|
26
|
+
def region_dictionary_path(language:, region:)
|
27
27
|
file_name = locale_for language: language, region: region
|
28
28
|
dictionary_path_for file_name: file_name
|
29
29
|
end
|
30
30
|
|
31
|
-
def language_dictionary_path
|
31
|
+
def language_dictionary_path(language:)
|
32
32
|
file_name = locale_for language: language
|
33
33
|
dictionary_path_for file_name: file_name
|
34
34
|
end
|
@@ -50,7 +50,7 @@ module Support
|
|
50
50
|
puts "#{indent * 2}filter_match? #=> #{results.filter_match?}"
|
51
51
|
puts "#{indent * 2}filters_matched: #=> #{results.filters_matched}"
|
52
52
|
puts "#{indent * 2}preprocessed_words #=>"
|
53
|
-
results.preprocessed_words&.preprocessed_words
|
53
|
+
results.preprocessed_words&.preprocessed_words&.each_with_index do |preprocessed_word, index|
|
54
54
|
puts "#{indent * 3}preprocessed_words[#{index}] #=>"
|
55
55
|
puts "#{indent * 4}preprocessed_word #=>"
|
56
56
|
puts "#{indent * 5}preprocessor: :#{preprocessed_word.preprocessor}"
|
@@ -61,6 +61,7 @@ module Support
|
|
61
61
|
|
62
62
|
def string_or_nil(value)
|
63
63
|
return 'nil' if value.nil?
|
64
|
+
|
64
65
|
"\"#{value}\""
|
65
66
|
end
|
66
67
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.shared_context 'dictionary cache' do
|
2
4
|
def dictionary_cache_for(dictionary_key:, dictionary_file_source: true, load: false)
|
3
5
|
dictionary_cache_from(dictionary_keys: [{ dictionary_key: dictionary_key, dictionary_file_source: dictionary_file_source, load: load }])
|
@@ -22,7 +24,9 @@ RSpec.shared_context 'dictionary cache' do
|
|
22
24
|
dictionary_cache = {}
|
23
25
|
|
24
26
|
dictionary_keys.each do |hash|
|
25
|
-
|
27
|
+
unless hash.key? :dictionary_key
|
28
|
+
raise ArgumentError, 'Expected required Hash key :dictionary_key but it was not found'
|
29
|
+
end
|
26
30
|
|
27
31
|
create(:dictionary_cache_service,
|
28
32
|
dictionary_cache: dictionary_cache,
|
@@ -38,32 +42,32 @@ end
|
|
38
42
|
|
39
43
|
RSpec.shared_context 'dictionary keys' do
|
40
44
|
def dictionary_key_for(language:, region: nil, tag: nil)
|
41
|
-
|
45
|
+
create(:dictionary_key, language: language, region: region, tag: tag)
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
45
49
|
RSpec.shared_context 'mock word filters' do
|
46
|
-
unless Object.const_defined?(
|
50
|
+
unless Object.const_defined?(:WordFilter01)
|
47
51
|
class WordFilter01 < LittleWeasel::Filters::WordFilter
|
48
52
|
class << self
|
49
|
-
def filter_match?(
|
53
|
+
def filter_match?(_word)
|
50
54
|
true
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
56
|
-
unless Object.const_defined?(
|
60
|
+
unless Object.const_defined?(:WordFilter02)
|
57
61
|
class WordFilter02 < LittleWeasel::Filters::WordFilter
|
58
62
|
class << self
|
59
|
-
def filter_match?(
|
63
|
+
def filter_match?(_word)
|
60
64
|
true
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
|
-
unless Object.const_defined?(
|
70
|
+
unless Object.const_defined?(:DollarSignFilter)
|
67
71
|
class DollarSignFilter < LittleWeasel::Filters::WordFilter
|
68
72
|
class << self
|
69
73
|
def filter_match?(word)
|
@@ -78,7 +82,7 @@ RSpec.shared_context 'mock word preprocessors' do
|
|
78
82
|
class UpcaseWordPreprocessor < LittleWeasel::Preprocessors::WordPreprocessor
|
79
83
|
class << self
|
80
84
|
def preprocess(word)
|
81
|
-
[true, word.upcase]
|
85
|
+
[true, word.upcase]
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
@@ -86,7 +90,7 @@ RSpec.shared_context 'mock word preprocessors' do
|
|
86
90
|
class DowncaseWordPreprocessor < LittleWeasel::Preprocessors::WordPreprocessor
|
87
91
|
class << self
|
88
92
|
def preprocess(word)
|
89
|
-
[true, word.downcase]
|
93
|
+
[true, word.downcase]
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|