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
@@ -5,34 +5,34 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::EnUs::NumericFilter 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 a number' 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?(
|
19
|
-
expect(subject.filter_match?('+100.0')).to
|
20
|
-
expect(subject.filter_match?(1_000_000.00)).to
|
21
|
-
expect(subject.filter_match?(1_000_000.10)).to
|
22
|
-
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?(123_456)).to be true
|
21
|
+
expect(subject.filter_match?('+100.0')).to be true
|
22
|
+
expect(subject.filter_match?(1_000_000.00)).to be true
|
23
|
+
expect(subject.filter_match?(1_000_000.10)).to be true
|
24
|
+
expect(subject.filter_match?(1_000_000.01)).to be true
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
context 'when word is NOT a number' do
|
27
29
|
it 'returns false' do
|
28
|
-
expect(subject.filter_match?
|
29
|
-
expect(subject.filter_match?
|
30
|
-
expect(subject.filter_match?
|
30
|
+
expect(subject.filter_match?('a')).to be false
|
31
|
+
expect(subject.filter_match?(:a)).to be false
|
32
|
+
expect(subject.filter_match?(Object.new)).to be false
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
let(:word) { 1 }
|
35
|
-
|
36
36
|
context 'when #filter_match? returns true' do
|
37
37
|
before { allow(subject.class).to receive(:filter_match?).and_return(true) }
|
38
38
|
|
@@ -5,26 +5,26 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::EnUs::SingleCharacterWordFilter do
|
6
6
|
subject { described_class.new }
|
7
7
|
|
8
|
-
#filter_match?
|
8
|
+
# filter_match?
|
9
9
|
describe '#filter_match?' do
|
10
|
+
let(:word) { 'x' }
|
11
|
+
|
10
12
|
context 'when word single character word' do
|
11
13
|
it 'returns true' do
|
12
|
-
%w
|
13
|
-
expect(subject.filter_match?
|
14
|
+
%w[a A I].each do |number|
|
15
|
+
expect(subject.filter_match?(number)).to be true
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
context 'when word is NOT a single character word' do
|
19
21
|
it 'returns false' do
|
20
|
-
expect(subject.filter_match?
|
21
|
-
expect(subject.filter_match?
|
22
|
-
expect(subject.filter_match?
|
22
|
+
expect(subject.filter_match?('X')).to be false
|
23
|
+
expect(subject.filter_match?(:a)).to be false
|
24
|
+
expect(subject.filter_match?(Object.new)).to be false
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
let(:word) { 'x' }
|
27
|
-
|
28
28
|
context 'when #filter_match? returns true' do
|
29
29
|
before { allow(subject.class).to receive(:filter_match?).and_return(true) }
|
30
30
|
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
6
|
-
include_context 'mock word filters'
|
7
|
-
|
8
|
-
WordFilterManagable = described_class
|
9
|
-
|
10
6
|
subject do
|
11
7
|
Class.new do
|
12
8
|
include WordFilterManagable
|
@@ -18,10 +14,14 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
18
14
|
end.new(word_filters)
|
19
15
|
end
|
20
16
|
|
17
|
+
include_context 'mock word filters'
|
18
|
+
|
19
|
+
WordFilterManagable = described_class
|
20
|
+
|
21
21
|
let(:word_filters) { [numeric_filter] }
|
22
22
|
let(:numeric_filter) { LittleWeasel::Filters::EnUs::NumericFilter.new }
|
23
23
|
|
24
|
-
#clear_filters
|
24
|
+
# clear_filters
|
25
25
|
describe '#clear_filters' do
|
26
26
|
it 'sets #word_filters to an empty Array ([])' do
|
27
27
|
expect { subject.clear_filters }.to \
|
@@ -29,7 +29,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
#add_filters
|
32
|
+
# add_filters
|
33
33
|
describe '#add_filters' do
|
34
34
|
context 'when argument word_filters is nil' do
|
35
35
|
context 'when no block is passed' do
|
@@ -57,7 +57,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
57
57
|
|
58
58
|
context 'when argument word_filters is a blank Array ([])' do
|
59
59
|
it 'nothing is changed' do
|
60
|
-
expect { subject.add_filters(word_filters: []) }.
|
60
|
+
expect { subject.add_filters(word_filters: []) }.not_to change { subject.word_filters.count }.from(subject.word_filters.count)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -93,7 +93,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
#replace_filters
|
96
|
+
# replace_filters
|
97
97
|
describe '#replace_filters' do
|
98
98
|
it 'replaces any existing word filters' do
|
99
99
|
expect(subject.word_filters.count).to eq 1
|
@@ -104,7 +104,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
#filters_on=
|
107
|
+
# filters_on=
|
108
108
|
describe '#filters_on=' do
|
109
109
|
context 'when a boolean is not passed' do
|
110
110
|
it 'raises an error' do
|
@@ -114,10 +114,10 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
114
114
|
|
115
115
|
context 'when true is assigned' do
|
116
116
|
it 'turns all the filters on' do
|
117
|
-
expect(subject.word_filters.count).
|
118
|
-
expect(subject.word_filters.all?
|
117
|
+
expect(subject.word_filters.count).not_to be_zero
|
118
|
+
expect(subject.word_filters.all?(&:filter_on?))
|
119
119
|
subject.filters_on = true
|
120
|
-
expect(subject.word_filters.all?
|
120
|
+
expect(subject.word_filters.all?(&:filter_off?))
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -127,15 +127,15 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'turns all the filters off' do
|
130
|
-
expect(subject.word_filters.count).
|
131
|
-
expect(subject.word_filters.all?
|
130
|
+
expect(subject.word_filters.count).not_to be_zero
|
131
|
+
expect(subject.word_filters.all?(&:filter_off?))
|
132
132
|
subject.filters_on = false
|
133
|
-
expect(subject.word_filters.all?
|
133
|
+
expect(subject.word_filters.all?(&:filter_on?))
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
#filter_match?
|
138
|
+
# filter_match?
|
139
139
|
describe '#filter_match?' do
|
140
140
|
context 'when argument word is not a String' do
|
141
141
|
let(:word) { :not_a_string }
|
@@ -149,7 +149,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
149
149
|
let(:word) { '' }
|
150
150
|
|
151
151
|
it 'returns false' do
|
152
|
-
expect(subject.filter_match?
|
152
|
+
expect(subject.filter_match?(word)).to be false
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -161,7 +161,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
161
161
|
let(:word) { '123456789' }
|
162
162
|
|
163
163
|
it 'returns true' do
|
164
|
-
expect(subject.filter_match?
|
164
|
+
expect(subject.filter_match?(word)).to be true
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -173,7 +173,7 @@ RSpec.describe LittleWeasel::Filters::WordFilterManagable, type: :module do
|
|
173
173
|
let(:word) { '123456789' }
|
174
174
|
|
175
175
|
it 'returns false' do
|
176
|
-
expect(subject.filter_match?
|
176
|
+
expect(subject.filter_match?(word)).to be false
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|
@@ -5,29 +5,29 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::WordFilter do
|
6
6
|
subject { described_class.new }
|
7
7
|
|
8
|
-
|
8
|
+
# .new
|
9
9
|
describe '.new' do
|
10
10
|
it 'instantiates the object' do
|
11
|
-
expect { subject }.
|
11
|
+
expect { subject }.not_to raise_error
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'sets #filter_on to true by default' do
|
15
|
-
expect(subject.filter_on).to
|
15
|
+
expect(subject.filter_on).to be true
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
#filter_off!
|
19
|
+
# filter_off!
|
20
20
|
describe '#filter_off!' do
|
21
21
|
before do
|
22
22
|
subject.filter_off!
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'sets the filter off' do
|
26
|
-
expect(subject.filter_off?).to
|
26
|
+
expect(subject.filter_off?).to be true
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
#filter_on
|
30
|
+
# filter_on
|
31
31
|
describe '#filter_on' do
|
32
32
|
context 'when set to true' do
|
33
33
|
before do
|
@@ -35,7 +35,7 @@ RSpec.describe LittleWeasel::Filters::WordFilter do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns true' do
|
38
|
-
expect(subject.filter_on).to
|
38
|
+
expect(subject.filter_on).to be true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -45,35 +45,35 @@ RSpec.describe LittleWeasel::Filters::WordFilter do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns false' do
|
48
|
-
expect(subject.filter_on).to
|
48
|
+
expect(subject.filter_on).to be false
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
#filter_on=
|
53
|
+
# filter_on=
|
54
54
|
describe '#filter_on=' do
|
55
55
|
context 'when argument value is valid' do
|
56
56
|
context 'when true' do
|
57
57
|
before do
|
58
58
|
subject.filter_on = false
|
59
|
-
expect(subject.filter_off?).to
|
59
|
+
expect(subject.filter_off?).to be true
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'sets #filter_on to true' do
|
63
63
|
subject.filter_on = true
|
64
|
-
expect(subject.filter_on).to
|
64
|
+
expect(subject.filter_on).to be true
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
context 'when false' do
|
69
69
|
before do
|
70
70
|
subject.filter_on = true
|
71
|
-
expect(subject.filter_on?).to
|
71
|
+
expect(subject.filter_on?).to be true
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'sets #filter_on to false' do
|
75
75
|
subject.filter_on = false
|
76
|
-
expect(subject.filter_on).to
|
76
|
+
expect(subject.filter_on).to be false
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -89,24 +89,24 @@ RSpec.describe LittleWeasel::Filters::WordFilter do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
#filter_on?
|
92
|
+
# filter_on?
|
93
93
|
describe '#filter_on?' do
|
94
94
|
context 'when #filter_on is true' do
|
95
95
|
it 'returns true' do
|
96
96
|
subject.filter_on = true
|
97
|
-
expect(subject.filter_on?).to
|
97
|
+
expect(subject.filter_on?).to be true
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
context 'when #filter_on is false' do
|
102
102
|
it 'returns false' do
|
103
103
|
subject.filter_on = false
|
104
|
-
expect(subject.filter_on?).to
|
104
|
+
expect(subject.filter_on?).to be false
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
#filter_match?
|
109
|
+
# filter_match?
|
110
110
|
describe '#filter_match?' do
|
111
111
|
let(:word) { 'word' }
|
112
112
|
|
@@ -13,12 +13,23 @@ RSpec.describe LittleWeasel::Filters::WordFilterValidatable, type: :module do
|
|
13
13
|
|
14
14
|
let(:filter_class) do
|
15
15
|
filter = Class.new do
|
16
|
-
def filter_on
|
17
|
-
|
18
|
-
|
19
|
-
def
|
20
|
-
|
21
|
-
|
16
|
+
def filter_on?
|
17
|
+
end
|
18
|
+
|
19
|
+
def filter_off?
|
20
|
+
end
|
21
|
+
|
22
|
+
def filter_on
|
23
|
+
end
|
24
|
+
|
25
|
+
def filter_on=
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_match?
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.filter_match?
|
32
|
+
end
|
22
33
|
end
|
23
34
|
filter
|
24
35
|
end
|
@@ -28,17 +39,18 @@ RSpec.describe LittleWeasel::Filters::WordFilterValidatable, type: :module do
|
|
28
39
|
end
|
29
40
|
let(:expected_error_message) { "Argument word_filter does not quack right: #{numeric_filter.class}" }
|
30
41
|
|
31
|
-
#validate_word_filter
|
42
|
+
# validate_word_filter
|
32
43
|
describe '#validate_word_filter' do
|
33
44
|
context 'when argument word_filter quacks correctly' do
|
34
45
|
it 'does not raise an error' do
|
35
|
-
expect { subject.validate_word_filter(word_filter: numeric_filter) }.
|
46
|
+
expect { subject.validate_word_filter(word_filter: numeric_filter) }.not_to raise_error
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
39
50
|
context 'when argument word_filter DOES NOT quack correctly to the right instance methods' do
|
40
51
|
context 'when word_filter does not respond to #filter_on?' do
|
41
|
-
before { numeric_filter.instance_eval("undef #{method_to_check}") }
|
52
|
+
before { numeric_filter.instance_eval("undef #{method_to_check}", __FILE__, __LINE__) }
|
53
|
+
|
42
54
|
let(:method_to_check) { :filter_on? }
|
43
55
|
|
44
56
|
it 'raises an error' do
|
@@ -48,7 +60,8 @@ RSpec.describe LittleWeasel::Filters::WordFilterValidatable, type: :module do
|
|
48
60
|
end
|
49
61
|
|
50
62
|
context 'when word_filter does not respond to #filter_on' do
|
51
|
-
before { numeric_filter.instance_eval("undef #{method_to_check}") }
|
63
|
+
before { numeric_filter.instance_eval("undef #{method_to_check}", __FILE__, __LINE__) }
|
64
|
+
|
52
65
|
let(:method_to_check) { :filter_on }
|
53
66
|
|
54
67
|
it 'raises an error' do
|
@@ -58,7 +71,8 @@ RSpec.describe LittleWeasel::Filters::WordFilterValidatable, type: :module do
|
|
58
71
|
end
|
59
72
|
|
60
73
|
context 'when word_filter does not respond to #filter_on=' do
|
61
|
-
before { numeric_filter.instance_eval("undef #{method_to_check}") }
|
74
|
+
before { numeric_filter.instance_eval("undef #{method_to_check}", __FILE__, __LINE__) }
|
75
|
+
|
62
76
|
let(:method_to_check) { :filter_on= }
|
63
77
|
|
64
78
|
it 'raises an error' do
|
@@ -68,7 +82,8 @@ RSpec.describe LittleWeasel::Filters::WordFilterValidatable, type: :module do
|
|
68
82
|
end
|
69
83
|
|
70
84
|
context 'when word_filter does not respond to #filter_match?' do
|
71
|
-
before { numeric_filter.instance_eval("undef #{method_to_check}") }
|
85
|
+
before { numeric_filter.instance_eval("undef #{method_to_check}", __FILE__, __LINE__) }
|
86
|
+
|
72
87
|
let(:method_to_check) { :filter_match? }
|
73
88
|
|
74
89
|
it 'raises an error' do
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::Filters::WordFiltersValidatable, type: :module do
|
6
|
+
subject { Subject.new }
|
7
|
+
|
6
8
|
include_context 'mock word filters'
|
7
9
|
|
8
10
|
WordFiltersValidatable = described_class
|
@@ -11,8 +13,6 @@ RSpec.describe LittleWeasel::Filters::WordFiltersValidatable, type: :module do
|
|
11
13
|
include WordFiltersValidatable
|
12
14
|
end
|
13
15
|
|
14
|
-
subject { Subject.new }
|
15
|
-
|
16
16
|
let(:word_filters) do
|
17
17
|
[
|
18
18
|
WordFilter01.new,
|
@@ -21,10 +21,10 @@ RSpec.describe LittleWeasel::Filters::WordFiltersValidatable, type: :module do
|
|
21
21
|
end
|
22
22
|
let(:expected_error_message) { "Argument word_filter does not quack right: #{numeric_filter.class}" }
|
23
23
|
|
24
|
-
#validate_word_filters
|
24
|
+
# validate_word_filters
|
25
25
|
describe '#validate_word_filters' do
|
26
26
|
context 'when argument word_filters is not an Array' do
|
27
|
-
let(:word_filters) { :not_an_array}
|
27
|
+
let(:word_filters) { :not_an_array }
|
28
28
|
|
29
29
|
it 'raises an error' do
|
30
30
|
expect { subject.validate_word_filters(word_filters: word_filters) }.to raise_error "Argument word_filters is not an Array: #{word_filters.class}"
|
@@ -33,7 +33,7 @@ RSpec.describe LittleWeasel::Filters::WordFiltersValidatable, type: :module do
|
|
33
33
|
|
34
34
|
context 'when argument word_filters contains valid word filters' do
|
35
35
|
it 'does not raise an error' do
|
36
|
-
expect { subject.validate_word_filters(word_filters: word_filters) }.
|
36
|
+
expect { subject.validate_word_filters(word_filters: word_filters) }.not_to raise_error
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,7 +41,7 @@ RSpec.describe LittleWeasel::Filters::WordFiltersValidatable, type: :module do
|
|
41
41
|
let(:word_filters) { [Object.new] }
|
42
42
|
|
43
43
|
it 'does not raise an error' do
|
44
|
-
expect { subject.validate_word_filters(word_filters: word_filters) }.to raise_error
|
44
|
+
expect { subject.validate_word_filters(word_filters: word_filters) }.to raise_error "Argument word_filter does not quack right: #{word_filters[0].class}"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe 'Dictionary integration', type: :integration do
|
6
|
+
subject { create(:dictionary_manager) }
|
7
|
+
|
6
8
|
include_context 'dictionary keys'
|
7
9
|
include_context 'mock word preprocessors'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
before(:each) { LittleWeasel.configure { |config| config.reset } }
|
11
|
+
before { LittleWeasel.configure(&:reset) }
|
12
12
|
|
13
13
|
let(:dictionary) do
|
14
14
|
subject.create_dictionary_from_file(dictionary_key: dictionary_key, file: dictionary_file_path,
|
@@ -22,7 +22,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
22
22
|
let(:word_filters) {}
|
23
23
|
let(:word_preprocessors) {}
|
24
24
|
|
25
|
-
#word_results
|
25
|
+
# word_results
|
26
26
|
describe '#word_results' do
|
27
27
|
describe 'when using word filters' do
|
28
28
|
let(:word_filters) { [LittleWeasel::Filters::EnUs::NumericFilter.new] }
|
@@ -32,11 +32,11 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
32
32
|
let(:word_results) { dictionary.word_results(number) }
|
33
33
|
|
34
34
|
it '#success? returns true' do
|
35
|
-
expect(word_results.success?).to
|
35
|
+
expect(word_results.success?).to be true
|
36
36
|
end
|
37
37
|
|
38
38
|
it '#filter_match? returns true' do
|
39
|
-
expect(word_results.filter_match?).to
|
39
|
+
expect(word_results.filter_match?).to be true
|
40
40
|
end
|
41
41
|
|
42
42
|
it '#filters_matched returns the filter(s) that were matched' do
|
@@ -44,7 +44,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it '#word_valid? returns false' do
|
47
|
-
expect(word_results.word_valid?).to
|
47
|
+
expect(word_results.word_valid?).to be false
|
48
48
|
end
|
49
49
|
|
50
50
|
it '#original_word returns the original word' do
|
@@ -60,12 +60,12 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it '#word_cached? returns false if the word is not in the dictionary' do
|
63
|
-
expect(word_results.word_cached?).to
|
63
|
+
expect(word_results.word_cached?).to be false
|
64
64
|
end
|
65
65
|
|
66
66
|
it '#word_cached? returns true 2nd-nth time the word was searched if invalid words are being cached by any metadata processing' do
|
67
67
|
dictionary.word_results(number)
|
68
|
-
expect(word_results.word_cached?).to
|
68
|
+
expect(word_results.word_cached?).to be true
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -77,11 +77,11 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
77
77
|
let(:word_results) { dictionary.word_results(number) }
|
78
78
|
|
79
79
|
it '#success? returns false' do
|
80
|
-
expect(word_results.success?).to
|
80
|
+
expect(word_results.success?).to be false
|
81
81
|
end
|
82
82
|
|
83
83
|
it '#filter_match? returns false' do
|
84
|
-
expect(word_results.filter_match?).to
|
84
|
+
expect(word_results.filter_match?).to be false
|
85
85
|
end
|
86
86
|
|
87
87
|
it '#filters_matched returns an empty Array' do
|
@@ -89,7 +89,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it '#word_valid? returns false' do
|
92
|
-
expect(word_results.word_valid?).to
|
92
|
+
expect(word_results.word_valid?).to be false
|
93
93
|
end
|
94
94
|
|
95
95
|
it '#original_word returns the original word' do
|
@@ -105,12 +105,12 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it '#word_cached? returns false if the word is not in the dictionary' do
|
108
|
-
expect(word_results.word_cached?).to
|
108
|
+
expect(word_results.word_cached?).to be false
|
109
109
|
end
|
110
110
|
|
111
111
|
it '#word_cached? returns true 2nd-nth time the word was searched if invalid words are being cached by any metadata processing' do
|
112
112
|
dictionary.word_results(number)
|
113
|
-
expect(word_results.word_cached?).to
|
113
|
+
expect(word_results.word_cached?).to be true
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
@@ -122,11 +122,11 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
122
122
|
|
123
123
|
context 'with preprocessors turned on' do
|
124
124
|
it '#success? returns true' do
|
125
|
-
expect(word_results.success?).to
|
125
|
+
expect(word_results.success?).to be true
|
126
126
|
end
|
127
127
|
|
128
128
|
it '#filter_match? returns false' do
|
129
|
-
expect(word_results.filter_match?).to
|
129
|
+
expect(word_results.filter_match?).to be false
|
130
130
|
end
|
131
131
|
|
132
132
|
it '#filters_matched returns the filter(s) that were matched' do
|
@@ -134,7 +134,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
it '#word_valid? returns true' do
|
137
|
-
expect(word_results.word_valid?).to
|
137
|
+
expect(word_results.word_valid?).to be true
|
138
138
|
end
|
139
139
|
|
140
140
|
it '#original_word returns the original word' do
|
@@ -150,7 +150,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
it '#word_cached? returns true if the word is in the dictionary' do
|
153
|
-
expect(word_results.word_cached?).to
|
153
|
+
expect(word_results.word_cached?).to be true
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -160,11 +160,11 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
it '#success? returns false' do
|
163
|
-
expect(word_results.success?).to
|
163
|
+
expect(word_results.success?).to be false
|
164
164
|
end
|
165
165
|
|
166
166
|
it '#filter_match? returns false' do
|
167
|
-
expect(word_results.filter_match?).to
|
167
|
+
expect(word_results.filter_match?).to be false
|
168
168
|
end
|
169
169
|
|
170
170
|
it '#filters_matched returns the filter(s) that were matched' do
|
@@ -172,7 +172,7 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it '#word_valid? returns false' do
|
175
|
-
expect(word_results.word_valid?).to
|
175
|
+
expect(word_results.word_valid?).to be false
|
176
176
|
end
|
177
177
|
|
178
178
|
it '#original_word returns the original word' do
|
@@ -188,12 +188,12 @@ RSpec.describe 'Dictionary integration', type: :integration do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it '#word_cached? returns false if the word is not in the dictionary' do
|
191
|
-
expect(word_results.word_cached?).to
|
191
|
+
expect(word_results.word_cached?).to be false
|
192
192
|
end
|
193
193
|
|
194
194
|
it '#word_cached? returns true 2nd-nth time the word was searched if invalid words are being cached by any metadata processing' do
|
195
195
|
dictionary.word_results(word)
|
196
|
-
expect(word_results.word_cached?).to
|
196
|
+
expect(word_results.word_cached?).to be true
|
197
197
|
end
|
198
198
|
end
|
199
199
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe LittleWeasel::Modules::DictionaryCreatorServicable, type: :module do
|
6
|
+
subject { SubjectMock.new(dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata, word_filters: word_filters) }
|
7
|
+
|
6
8
|
include_context 'dictionary keys'
|
7
9
|
|
8
10
|
DictionaryCreatorServicable = described_class
|
@@ -21,8 +23,6 @@ RSpec.describe LittleWeasel::Modules::DictionaryCreatorServicable, type: :module
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
subject { SubjectMock.new(dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata, word_filters: word_filters) }
|
25
|
-
|
26
26
|
let(:en_us_dictionary_key) { dictionary_key_for(language: :en, region: :us) }
|
27
27
|
let(:dictionary_key) { en_us_dictionary_key }
|
28
28
|
let(:key) { dictionary_key.key }
|
@@ -31,24 +31,25 @@ RSpec.describe LittleWeasel::Modules::DictionaryCreatorServicable, type: :module
|
|
31
31
|
let(:dictionary_metadata) { {} }
|
32
32
|
let(:word_filters) {}
|
33
33
|
|
34
|
-
#attributes
|
34
|
+
# attributes
|
35
35
|
describe 'attributes' do
|
36
36
|
it 'responds to the correct attributes' do
|
37
37
|
expect(subject).to respond_to(
|
38
38
|
:dictionary_key,
|
39
39
|
:dictionary_cache,
|
40
|
-
:word_filters
|
40
|
+
:word_filters
|
41
|
+
)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
#dictionary_creator_service
|
45
|
+
# dictionary_creator_service
|
45
46
|
describe '#dictionary_creator_service' do
|
46
47
|
it 'responds to #dictionary_creator_service' do
|
47
48
|
expect(subject).to respond_to(:dictionary_creator_service)
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'returns a Services::DictionaryCreatorService object' do
|
51
|
-
expect(subject.dictionary_creator_service).to
|
52
|
+
expect(subject.dictionary_creator_service).to be_a LittleWeasel::Services::DictionaryCreatorService
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|