Skip to content

Commit d767272

Browse files
committed
Tests: Upgrade to modern RSpec syntax
Replace should and stub with expect etc.
1 parent ebf52ee commit d767272

9 files changed

Lines changed: 106 additions & 107 deletions

File tree

spec/in_context_editor_spec.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
end
1010
end
1111

12-
specify { PhraseApp::InContextEditor.prefix.should eql("my prefix") }
13-
specify { PhraseApp::InContextEditor.suffix.should eql("my suffix") }
12+
specify { expect(PhraseApp::InContextEditor.prefix).to eql("my prefix") }
13+
specify { expect(PhraseApp::InContextEditor.suffix).to eql("my suffix") }
1414
end
1515

1616
describe "#self.with_config(config_options={}, &block)" do
1717
it "should allow to set a config that is only present in a given block" do
1818
PhraseApp::InContextEditor.config.project_id = "old-project-id"
19-
PhraseApp::InContextEditor.project_id.should eql "old-project-id"
19+
expect(PhraseApp::InContextEditor.project_id).to eql "old-project-id"
2020
project_id_1 = nil
2121
project_id_2 = nil
2222
PhraseApp::InContextEditor.with_config(project_id: "my-new-project-id") do
@@ -27,10 +27,9 @@
2727
project_id_1 = PhraseApp::InContextEditor.project_id
2828
end
2929

30-
project_id_1.should eql "my-new-project-id"
31-
project_id_2.should eql "my-newest-project-id"
32-
33-
PhraseApp::InContextEditor.project_id.should eql "old-project-id"
30+
expect(project_id_1).to eql "my-new-project-id"
31+
expect(project_id_2).to eql "my-newest-project-id"
32+
expect(PhraseApp::InContextEditor.project_id).to eql "old-project-id"
3433
end
3534
end
3635
end

spec/phraseapp-in-context-editor-ruby/backend_service_spec.rb

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
before(:each) do
2020
PhraseApp::InContextEditor.config.prefix = "{{__"
2121
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 }
2525
end
2626

2727
subject { phraseapp_service.translate(*args) }
@@ -35,58 +35,58 @@
3535
let(:args){ [key_name] }
3636
let(:key_is_blacklisted){ true }
3737

38-
it { should eql i18n_translation }
38+
it { is_expected.to eql i18n_translation }
3939
end
4040

4141
context "key is ignored" do
4242
let(:args) { [key_name] }
4343
let(:key_is_ignored) { true }
4444

45-
it { should eql i18n_translation }
45+
it { is_expected.to eql i18n_translation }
4646
end
4747

4848
context "resolve: false given as argument" do
4949
let(:args){ [key_name, resolve: false] }
5050

5151
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)
5353
end
5454

55-
it { should eql i18n_translation }
55+
it { is_expected.to eql i18n_translation }
5656
end
5757

5858
context "resolve: true given as argument" do
5959
let(:args){ [key_name, resolve: true] }
6060

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__}}' }
6363
end
6464

6565
context "key is not blacklisted" do
6666
let(:args){ [key_name] }
6767
let(:key_is_blacklisted){ false }
6868

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__}}' }
7171
end
7272

7373
describe "different arguments given" do
7474
context "default array given", vcr: {cassette_name: 'fetch list of keys filtered by fallback key names'} do
7575
let(:args){ [:key, { :default => [:first_fallback, :second_fallback] }] }
76-
it { should eql '{{__phrase_key__}}' }
76+
it { is_expected.to eql '{{__phrase_key__}}' }
7777
end
7878

7979
context "default string given" do
8080
let(:args){ [:key, { :default => 'first fallback' }] }
8181

82-
it { should eql '{{__phrase_key__}}' }
82+
it { is_expected.to eql '{{__phrase_key__}}' }
8383
end
8484

8585
context "scope array given" do
86-
let(:context_key_translation){ stub }
86+
let(:context_key_translation){ double }
8787
let(:args){ [:key, { :scope => [:context] }] }
8888

89-
it { should eql '{{__phrase_context.key__}}' }
89+
it { is_expected.to eql '{{__phrase_context.key__}}' }
9090
end
9191
end
9292
end
@@ -98,41 +98,41 @@
9898
PhraseApp::InContextEditor.enabled = false
9999
end
100100

101-
it { should eql i18n_translation }
101+
it { is_expected.to eql i18n_translation }
102102

