|
19 | 19 | before(:each) do |
20 | 20 | PhraseApp::InContextEditor.config.prefix = "{{__" |
21 | 21 | PhraseApp::InContextEditor.config.suffix = "__}}" |
22 | | - I18n.stub(:translate_without_phraseapp).with(key_name).and_return(i18n_translation) |
23 | | - phraseapp_service.stub(:has_blacklist_entry_for_key?){ key_is_blacklisted } |
24 | | - phraseapp_service.stub(:key_is_ignored?) { key_is_ignored } |
| 22 | + allow(I18n).to receive(:translate_without_phraseapp).with(key_name).and_return(i18n_translation) |
| 23 | + allow(phraseapp_service).to receive(:has_blacklist_entry_for_key?){ key_is_blacklisted } |
| 24 | + allow(phraseapp_service).to receive(:key_is_ignored?) { key_is_ignored } |
25 | 25 | end |
26 | 26 |
|
27 | 27 | subject { phraseapp_service.translate(*args) } |
|
35 | 35 | let(:args){ [key_name] } |
36 | 36 | let(:key_is_blacklisted){ true } |
37 | 37 |
|
38 | | - it { should eql i18n_translation } |
| 38 | + it { is_expected.to eql i18n_translation } |
39 | 39 | end |
40 | 40 |
|
41 | 41 | context "key is ignored" do |
42 | 42 | let(:args) { [key_name] } |
43 | 43 | let(:key_is_ignored) { true } |
44 | 44 |
|
45 | | - it { should eql i18n_translation } |
| 45 | + it { is_expected.to eql i18n_translation } |
46 | 46 | end |
47 | 47 |
|
48 | 48 | context "resolve: false given as argument" do |
49 | 49 | let(:args){ [key_name, resolve: false] } |
50 | 50 |
|
51 | 51 | before(:each) do |
52 | | - I18n.stub(:translate_without_phraseapp).with(key_name, resolve: false).and_return(i18n_translation) |
| 52 | + allow(I18n).to receive(:translate_without_phraseapp).with(key_name, resolve: false).and_return(i18n_translation) |
53 | 53 | end |
54 | 54 |
|
55 | | - it { should eql i18n_translation } |
| 55 | + it { is_expected.to eql i18n_translation } |
56 | 56 | end |
57 | 57 |
|
58 | 58 | context "resolve: true given as argument" do |
59 | 59 | let(:args){ [key_name, resolve: true] } |
60 | 60 |
|
61 | | - it { should be_a String } |
62 | | - it { should eql '{{__phrase_foo.bar__}}' } |
| 61 | + it { is_expected.to be_a String } |
| 62 | + it { is_expected.to eql '{{__phrase_foo.bar__}}' } |
63 | 63 | end |
64 | 64 |
|
65 | 65 | context "key is not blacklisted" do |
66 | 66 | let(:args){ [key_name] } |
67 | 67 | let(:key_is_blacklisted){ false } |
68 | 68 |
|
69 | | - it { should be_a PhraseApp::InContextEditor::Delegate::I18nDelegate } |
70 | | - it { should eql '{{__phrase_foo.bar__}}' } |
| 69 | + it { is_expected.to be_a PhraseApp::InContextEditor::Delegate::I18nDelegate } |
| 70 | + it { is_expected.to eql '{{__phrase_foo.bar__}}' } |
71 | 71 | end |
72 | 72 |
|
73 | 73 | describe "different arguments given" do |
74 | 74 | context "default array given", vcr: {cassette_name: 'fetch list of keys filtered by fallback key names'} do |
75 | 75 | let(:args){ [:key, { :default => [:first_fallback, :second_fallback] }] } |
76 | | - it { should eql '{{__phrase_key__}}' } |
| 76 | + it { is_expected.to eql '{{__phrase_key__}}' } |
77 | 77 | end |
78 | 78 |
|
79 | 79 | context "default string given" do |
80 | 80 | let(:args){ [:key, { :default => 'first fallback' }] } |
81 | 81 |
|
82 | | - it { should eql '{{__phrase_key__}}' } |
| 82 | + it { is_expected.to eql '{{__phrase_key__}}' } |
83 | 83 | end |
84 | 84 |
|
85 | 85 | context "scope array given" do |
86 | | - let(:context_key_translation){ stub } |
| 86 | + let(:context_key_translation){ double } |
87 | 87 | let(:args){ [:key, { :scope => [:context] }] } |
88 | 88 |
|
89 | | - it { should eql '{{__phrase_context.key__}}' } |
| 89 | + it { is_expected.to eql '{{__phrase_context.key__}}' } |
90 | 90 | end |
91 | 91 | end |
92 | 92 | end |
|
98 | 98 | PhraseApp::InContextEditor.enabled = false |
99 | 99 | end |
100 | 100 |
|
101 | | - it { should eql i18n_translation } |
| 101 | + it { is_expected.to eql i18n_translation } |
102 | 102 |
|
103 | 103 | context "given arguments other than key_name" do |
104 | 104 | let(:args){ [key_name, locale: :ru] } |
105 | 105 | let(:ru_translation){ double } |
106 | 106 |
|
107 | 107 | before(:each) do |
108 | | - I18n.stub(:translate_without_phraseapp).with(key_name, locale: :ru){ ru_translation } |
| 108 | + allow(I18n).to receive(:translate_without_phraseapp).with(key_name, locale: :ru){ ru_translation } |
109 | 109 | end |
110 | 110 |
|
111 | | - it { should eql ru_translation } |
| 111 | + it { is_expected.to eql ru_translation } |
112 | 112 | end |
113 | 113 |
|
114 | 114 | describe "different arguments given" do |
115 | 115 | before(:each) do |
116 | | - I18n.unstub(:translate_without_phraseapp) |
| 116 | + allow(I18n).to receive(:translate_without_phraseapp).and_call_original |
117 | 117 | end |
118 | 118 |
|
119 | 119 | context "default array given" do |
120 | 120 | let(:args) { [:key, { :default => [:first_fallback, :second_fallback] }] } |
121 | 121 |
|
122 | | - specify { subject.should eql "translation missing: en.key" } |
| 122 | + it { is_expected.to eql "translation missing: en.key" } |
123 | 123 | end |
124 | 124 |
|
125 | 125 | context "default string given" do |
126 | 126 | let(:args) { [:key, { :default => 'first fallback' }] } |
127 | 127 |
|
128 | | - it { should eql 'first fallback' } |
| 128 | + it { is_expected.to eql 'first fallback' } |
129 | 129 | end |
130 | 130 |
|
131 | 131 | context "scope array given" do |
132 | | - let(:context_key_translation) { stub } |
| 132 | + let(:context_key_translation) { double } |
133 | 133 | let(:args) { [:key, { :scope => [:context] }] } |
134 | 134 |
|
135 | | - specify { subject.should eql "translation missing: en.context.key" } |
| 135 | + it { is_expected.to eql "translation missing: en.context.key" } |
136 | 136 | end |
137 | 137 | end |
138 | 138 | end |
|
143 | 143 | subject { phraseapp_service.send(:has_blacklist_entry_for_key?, key) } |
144 | 144 |
|
145 | 145 | before(:each) do |
146 | | - phraseapp_service.stub(:blacklisted_keys){ blacklisted_keys } |
| 146 | + allow(phraseapp_service).to receive(:blacklisted_keys){ blacklisted_keys } |
147 | 147 | end |
148 | 148 |
|
149 | 149 | context "blacklisted_keys contain key" do |
150 | 150 | let(:blacklisted_keys){ [key] } |
151 | | - it { should be_truthy } |
| 151 | + it { is_expected.to be_truthy } |
152 | 152 | end |
153 | 153 |
|
154 | 154 | context "key is blacklisted (using wildcards)" do |
155 | 155 | let(:blacklisted_keys){ ["foo.black*"] } |
156 | | - it { should be_truthy } |
| 156 | + it { is_expected.to be_truthy } |
157 | 157 | end |
158 | 158 |
|
159 | 159 | context "if no blacklisted_keys" do |
160 | 160 | let(:blacklisted_keys){ [] } |
161 | | - it { should be_falsey } |
| 161 | + it { is_expected.to be_falsey } |
162 | 162 | end |
163 | 163 | end |
164 | 164 |
|
|
174 | 174 | context "blacklisted_keys contain key" do |
175 | 175 | let(:ignored_keys) { ["foo.ignored"] } |
176 | 176 |
|
177 | | - it { should be_truthy } |
| 177 | + it { is_expected.to be_truthy } |
178 | 178 | end |
179 | 179 |
|
180 | 180 | context "key is ignores (using wildcards)" do |
181 | 181 | let(:ignored_keys) { ["foo.*"] } |
182 | 182 |
|
183 | | - it { should be_truthy } |
| 183 | + it { is_expected.to be_truthy } |
184 | 184 | end |
185 | 185 |
|
186 | 186 | context "if no keys are ignored" do |
187 | 187 | let(:ignored_keys) { [] } |
188 | 188 |
|
189 | | - it { should be_falsey } |
| 189 | + it { is_expected.to be_falsey } |
190 | 190 | end |
191 | 191 | end |
192 | 192 |
|
193 | 193 | describe "#blacklisted_keys", vcr: {cassette_name: 'fetch list of blacklisted keys'} do |
194 | 194 | subject { phraseapp_service.send(:blacklisted_keys) } |
195 | 195 |
|
196 | | - it { should eql ["faker*"] } |
| 196 | + it { is_expected.to eql ["faker*"] } |
197 | 197 |
|
198 | 198 | describe "memoizing the blacklisted_keys" do |
199 | 199 | specify do |
200 | 200 | old_id = phraseapp_service.send(:blacklisted_keys).object_id |
201 | | - old_id.should eql subject.object_id |
| 201 | + expect(old_id).to eql subject.object_id |
202 | 202 | end |
203 | 203 | end |
204 | 204 | end |
|
208 | 208 |
|
209 | 209 | context 'default case' do |
210 | 210 | let(:args) { ['my.key', {}] } |
211 | | - it { should == 'my.key'} |
| 211 | + it { is_expected.to eql 'my.key'} |
212 | 212 | end |
213 | 213 |
|
214 | 214 | context 'the leading dot should be removed' do |
215 | 215 | let(:args) { ['.my.key', {}] } |
216 | | - it { should == 'my.key'} |
| 216 | + it { is_expected.to eql 'my.key'} |
217 | 217 | end |
218 | 218 | end |
219 | 219 | end |
0 commit comments