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.
@@ -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
@@ -1,4 +0,0 @@
1
- module SpecAddons
2
- class TestClass
3
- end
4
- end
@@ -1,8 +0,0 @@
1
- RSpec.describe MessagesDictionary::Dict do
2
- subject { described_class.new key: 'value' }
3
-
4
- it "allows indifferent access" do
5
- expect(subject[:key]).to eq('value')
6
- expect(subject['key']).to eq('value')
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- RSpec.describe MessagesDictionary::SpecialString do
2
- subject { described_class.new('MyTestString') }
3
-
4
- specify "#snake_case" do
5
- expect(subject.snake_case).to eq('my_test_string')
6
- end
7
- end