103103
context "given arguments other than key_name" do
104104
let(:args){ [key_name, locale: :ru] }
105105
let(:ru_translation){ double }
106106

107107
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 }
109109
end
110110

111-
it { should eql ru_translation }
111+
it { is_expected.to eql ru_translation }
112112
end
113113

114114
describe "different arguments given" do
115115
before(:each) do
116-
I18n.unstub(:translate_without_phraseapp)
116+
allow(I18n).to receive(:translate_without_phraseapp).and_call_original
117117
end
118118

119119
context "default array given" do
120120
let(:args) { [:key, { :default => [:first_fallback, :second_fallback] }] }
121121

122-
specify { subject.should eql "translation missing: en.key" }
122+
it { is_expected.to eql "translation missing: en.key" }
123123
end
124124

125125
context "default string given" do
126126
let(:args) { [:key, { :default => 'first fallback' }] }
127127

128-
it { should eql 'first fallback' }
128+
it { is_expected.to eql 'first fallback' }
129129
end
130130

131131
context "scope array given" do
132-
let(:context_key_translation) { stub }
132+
let(:context_key_translation) { double }
133133
let(:args) { [:key, { :scope => [:context] }] }
134134

135-
specify { subject.should eql "translation missing: en.context.key" }
135+
it { is_expected.to eql "translation missing: en.context.key" }
136136
end
137137
end
138138
end
@@ -143,22 +143,22 @@
143143
subject { phraseapp_service.send(:has_blacklist_entry_for_key?, key) }
144144

145145
before(:each) do
146-
phraseapp_service.stub(:blacklisted_keys){ blacklisted_keys }
146+
allow(phraseapp_service).to receive(:blacklisted_keys){ blacklisted_keys }
147147
end
148148

149149
context "blacklisted_keys contain key" do
150150
let(:blacklisted_keys){ [key] }
151-
it { should be_truthy }
151+
it { is_expected.to be_truthy }
152152
end
153153

154154
context "key is blacklisted (using wildcards)" do
155155
let(:blacklisted_keys){ ["foo.black*"] }
156-
it { should be_truthy }
156+
it { is_expected.to be_truthy }
157157
end
158158

159159
context "if no blacklisted_keys" do
160160
let(:blacklisted_keys){ [] }
161-
it { should be_falsey }
161+
it { is_expected.to be_falsey }
162162
end
163163
end
164164

@@ -174,31 +174,31 @@
174174
context "blacklisted_keys contain key" do
175175
let(:ignored_keys) { ["foo.ignored"] }
176176

177-
it { should be_truthy }
177+
it { is_expected.to be_truthy }
178178
end
179179

180180
context "key is ignores (using wildcards)" do
181181
let(:ignored_keys) { ["foo.*"] }
182182

183-
it { should be_truthy }
183+
it { is_expected.to be_truthy }
184184
end
185185

186186
context "if no keys are ignored" do
187187
let(:ignored_keys) { [] }
188188

189-
it { should be_falsey }
189+
it { is_expected.to be_falsey }
190190
end
191191
end
192192

193193
describe "#blacklisted_keys", vcr: {cassette_name: 'fetch list of blacklisted keys'} do
194194
subject { phraseapp_service.send(:blacklisted_keys) }
195195

196-
it { should eql ["faker*"] }
196+
it { is_expected.to eql ["faker*"] }
197197

198198
describe "memoizing the blacklisted_keys" do
199199
specify do
200200
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
202202
end
203203
end
204204
end
@@ -208,12 +208,12 @@
208208

209209
context 'default case' do
210210
let(:args) { ['my.key', {}] }
211-
it { should == 'my.key'}
211+
it { is_expected.to eql 'my.key'}
212212
end
213213

214214
context 'the leading dot should be removed' do
215215
let(:args) { ['.my.key', {}] }
216-
it { should == 'my.key'}
216+
it { is_expected.to eql 'my.key'}
217217
end
218218
end
219219
end

spec/phraseapp-in-context-editor-ruby/cache_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
let(:cache_key) { :foo }
99

1010
before(:each) do
11-
PhraseApp::InContextEditor.stub(:cache_lifetime).and_return(300)
11+
allow(PhraseApp::InContextEditor).to receive(:cache_lifetime).and_return(300)
1212
end
1313

1414
subject { cache }
1515

1616
describe "#initialize" do
1717
subject { PhraseApp::InContextEditor::Cache.new(lifetime: 999) }
1818

