LittleWeasel 3.0.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.reek.yml +17 -0
  4. data/.rspec +4 -2
  5. data/.rubocop.yml +187 -0
  6. data/.ruby-version +1 -1
  7. data/.yardopts +2 -0
  8. data/CHANGELOG.md +22 -1
  9. data/Gemfile +3 -1
  10. data/Jenkinsfile +20 -0
  11. data/LittleWeasel.gemspec +31 -18
  12. data/README.md +408 -42
  13. data/Rakefile +296 -3
  14. data/lib/LittleWeasel/block_results.rb +81 -0
  15. data/lib/LittleWeasel/configure.rb +98 -0
  16. data/lib/LittleWeasel/dictionary.rb +125 -0
  17. data/lib/LittleWeasel/dictionary_key.rb +48 -0
  18. data/lib/LittleWeasel/dictionary_manager.rb +91 -0
  19. data/lib/LittleWeasel/errors/dictionary_file_already_loaded_error.rb +9 -0
  20. data/lib/LittleWeasel/errors/dictionary_file_empty_error.rb +8 -0
  21. data/lib/LittleWeasel/errors/dictionary_file_not_found_error.rb +8 -0
  22. data/lib/LittleWeasel/errors/dictionary_file_too_large_error.rb +16 -0
  23. data/lib/LittleWeasel/errors/language_required_error.rb +8 -0
  24. data/lib/LittleWeasel/errors/must_override_error.rb +8 -0
  25. data/lib/LittleWeasel/filters/en_us/currency_filter.rb +19 -0
  26. data/lib/LittleWeasel/filters/en_us/numeric_filter.rb +19 -0
  27. data/lib/LittleWeasel/filters/en_us/single_character_word_filter.rb +21 -0
  28. data/lib/LittleWeasel/filters/word_filter.rb +59 -0
  29. data/lib/LittleWeasel/filters/word_filter_managable.rb +80 -0
  30. data/lib/LittleWeasel/filters/word_filter_validatable.rb +31 -0
  31. data/lib/LittleWeasel/filters/word_filterable.rb +19 -0
  32. data/lib/LittleWeasel/filters/word_filters_validatable.rb +29 -0
  33. data/lib/LittleWeasel/metadata/dictionary_metadata.rb +145 -0
  34. data/lib/LittleWeasel/metadata/invalid_words_metadata.rb +134 -0
  35. data/lib/LittleWeasel/metadata/invalid_words_service_results.rb +45 -0
  36. data/lib/LittleWeasel/metadata/metadata_observable_validatable.rb +22 -0
  37. data/lib/LittleWeasel/metadata/metadata_observerable.rb +90 -0
  38. data/lib/LittleWeasel/metadata/metadatable.rb +134 -0
  39. data/lib/LittleWeasel/modules/class_name_to_symbol.rb +26 -0
  40. data/lib/LittleWeasel/modules/configurable.rb +26 -0
  41. data/lib/LittleWeasel/modules/deep_dup.rb +11 -0
  42. data/lib/LittleWeasel/modules/dictionary_cache_keys.rb +34 -0
  43. data/lib/LittleWeasel/modules/dictionary_cache_servicable.rb +26 -0
  44. data/lib/LittleWeasel/modules/dictionary_cache_validatable.rb +18 -0
  45. data/lib/LittleWeasel/modules/dictionary_creator_servicable.rb +27 -0
  46. data/lib/LittleWeasel/modules/dictionary_file_loader.rb +67 -0
  47. data/lib/LittleWeasel/modules/dictionary_key_validatable.rb +17 -0
  48. data/lib/LittleWeasel/modules/dictionary_keyable.rb +24 -0
  49. data/lib/LittleWeasel/modules/dictionary_metadata_servicable.rb +29 -0
  50. data/lib/LittleWeasel/modules/dictionary_metadata_validatable.rb +15 -0
  51. data/lib/LittleWeasel/modules/dictionary_source_validatable.rb +15 -0
  52. data/lib/LittleWeasel/modules/dictionary_sourceable.rb +86 -0
  53. data/lib/LittleWeasel/modules/dictionary_validatable.rb +18 -0
  54. data/lib/LittleWeasel/modules/language.rb +24 -0
  55. data/lib/LittleWeasel/modules/language_validatable.rb +14 -0
  56. data/lib/LittleWeasel/modules/locale.rb +23 -0
  57. data/lib/LittleWeasel/modules/order_validatable.rb +16 -0
  58. data/lib/LittleWeasel/modules/orderable.rb +17 -0
  59. data/lib/LittleWeasel/modules/region.rb +24 -0
  60. data/lib/LittleWeasel/modules/region_validatable.rb +14 -0
  61. data/lib/LittleWeasel/modules/tag_validatable.rb +14 -0
  62. data/lib/LittleWeasel/modules/taggable.rb +31 -0
  63. data/lib/LittleWeasel/modules/word_results_validatable.rb +28 -0
  64. data/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor.rb +22 -0
  65. data/lib/LittleWeasel/preprocessors/preprocessed_word.rb +29 -0
  66. data/lib/LittleWeasel/preprocessors/preprocessed_word_validatable.rb +56 -0
  67. data/lib/LittleWeasel/preprocessors/preprocessed_words.rb +59 -0
  68. data/lib/LittleWeasel/preprocessors/preprocessed_words_validatable.rb +28 -0
  69. data/lib/LittleWeasel/preprocessors/word_preprocessable.rb +19 -0
  70. data/lib/LittleWeasel/preprocessors/word_preprocessor.rb +123 -0
  71. data/lib/LittleWeasel/preprocessors/word_preprocessor_managable.rb +114 -0
  72. data/lib/LittleWeasel/preprocessors/word_preprocessor_validatable.rb +40 -0
  73. data/lib/LittleWeasel/preprocessors/word_preprocessors_validatable.rb +24 -0
  74. data/lib/LittleWeasel/services/dictionary_cache_service.rb +211 -0
  75. data/lib/LittleWeasel/services/dictionary_creator_service.rb +94 -0
  76. data/lib/LittleWeasel/services/dictionary_file_loader_service.rb +37 -0
  77. data/lib/LittleWeasel/services/dictionary_killer_service.rb +35 -0
  78. data/lib/LittleWeasel/services/dictionary_metadata_service.rb +116 -0
  79. data/lib/LittleWeasel/services/invalid_words_service.rb +59 -0
  80. data/lib/LittleWeasel/version.rb +3 -1
  81. data/lib/LittleWeasel/word_results.rb +146 -0
  82. data/lib/LittleWeasel.rb +5 -184
  83. data/spec/factories/dictionary.rb +43 -0
  84. data/spec/factories/dictionary_cache_service.rb +95 -0
  85. data/spec/factories/dictionary_creator_service.rb +16 -0
  86. data/spec/factories/dictionary_file_loader_service.rb +13 -0
  87. data/spec/factories/dictionary_hash.rb +39 -0
  88. data/spec/factories/dictionary_key.rb +14 -0
  89. data/spec/factories/dictionary_killer_service.rb +14 -0
  90. data/spec/factories/dictionary_manager.rb +10 -0
  91. data/spec/factories/dictionary_metadata.rb +16 -0
  92. data/spec/factories/dictionary_metadata_service.rb +16 -0
  93. data/spec/factories/numeric_filter.rb +12 -0
  94. data/spec/factories/preprocessed_word.rb +16 -0
  95. data/spec/factories/preprocessed_words.rb +41 -0
  96. data/spec/factories/single_character_word_filter.rb +12 -0
  97. data/spec/factories/word_results.rb +16 -0
  98. data/spec/lib/LittleWeasel/block_results_spec.rb +248 -0
  99. data/spec/lib/LittleWeasel/configure_spec.rb +74 -0
  100. data/spec/lib/LittleWeasel/dictionary_key_spec.rb +118 -0
  101. data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +166 -0
  102. data/spec/lib/LittleWeasel/dictionary_spec.rb +289 -0
  103. data/spec/lib/LittleWeasel/filters/en_us/currency_filter_spec.rb +80 -0
  104. data/spec/lib/LittleWeasel/filters/en_us/numeric_filter_spec.rb +66 -0
  105. data/spec/lib/LittleWeasel/filters/en_us/single_character_word_filter_spec.rb +58 -0
  106. data/spec/lib/LittleWeasel/filters/word_filter_managable_spec.rb +180 -0
  107. data/spec/lib/LittleWeasel/filters/word_filter_spec.rb +151 -0
  108. data/spec/lib/LittleWeasel/filters/word_filter_validatable_spec.rb +94 -0
  109. data/spec/lib/LittleWeasel/filters/word_filters_validatable_spec.rb +48 -0
  110. data/spec/lib/LittleWeasel/integraton_tests/dictionary_integration_spec.rb +201 -0
  111. data/spec/lib/LittleWeasel/metadata/dictionary_creator_servicable_spec.rb +54 -0
  112. data/spec/lib/LittleWeasel/metadata/dictionary_metadata_spec.rb +209 -0
  113. data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +155 -0
  114. data/spec/lib/LittleWeasel/metadata/metadata_observerable_spec.rb +31 -0
  115. data/spec/lib/LittleWeasel/metadata/metadatable_spec.rb +35 -0
  116. data/spec/lib/LittleWeasel/modules/class_name_to_symbol_spec.rb +21 -0
  117. data/spec/lib/LittleWeasel/modules/dictionary_file_loader_spec.rb +125 -0
  118. data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +81 -0
  119. data/spec/lib/LittleWeasel/modules/language_spec.rb +112 -0
  120. data/spec/lib/LittleWeasel/modules/locale_spec.rb +95 -0
  121. data/spec/lib/LittleWeasel/modules/region_spec.rb +112 -0
  122. data/spec/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor_spec.rb +34 -0
  123. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_spec.rb +105 -0
  124. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_validatable_spec.rb +143 -0
  125. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_spec.rb +77 -0
  126. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_validatable_spec.rb +58 -0
  127. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +242 -0
  128. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +218 -0
  129. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_validatable_spec.rb +109 -0
  130. data/spec/lib/LittleWeasel/preprocessors/word_preprocessors_validatable_spec.rb +49 -0
  131. data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +444 -0
  132. data/spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb +119 -0
  133. data/spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb +71 -0
  134. data/spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb +279 -0
  135. data/spec/lib/LittleWeasel/word_results_spec.rb +275 -0
  136. data/spec/lib/LittleWeasel/workflow/workflow_spec.rb +20 -0
  137. data/spec/spec_helper.rb +117 -6
  138. data/spec/support/factory_bot.rb +15 -0
  139. data/spec/support/file_helpers.rb +46 -0
  140. data/spec/support/files/empty-dictionary.txt +0 -0
  141. data/{lib/dictionary → spec/support/files/en-US-big.txt} +262156 -31488
  142. data/spec/support/files/en-US-tagged.txt +26 -0
  143. data/spec/support/files/en-US.txt +26 -0
  144. data/spec/support/files/en.txt +26 -0
  145. data/spec/support/files/es-ES.txt +27 -0
  146. data/spec/support/files/es.txt +27 -0
  147. data/spec/support/general_helpers.rb +68 -0
  148. data/spec/support/shared_contexts.rb +107 -0
  149. data/spec/support/shared_examples.rb +105 -0
  150. metadata +378 -38
  151. data/spec/checker/checker_spec.rb +0 -286
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Modules::DictionarySourceable, type: :module do
6
+ subject { MockDictionarySourceable.new(dictionary_memory_source) }
7
+
8
+ DictionarySourceable = described_class
9
+
10
+ class MockDictionarySourceable
11
+ include DictionarySourceable
12
+
13
+ def initialize(dictionary_source)
14
+ self.dictionary_source = dictionary_source
15
+ end
16
+ end
17
+
18
+ let(:dictionary_memory_source) { described_class.memory_source }
19
+ let(:dictionary_file_source) { language_dictionary_path language: :en }
20
+
21
+ #.MEMORY_SOURCE
22
+ describe '::MEMORY_SOURCE' do
23
+ it 'returns the memory source prefix' do
24
+ expect(described_class::MEMORY_SOURCE).to eq '*'
25
+ end
26
+ end
27
+
28
+ #.memory_source
29
+ describe '.memory_source' do
30
+ it 'returns a new memory source' do
31
+ expect(described_class.memory_source).to be_truthy
32
+ end
33
+ end
34
+
35
+ #.file_source?
36
+ describe '.file_source?' do
37
+ context 'when dictionary_source is a file source' do
38
+ it 'returns truthy' do
39
+ expect(described_class.file_source? dictionary_file_source).to be_truthy
40
+ end
41
+ end
42
+
43
+ context 'when dictionary_source is NOT a file source' do
44
+ it 'returns falsey' do
45
+ expect(described_class.file_source? dictionary_memory_source).to be_falsey
46
+ end
47
+ end
48
+ end
49
+
50
+ #.memory_source?
51
+ describe '.memory_source?' do
52
+ context 'when dictionary_source is a memory source' do
53
+ it 'returns truthy if argument is a valid memory source' do
54
+ expect(described_class.memory_source? '*12345678').to be_truthy
55
+ expect(described_class.memory_source? '*abcdef00').to be_truthy
56
+ expect(described_class.memory_source? '*ABCDEF00').to be_truthy
57
+ expect(described_class.memory_source? '*aBcDeF00').to be_truthy
58
+ end
59
+
60
+ it 'returns falsey if argument is NOT a memory source' do
61
+ expect(described_class.memory_source? '*123456789').to be_falsey
62
+ expect(described_class.memory_source? '*abcdefg0').to be_falsey
63
+ expect(described_class.memory_source? '*ABCDEFG0').to be_falsey
64
+ expect(described_class.memory_source? '*aBcDeFg0').to be_falsey
65
+ expect(described_class.memory_source? '$12345678').to be_falsey
66
+
67
+ expect(described_class.memory_source? '123456789').to be_falsey
68
+ expect(described_class.memory_source? 'abcdefg0').to be_falsey
69
+ expect(described_class.memory_source? 'ABCDEFG0').to be_falsey
70
+ expect(described_class.memory_source? 'aBcDeFg0').to be_falsey
71
+ expect(described_class.memory_source? '123456789').to be_falsey
72
+ end
73
+ end
74
+
75
+ context 'when dictionary_source is a file source' do
76
+ it 'returns falsey' do
77
+ expect(described_class.memory_source? dictionary_file_source).to be_falsey
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Modules::Language, type: :module do
6
+ Language = described_class
7
+
8
+ subject do
9
+ Class.new do
10
+ include Language
11
+
12
+ attr_reader :language
13
+
14
+ def initialize(language)
15
+ self.language = language
16
+ end
17
+
18
+ private
19
+
20
+ attr_writer :language
21
+ end.new(language)
22
+ end
23
+
24
+ let(:language) {}
25
+
26
+ #language?
27
+ describe '#language?' do
28
+ context 'when language is present?' do
29
+ let(:language) { :es }
30
+
31
+ it 'returns true' do
32
+ expect(subject.language?).to eq true
33
+ end
34
+ end
35
+
36
+ context 'when language is NOT present?' do
37
+ it 'returns false' do
38
+ expect(subject.language?).to eq false
39
+ end
40
+ end
41
+ end
42
+
43
+ #normalize_language!
44
+ describe '#normalize_language!' do
45
+ context 'when language is present?' do
46
+ context 'when language responds to #upcase!' do
47
+ before do
48
+ subject.normalize_language!
49
+ end
50
+
51
+ let(:language) { :AA }
52
+
53
+ it 'changes language to lower case' do
54
+ expect(subject.language).to eq :aa
55
+ end
56
+ end
57
+
58
+ context 'when language DOES NOT respond to #downcase' do
59
+ let(:language) { Object.new }
60
+
61
+ it 'raises an error' do
62
+ expect { subject.normalize_language! }.to raise_error(NoMethodError, /undefined method `downcase'/)
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'when language is NOT present?' do
68
+ before do
69
+ subject.normalize_language!
70
+ end
71
+
72
+ it 'does nothing' do
73
+ expect(subject.language).to be_nil
74
+ end
75
+ end
76
+ end
77
+
78
+ #.normalize_language
79
+ describe '#.normalize_language' do
80
+ context 'with a non-nil language' do
81
+ context 'when passing a Symbol' do
82
+ let(:language) { :AbCdEfG }
83
+
84
+ it 'converts the language to a lower-case Symbol' do
85
+ expect(described_class.normalize_language(language)).to eq :abcdefg
86
+ end
87
+ end
88
+
89
+ context 'when passing a String' do
90
+ let(:language) { 'AbCdEfG' }
91
+
92
+ it 'converts the language to a lower-case String' do
93
+ expect(described_class.normalize_language(language)).to eq 'abcdefg'
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'with a nil language' do
99
+ it 'returns nil' do
100
+ expect(described_class.normalize_language(language)).to be_nil
101
+ end
102
+ end
103
+
104
+ context 'when language does not respond to #downcase' do
105
+ let(:language) { 1 }
106
+
107
+ it 'returns nil' do
108
+ expect { described_class.normalize_language(language) }.to raise_error(NoMethodError, /undefined method `downcase'/)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Modules::Locale, type: :module do
6
+ Locale = described_class
7
+
8
+ subject do
9
+ Class.new do
10
+ include Locale
11
+
12
+ attr_reader :language, :region
13
+
14
+ def initialize(language, region)
15
+ self.language = language
16
+ self.region = region
17
+ end
18
+
19
+ private
20
+
21
+ attr_writer :language, :region
22
+ end.new(language, region)
23
+ end
24
+
25
+ let(:language) {}
26
+ let(:region) {}
27
+
28
+ #locale
29
+ describe '#locale' do
30
+ context 'with valid arguments' do
31
+ context 'with valid language' do
32
+ let(:language) { :en }
33
+
34
+ it 'returns the expected locale (language only)' do
35
+ expect(subject.locale).to eq 'en'
36
+ end
37
+ end
38
+
39
+ context 'with valid language and region' do
40
+ let(:language) { :en }
41
+ let(:region) { :us }
42
+
43
+ it 'returns the expected locale (language and region)' do
44
+ expect(subject.locale).to eq 'en-US'
45
+ end
46
+
47
+ describe 'normalizes language and region to the proper case' do
48
+ let(:language) { :EN }
49
+ let(:region) { :us }
50
+
51
+ it 'returns the expected locale with language lowercase and region uppercase' do
52
+ expect(subject.locale).to eq 'en-US'
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'with valid language and nil region' do
58
+ let(:language) { :en }
59
+ let(:region) {}
60
+
61
+ it 'returns the expected locale (language only)' do
62
+ expect(subject.locale).to eq 'en'
63
+ end
64
+ end
65
+
66
+ context 'with valid language and blank region' do
67
+ let(:language) { :en }
68
+ let(:region) { '' }
69
+
70
+ it 'returns the expected locale (language only)' do
71
+ expect(subject.locale).to eq 'en'
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'with invalid arguments' do
77
+ context 'when argument language does not respond to #downcase' do
78
+ let(:language) { 1 }
79
+
80
+ it 'raises an error' do
81
+ expect { subject.locale }.to raise_error(NoMethodError, /undefined method `downcase'/)
82
+ end
83
+ end
84
+
85
+ context 'when argument region does not respond to #upcase' do
86
+ let(:language) { :en }
87
+ let(:region) { 1 }
88
+
89
+ it 'raises an error' do
90
+ expect { subject.locale }.to raise_error(NoMethodError, /undefined method `upcase'/)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Modules::Region, type: :module do
6
+ Region = described_class
7
+
8
+ subject do
9
+ Class.new do
10
+ include Region
11
+
12
+ attr_reader :region
13
+
14
+ def initialize(region)
15
+ self.region = region
16
+ end
17
+
18
+ private
19
+
20
+ attr_writer :region
21
+ end.new(region)
22
+ end
23
+
24
+ let(:region) {}
25
+
26
+ #region?
27
+ describe '#region?' do
28
+ context 'when region is present?' do
29
+ let(:region) { :es }
30
+
31
+ it 'returns true' do
32
+ expect(subject.region?).to eq true
33
+ end
34
+ end
35
+
36
+ context 'when region is NOT present?' do
37
+ it 'returns false' do
38
+ expect(subject.region?).to eq false
39
+ end
40
+ end
41
+ end
42
+
43
+ #normalize_region!
44
+ describe '#normalize_region!' do
45
+ context 'when region is present?' do
46
+ context 'when region responds to #upcase' do
47
+ before do
48
+ subject.normalize_region!
49
+ end
50
+
51
+ let(:region) { :aa }
52
+
53
+ it 'changes region to upper case' do
54
+ expect(subject.region).to eq :AA
55
+ end
56
+ end
57
+
58
+ context 'when region DOES NOT respond to #upcase' do
59
+ let(:region) { Object.new }
60
+
61
+ it 'raises an error' do
62
+ expect { subject.normalize_region! }.to raise_error(NoMethodError, /undefined method `upcase'/)
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'when region is NOT present?' do
68
+ before do
69
+ subject.normalize_region!
70
+ end
71
+
72
+ it 'does nothing' do
73
+ expect(subject.region).to be_nil
74
+ end
75
+ end
76
+ end
77
+
78
+ #.normalize_region
79
+ describe '#.normalize_region' do
80
+ context 'with a non-nil region' do
81
+ context 'when passing a Symbol' do
82
+ let(:region) { :AbCdEfG }
83
+
84
+ it 'converts the region to a upper-case Symbol' do
85
+ expect(described_class.normalize_region(region)).to eq :ABCDEFG
86
+ end
87
+ end
88
+
89
+ context 'when passing a String' do
90
+ let(:region) { 'AbCdEfG' }
91
+
92
+ it 'converts the region to a upper-case String' do
93
+ expect(described_class.normalize_region(region)).to eq 'ABCDEFG'
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'with a nil region' do
99
+ it 'returns nil' do
100
+ expect(described_class.normalize_region(region)).to be_nil
101
+ end
102
+ end
103
+
104
+ context 'when region does not respond to #upcase' do
105
+ let(:region) { 1 }
106
+
107
+ it 'returns nil' do
108
+ expect { described_class.normalize_region(region) }.to raise_error(NoMethodError, /undefined method `upcase'/)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literals: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Preprocessors::EnUs::CapitalizePreprocessor do
6
+ subject { described_class.new }
7
+
8
+ #.new
9
+ describe '.new' do
10
+ it 'instantiates the object' do
11
+ expect { subject }.to_not raise_error
12
+ end
13
+
14
+ describe '#order' do
15
+ it 'sets #order to 0 by default' do
16
+ expect(subject.order).to eq 0
17
+ end
18
+ end
19
+
20
+ describe '#preprocessor_on' do
21
+ it 'sets #preprocessor_on to true by default' do
22
+ expect(subject.preprocessor_on).to eq true
23
+ end
24
+ end
25
+ end
26
+
27
+ #.preprocess
28
+ describe '.preprocess' do
29
+ it 'processes and capitalizes the word' do
30
+ expect(described_class.preprocess 'wOrD').to eq [true, 'Word']
31
+ expect(described_class.preprocess 'Word').to eq [true, 'Word']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Preprocessors::PreprocessedWord do
6
+ subject do
7
+ described_class.new(
8
+ original_word: original_word,
9
+ preprocessed_word: preprocessed_word,
10
+ preprocessor: preprocessor,
11
+ preprocessed: preprocessed,
12
+ preprocessor_order: preprocessor_order
13
+ )
14
+ end
15
+
16
+ let(:original_word) { :original_word }
17
+ let(:preprocessed_word) { :preprocessed_word }
18
+ let(:preprocessor) { :preprocessor }
19
+ let(:preprocessed) { true }
20
+ let(:preprocessor_order) { :preprocessor_order }
21
+
22
+ #.new
23
+ describe '.new' do
24
+ context 'initializes the attributes' do
25
+ describe '#original_word' do
26
+ it 'is initialized' do
27
+ expect(subject.original_word).to eq :original_word
28
+ end
29
+ end
30
+
31
+ describe '#preprocessed_word' do
32
+ it 'is initialized' do
33
+ expect(subject.preprocessed_word).to eq :preprocessed_word
34
+ end
35
+ end
36
+
37
+ describe '#preprocessor' do
38
+ it 'is initialized' do
39
+ expect(subject.preprocessor).to eq :preprocessor
40
+ end
41
+ end
42
+
43
+ describe '#preprocessor_order' do
44
+ it 'is initialized' do
45
+ expect(subject.preprocessor_order).to eq :preprocessor_order
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # attributes
52
+ context 'attributes' do
53
+ describe 'original_word=' do
54
+ let(:changed_to) { :original_word_changed }
55
+
56
+ it 'sets the attribute' do
57
+ subject.original_word = changed_to
58
+ expect(subject.original_word).to eq changed_to
59
+ end
60
+ end
61
+
62
+ describe 'preprocessed_word=' do
63
+ let(:changed_to) { :preprocessed_word_changed }
64
+
65
+ it 'sets the attribute' do
66
+ subject.preprocessed_word = changed_to
67
+ expect(subject.preprocessed_word).to eq changed_to
68
+ end
69
+ end
70
+
71
+ describe 'preprocessor=' do
72
+ let(:changed_to) { :preprocessor_changed }
73
+
74
+ it 'sets the attribute' do
75
+ subject.preprocessor = changed_to
76
+ expect(subject.preprocessor).to eq changed_to
77
+ end
78
+ end
79
+
80
+ describe 'preprocessor_order=' do
81
+ let(:changed_to) { :preprocessor_order_changed }
82
+
83
+ it 'sets the attribute' do
84
+ subject.preprocessor_order = changed_to
85
+ expect(subject.preprocessor_order).to eq changed_to
86
+ end
87
+ end
88
+
89
+ describe '#preprocessed?' do
90
+ context 'when preprocessed is true' do
91
+ it 'returns true' do
92
+ expect(subject.preprocessed?).to eq true
93
+ end
94
+ end
95
+
96
+ context 'when preprocessed is false' do
97
+ let(:preprocessed) { false }
98
+
99
+ it 'returns false' do
100
+ expect(subject.preprocessed?).to eq false
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe LittleWeasel::Preprocessors::PreprocessedWordValidatable, type: :module do
6
+ PreprocessedWordValidatable = described_class
7
+
8
+ class MockSubject
9
+ include PreprocessedWordValidatable
10
+ end
11
+
12
+ subject do
13
+ MockSubject.new
14
+ end
15
+
16
+ before do
17
+ allow(preprocessed_word_object).to receive(:respond_to?).and_call_original
18
+ end
19
+
20
+ let(:preprocessed_word_object) do
21
+ create(:preprocessed_word,
22
+ original_word: original_word,
23
+ preprocessed: preprocessed,
24
+ preprocessed_word: preprocessed_word,
25
+ preprocessor: preprocessor,
26
+ preprocessor_order: preprocessor_order)
27
+ end
28
+ let(:original_word) { 'word' }
29
+ let(:preprocessed) { true }
30
+ let(:preprocessed_word) { 'preprocessed-word0'}
31
+ let(:preprocessor) { :preprocesor0 }
32
+ let(:preprocessor_order) { 0 }
33
+
34
+ #.validate_prepreprocessed_word
35
+ describe '.validate_prepreprocessed_word' do
36
+ context 'when the object is valid' do
37
+ it 'does not raise an error' do
38
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to_not raise_error
39
+ end
40
+ end
41
+
42
+ context 'when the object is INVALID' do
43
+ context 'when #original_word is missing' do
44
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
45
+ let(:method) { :original_word }
46
+
47
+ it 'raises an eror' do
48
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
49
+ end
50
+ end
51
+
52
+ context 'when #original_word= is missing' do
53
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
54
+ let(:method) { :original_word= }
55
+
56
+ it 'raises an eror' do
57
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
58
+ end
59
+ end
60
+
61
+ context 'when #preprocessed_word is missing' do
62
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
63
+ let(:method) { :preprocessed_word }
64
+
65
+ it 'raises an eror' do
66
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
67
+ end
68
+ end
69
+
70
+ context 'when #preprocessed_word= is missing' do
71
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
72
+ let(:method) { :preprocessed_word= }
73
+
74
+ it 'raises an eror' do
75
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
76
+ end
77
+ end
78
+
79
+ context 'when #preprocessed is missing' do
80
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
81
+ let(:method) { :preprocessed }
82
+
83
+ it 'raises an eror' do
84
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
85
+ end
86
+ end
87
+
88
+ context 'when #preprocessed= is missing' do
89
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
90
+ let(:method) { :preprocessed= }
91
+
92
+ it 'raises an eror' do
93
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
94
+ end
95
+ end
96
+
97
+ context 'when #preprocessed? is missing' do
98
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
99
+ let(:method) { :preprocessed? }
100
+
101
+ it 'raises an eror' do
102
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
103
+ end
104
+ end
105
+
106
+ context 'when #preprocessor is missing' do
107
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
108
+ let(:method) { :preprocessor }
109
+
110
+ it 'raises an eror' do
111
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
112
+ end
113
+ end
114
+
115
+ context 'when #preprocessor= is missing' do
116
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
117
+ let(:method) { :preprocessor= }
118
+
119
+ it 'raises an eror' do
120
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
121
+ end
122
+ end
123
+
124
+ context 'when #preprocessor_order is missing' do
125
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
126
+ let(:method) { :preprocessor_order }
127
+
128
+ it 'raises an eror' do
129
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
130
+ end
131
+ end
132
+
133
+ context 'when #preprocessor_order= is missing' do
134
+ before { allow(preprocessed_word_object).to receive(:respond_to?).with(method).and_return(false) }
135
+ let(:method) { :preprocessor_order= }
136
+
137
+ it 'raises an eror' do
138
+ expect { PreprocessedWordValidatable.validate_prepreprocessed_word(preprocessed_word: preprocessed_word_object) }.to raise_error(/Argument preprocessed_word: does not respond to.+#{method}/)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end