messages_dictionary 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODE_OF_CONDUCT.md +46 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +24 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +13 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +27 -0
- data/.gitignore +11 -3
- data/.rubocop.yml +46 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +66 -29
- data/LICENSE +1 -1
- data/README.md +20 -14
- data/Rakefile +39 -2
- data/lib/messages_dictionary/injector.rb +72 -27
- data/lib/messages_dictionary/utils/dict.rb +9 -4
- data/lib/messages_dictionary/utils/string_utils.rb +21 -0
- data/lib/messages_dictionary/version.rb +4 -2
- data/lib/messages_dictionary.rb +20 -4
- data/messages_dictionary.gemspec +28 -17
- data/spec/lib/messages_dictionary/injector_spec.rb +168 -0
- data/spec/lib/messages_dictionary/utils/dict_spec.rb +10 -0
- data/spec/lib/messages_dictionary_spec.rb +20 -0
- data/spec/spec_helper.rb +15 -6
- data/spec/support/spec_files_setup.rb +10 -5
- data/spec/support/spec_utils.rb +16 -20
- metadata +114 -23
- data/.travis.yml +0 -12
- data/lib/messages_dictionary/utils/snake_case.rb +0 -17
- data/spec/injector_spec.rb +0 -146
- data/spec/support/test_class.rb +0 -4
- data/spec/utils/dict_spec.rb +0 -8
- data/spec/utils/snake_case_spec.rb +0 -7
data/spec/injector_spec.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
RSpec.describe MessagesDictionary do
|
2
|
-
before :all do
|
3
|
-
@subject = SpecAddons::TestClass
|
4
|
-
@subject.class_eval do
|
5
|
-
include MessagesDictionary
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@subject.class_eval do
|
11
|
-
remove_const(:DICTIONARY_CONF) if const_defined?(:DICTIONARY_CONF)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "messages" do
|
16
|
-
context "outputting" do
|
17
|
-
it "uses STDOUT by default" do
|
18
|
-
@subject.class_eval do
|
19
|
-
has_messages_dictionary messages: {test: 'string'}
|
20
|
-
end
|
21
|
-
|
22
|
-
expect(@subject::DICTIONARY_CONF[:output]).to eq(STDOUT)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "uses puts method by default" do
|
26
|
-
@subject.class_eval do
|
27
|
-
has_messages_dictionary messages: {test: 'string'}
|
28
|
-
end
|
29
|
-
|
30
|
-
expect(@subject::DICTIONARY_CONF[:method]).to eq(:puts)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "allows customizing output and method" do
|
34
|
-
output = double('output')
|
35
|
-
@subject.class_eval do
|
36
|
-
has_messages_dictionary messages: {test: 'string'}, output: output, method: :custom_puts
|
37
|
-
end
|
38
|
-
|
39
|
-
object = @subject.new
|
40
|
-
expect(output).to receive(:custom_puts).with('string')
|
41
|
-
object.send(:pretty_output, :test)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "aliases pretty_output as pou" do
|
45
|
-
output = double('output')
|
46
|
-
@subject.class_eval do
|
47
|
-
has_messages_dictionary messages: {test: 'string'}, output: output
|
48
|
-
end
|
49
|
-
|
50
|
-
object = @subject.new
|
51
|
-
expect(output).to receive(:puts).with('string')
|
52
|
-
object.send(:pou, :test)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "passed as hash" do
|
57
|
-
it "supports nesting" do
|
58
|
-
@subject.class_eval do
|
59
|
-
has_messages_dictionary messages: {parent: {child: 'child_string'} }
|
60
|
-
end
|
61
|
-
|
62
|
-
object = @subject.new
|
63
|
-
expect( object.send(:pretty_output, 'parent.child') {|msg| msg} ).to eq('child_string')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "passed in file" do
|
68
|
-
it "searches file named after class name by default" do
|
69
|
-
setup_env!('spec_addons', 'test_class.yml')
|
70
|
-
|
71
|
-
@subject.class_eval do
|
72
|
-
has_messages_dictionary
|
73
|
-
end
|
74
|
-
|
75
|
-
object = @subject.new
|
76
|
-
expect( object.send(:pretty_output, :test) {|msg| msg} ).to eq('string')
|
77
|
-
clear_env!('spec_addons')
|
78
|
-
end
|
79
|
-
|
80
|
-
it "allows passing path and file" do
|
81
|
-
setup_env!('my_test_dir', 'my_test_file.yml')
|
82
|
-
|
83
|
-
@subject.class_eval do
|
84
|
-
has_messages_dictionary file: 'my_test_file.yml', dir: 'my_test_dir'
|
85
|
-
end
|
86
|
-
|
87
|
-
object = @subject.new
|
88
|
-
expect( object.send(:pretty_output, :test) {|msg| msg} ).to eq('string')
|
89
|
-
clear_env!('my_test_dir')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "error" do
|
95
|
-
it "is raised when key is not found" do
|
96
|
-
@subject.class_eval do
|
97
|
-
has_messages_dictionary messages: {test: 'string'}
|
98
|
-
end
|
99
|
-
|
100
|
-
object = @subject.new
|
101
|
-
expect( -> {object.send(:pretty_output, :does_not_exist)} ).to raise_error(KeyError)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "is raised when file is not found and the program aborts" do
|
105
|
-
err = capture_stderr do
|
106
|
-
expect(-> {
|
107
|
-
@subject.class_eval do
|
108
|
-
has_messages_dictionary dir: 'random', file: 'not_exist.yml'
|
109
|
-
end
|
110
|
-
}).to raise_error(SystemExit)
|
111
|
-
end.strip
|
112
|
-
expect(err).to eq("File #{File.expand_path('random/not_exist.yml')} does not exist...")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "transformations" do
|
117
|
-
it "applies per-method transformations" do
|
118
|
-
@subject.class_eval do
|
119
|
-
has_messages_dictionary messages: {test: 'string'}
|
120
|
-
end
|
121
|
-
|
122
|
-
object = @subject.new
|
123
|
-
expect( object.send(:pretty_output, :test) {|msg| msg.upcase!} ).to eq('STRING')
|
124
|
-
end
|
125
|
-
|
126
|
-
it "applies per-class transformations" do
|
127
|
-
@subject.class_eval do
|
128
|
-
has_messages_dictionary messages: {test: 'string'},
|
129
|
-
transform: ->(msg) {msg.upcase!}
|
130
|
-
end
|
131
|
-
|
132
|
-
object = @subject.new
|
133
|
-
expect( object.send(:pretty_output, :test) ).to eq('STRING')
|
134
|
-
end
|
135
|
-
|
136
|
-
it "per-method takes higher priority than per-class" do
|
137
|
-
@subject.class_eval do
|
138
|
-
has_messages_dictionary messages: {test: 'string'},
|
139
|
-
transform: ->(msg) {msg.reverse!}
|
140
|
-
end
|
141
|
-
|
142
|
-
object = @subject.new
|
143
|
-
expect( object.send(:pretty_output, :test) {|msg| msg.upcase!} ).to eq('STRING')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
data/spec/support/test_class.rb
DELETED
data/spec/utils/dict_spec.rb
DELETED