19-
it { subject.lifetime.should == 999 }
19+
it { expect(subject.lifetime).to eql 999 }
2020
end
2121

2222
describe "#cached?(cache_key)" do
@@ -35,7 +35,7 @@
3535
end
3636
end
3737

38-
it { should be_truthy }
38+
it { is_expected.to be_truthy }
3939

4040
context "the entry has expired" do
4141
before(:each) do
@@ -44,12 +44,12 @@
4444
end
4545
end
4646

47-
it { should be_falsey }
47+
it { is_expected.to be_falsey }
4848
end
4949
end
5050

5151
context "no entry for that key exists" do
52-
it { should be_falsey }
52+
it { is_expected.to be_falsey }
5353
end
5454
end
5555

@@ -60,7 +60,7 @@
6060
cache.set(cache_key, "bar")
6161
end
6262

63-
it { should == "bar" }
63+
it { is_expected.to eql "bar" }
6464
end
6565

6666
describe "#set(cache_key, value)" do
@@ -70,6 +70,6 @@
7070
cache.set(cache_key, "bar")
7171
end
7272

73-
it { should == "bar" }
73+
it { is_expected.to eql "bar" }
7474
end
7575
end

spec/phraseapp-in-context-editor-ruby/config_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
it "should return the default option when no specific value assigned" do
1212
config = PhraseApp::InContextEditor::Config.new
13-
config.project_id.should eql nil
14-
PhraseApp::InContextEditor::Config.project_id.should eql nil
13+
expect(config.project_id).to eql(nil)
14+
expect(PhraseApp::InContextEditor::Config.project_id).to eql(nil)
1515
PhraseApp::InContextEditor::Config.project_id = "foo"
16-
PhraseApp::InContextEditor::Config.project_id.should eql "foo"
17-
config.project_id.should eql "foo"
16+
expect(PhraseApp::InContextEditor::Config.project_id).to eql "foo"
17+
expect(config.project_id).to eql "foo"
1818
config.project_id = "bar"
19-
config.project_id.should eql "bar"
19+
expect(config.project_id).to eql "bar"
2020
PhraseApp::InContextEditor::Config.project_id = "foo"
2121
end
2222

@@ -26,33 +26,33 @@
2626
PhraseApp::InContextEditor::Config.access_token = "my-new-token"
2727
second_api_client = PhraseApp::InContextEditor::Config.api_client
2828
# Hacky: Currently no better way to check api client renewal
29-
second_api_client.object_id.should_not == first_api_client.object_id
30-
second_api_client.instance_eval("@credentials").send(:token).should eql "my-new-token"
29+
expect(second_api_client.object_id).not_to eql first_api_client.object_id
30+
expect(second_api_client.instance_eval("@credentials").send(:token)).to eql("my-new-token")
3131
end
3232
end
3333

3434
describe "#assign_values(config_options)" do
3535
it "should assign the config values to the instance" do
3636
config = PhraseApp::InContextEditor::Config.new
37-
config.project_id.should eql nil
37+
expect(config.project_id).to eql(nil)
3838
config.assign_values(project_id: "foo")
39-
config.project_id.should eql "foo"
40-
PhraseApp::InContextEditor::Config.project_id.should eql nil
39+
expect(config.project_id).to eql("foo")
40+
expect(PhraseApp::InContextEditor::Config.project_id).to eql(nil)
4141
end
4242
end
4343

4444
describe "#self.reset_to_defaults!" do
4545
it "should reset the class level variables to their defaults" do
4646
PhraseApp::InContextEditor::Config.project_id = "foo"
47-
PhraseApp::InContextEditor::Config.project_id.should eql "foo"
47+
expect(PhraseApp::InContextEditor::Config.project_id).to eql("foo")
4848
PhraseApp::InContextEditor::Config.reset_to_defaults!
49-
PhraseApp::InContextEditor::Config.project_id.should eql nil
49+
expect(PhraseApp::InContextEditor::Config.project_id).to eql(nil)
5050
end
5151
end
5252

5353
describe "#self.api_client" do
5454
it "should be generate an api client by default" do
55-
PhraseApp::InContextEditor::Config.api_client.should be_a(PhraseApp::Client)
55+
expect(PhraseApp::InContextEditor::Config.api_client).to be_a(PhraseApp::Client)
5656
end
5757
end
5858
end

0 commit comments

Comments
 (0)