mediawiki_selenium 1.0.0.pre.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -4
- data/UPGRADE.md +1 -1
- data/bin/mediawiki-selenium-init +1 -1
- data/lib/mediawiki_selenium/browser_factory/base.rb +8 -8
- data/lib/mediawiki_selenium/browser_factory/chrome.rb +1 -1
- data/lib/mediawiki_selenium/browser_factory/firefox.rb +4 -4
- data/lib/mediawiki_selenium/browser_factory/phantomjs.rb +2 -2
- data/lib/mediawiki_selenium/browser_factory.rb +5 -5
- data/lib/mediawiki_selenium/environment.rb +15 -14
- data/lib/mediawiki_selenium/initializer.rb +4 -4
- data/lib/mediawiki_selenium/page_factory.rb +1 -1
- data/lib/mediawiki_selenium/remote_browser_factory.rb +12 -8
- data/lib/mediawiki_selenium/step_definitions/login_steps.rb +0 -11
- data/lib/mediawiki_selenium/step_definitions/navigation_steps.rb +0 -11
- data/lib/mediawiki_selenium/step_definitions/preferences_steps.rb +0 -11
- data/lib/mediawiki_selenium/step_definitions/resource_loader_steps.rb +0 -11
- data/lib/mediawiki_selenium/step_definitions/upload_file_steps.rb +3 -3
- data/lib/mediawiki_selenium/step_definitions.rb +5 -5
- data/lib/mediawiki_selenium/support/env.rb +5 -16
- data/lib/mediawiki_selenium/support/hooks.rb +15 -26
- data/lib/mediawiki_selenium/support/modules/api_helper.rb +5 -7
- data/lib/mediawiki_selenium/support/pages/api_page.rb +6 -6
- data/lib/mediawiki_selenium/support/pages/login_page.rb +13 -12
- data/lib/mediawiki_selenium/support/pages/random_page.rb +2 -2
- data/lib/mediawiki_selenium/support/pages/reset_preferences_page.rb +3 -3
- data/lib/mediawiki_selenium/support/pages.rb +4 -4
- data/lib/mediawiki_selenium/support/sauce.rb +14 -18
- data/lib/mediawiki_selenium/support.rb +4 -4
- data/lib/mediawiki_selenium/version.rb +1 -12
- data/lib/mediawiki_selenium/warnings_formatter.rb +15 -15
- data/lib/mediawiki_selenium.rb +8 -19
- data/mediawiki_selenium.gemspec +35 -28
- data/spec/api_helper_spec.rb +25 -25
- data/spec/browser_factory/base_spec.rb +50 -46
- data/spec/browser_factory/chrome_spec.rb +11 -11
- data/spec/browser_factory/firefox_spec.rb +17 -17
- data/spec/browser_factory/phantomjs_spec.rb +11 -11
- data/spec/environment_spec.rb +194 -159
- data/spec/page_factory_spec.rb +12 -12
- data/spec/remote_browser_factory_spec.rb +15 -15
- data/spec/spec_helper.rb +2 -2
- data/templates/tests/browser/features/support/env.rb +3 -3
- metadata +9 -9
- data/.rubocop_todo.yml +0 -160
data/spec/environment_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module MediawikiSelenium
|
4
4
|
describe Environment do
|
@@ -13,101 +13,101 @@ module MediawikiSelenium
|
|
13
13
|
mediawiki_api_url: mediawiki_api_url,
|
14
14
|
mediawiki_url: mediawiki_url,
|
15
15
|
mediawiki_user: mediawiki_user,
|
16
|
-
mediawiki_password: mediawiki_password
|
16
|
+
mediawiki_password: mediawiki_password
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
-
let(:browser) {
|
21
|
-
let(:mediawiki_api_url) {
|
22
|
-
let(:mediawiki_url) {
|
23
|
-
let(:mediawiki_user) {
|
24
|
-
let(:mediawiki_password) {
|
20
|
+
let(:browser) { 'firefox' }
|
21
|
+
let(:mediawiki_api_url) { 'http://an.example/wiki/api.php' }
|
22
|
+
let(:mediawiki_url) { 'http://an.example/wiki/' }
|
23
|
+
let(:mediawiki_user) { 'mw user' }
|
24
|
+
let(:mediawiki_password) { 'mw password' }
|
25
25
|
|
26
|
-
describe
|
26
|
+
describe '.load' do
|
27
27
|
subject { Environment.load(name, extra) }
|
28
28
|
|
29
|
-
let(:name) {
|
29
|
+
let(:name) { 'foo' }
|
30
30
|
let(:extra) { {} }
|
31
31
|
|
32
32
|
before do
|
33
|
-
expect(YAML).to receive(:load_file).with(
|
34
|
-
and_return(
|
33
|
+
expect(YAML).to receive(:load_file).with('environments.yml').
|
34
|
+
and_return('foo' => { 'x' => 'a', 'y' => 'b' })
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'returns a new environment' do
|
38
38
|
expect(subject).to be_a(Environment)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
expect(subject[:x]).to eq(
|
43
|
-
expect(subject[:y]).to eq(
|
41
|
+
it 'uses the given configuration in `environments.yml`' do
|
42
|
+
expect(subject[:x]).to eq('a')
|
43
|
+
expect(subject[:y]).to eq('b')
|
44
44
|
end
|
45
45
|
|
46
|
-
context
|
47
|
-
let(:name) {
|
46
|
+
context 'when the given environment does not exist in `environments.yml`' do
|
47
|
+
let(:name) { 'bar' }
|
48
48
|
|
49
|
-
it
|
50
|
-
expect { subject }.to raise_error(ConfigurationError,
|
49
|
+
it 'raises a ConfigurationError' do
|
50
|
+
expect { subject }.to raise_error(ConfigurationError, 'unknown environment `bar`')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
context
|
55
|
-
let(:extra) { { x:
|
54
|
+
context 'when extra configuration is given' do
|
55
|
+
let(:extra) { { x: 'c' } }
|
56
56
|
|
57
|
-
it
|
58
|
-
expect(subject[:x]).to eq(
|
59
|
-
expect(subject[:y]).to eq(
|
57
|
+
it 'overwrites the loaded configuration' do
|
58
|
+
expect(subject[:x]).to eq('c')
|
59
|
+
expect(subject[:y]).to eq('b')
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
describe
|
64
|
+
describe '.load_default' do
|
65
65
|
subject { Environment.load_default }
|
66
66
|
|
67
|
-
it
|
68
|
-
expect(ENV).to receive(:[]).with(
|
69
|
-
expect(Environment).to receive(:load).with(
|
67
|
+
it 'loads the environment configuration specified by MEDIAWIKI_ENVIRONMENT' do
|
68
|
+
expect(ENV).to receive(:[]).with('MEDIAWIKI_ENVIRONMENT').and_return('foo')
|
69
|
+
expect(Environment).to receive(:load).with('foo', ENV)
|
70
70
|
subject
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
describe
|
74
|
+
describe '#==' do
|
75
75
|
subject { env == other }
|
76
76
|
|
77
|
-
context
|
77
|
+
context 'given an environment with the same configuration' do
|
78
78
|
let(:other) { Environment.new(config) }
|
79
79
|
|
80
|
-
it
|
80
|
+
it 'considers them equal' do
|
81
81
|
expect(subject).to be(true)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
context
|
86
|
-
let(:other) { Environment.new(config.merge(some:
|
85
|
+
context 'given an environment with different configuration' do
|
86
|
+
let(:other) { Environment.new(config.merge(some: 'extra')) }
|
87
87
|
|
88
|
-
it
|
88
|
+
it 'considers them not equal' do
|
89
89
|
expect(subject).to be(false)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
95
|
-
context
|
94
|
+
describe '#as_user' do
|
95
|
+
context 'when both an alternative user and password are defined' do
|
96
96
|
let(:config) do
|
97
97
|
{
|
98
|
-
mediawiki_user:
|
99
|
-
mediawiki_password:
|
100
|
-
mediawiki_user_b:
|
101
|
-
mediawiki_password_b:
|
98
|
+
mediawiki_user: 'user',
|
99
|
+
mediawiki_password: 'pass',
|
100
|
+
mediawiki_user_b: 'user b',
|
101
|
+
mediawiki_password_b: 'pass b'
|
102
102
|
}
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
expect { |block| env.as_user(:b, &block) }.to yield_with_args(
|
105
|
+
it 'yields the alternative user and password in the new environment' do
|
106
|
+
expect { |block| env.as_user(:b, &block) }.to yield_with_args('user b', 'pass b')
|
107
107
|
|
108
108
|
env.as_user(:b) do
|
109
|
-
expect(env[:mediawiki_user]).to eq(
|
110
|
-
expect(env[:mediawiki_password]).to eq(
|
109
|
+
expect(env[:mediawiki_user]).to eq('user b')
|
110
|
+
expect(env[:mediawiki_password]).to eq('pass b')
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -115,90 +115,90 @@ module MediawikiSelenium
|
|
115
115
|
context "when an alternative for the password isn't defined" do
|
116
116
|
let(:config) do
|
117
117
|
{
|
118
|
-
mediawiki_user:
|
119
|
-
mediawiki_password:
|
120
|
-
mediawiki_user_b:
|
118
|
+
mediawiki_user: 'user',
|
119
|
+
mediawiki_password: 'pass',
|
120
|
+
mediawiki_user_b: 'user b'
|
121
121
|
}
|
122
122
|
end
|
123
123
|
|
124
|
-
it
|
125
|
-
expect { |block| env.as_user(:b, &block) }.to yield_with_args(
|
124
|
+
it 'falls back to using the base defined password' do
|
125
|
+
expect { |block| env.as_user(:b, &block) }.to yield_with_args('user b', 'pass')
|
126
126
|
|
127
127
|
env.as_user(:b) do
|
128
|
-
expect(env[:mediawiki_user]).to eq(
|
129
|
-
expect(env[:mediawiki_password]).to eq(
|
128
|
+
expect(env[:mediawiki_user]).to eq('user b')
|
129
|
+
expect(env[:mediawiki_password]).to eq('pass')
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
describe
|
135
|
+
describe '#browser_factory' do
|
136
136
|
subject { env.browser_factory }
|
137
137
|
|
138
|
-
it
|
138
|
+
it 'is a factory for the configured browser' do
|
139
139
|
expect(subject).to be_a(BrowserFactory::Firefox)
|
140
140
|
end
|
141
141
|
|
142
|
-
context
|
142
|
+
context 'given an explicit type of browser' do
|
143
143
|
subject { env.browser_factory(:chrome) }
|
144
144
|
|
145
|
-
it
|
145
|
+
it 'is a factory for that type' do
|
146
146
|
expect(subject).to be_a(BrowserFactory::Chrome)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
context
|
150
|
+
context 'caching in a cloned environment' do
|
151
151
|
let(:env1) { env }
|
152
152
|
let(:env2) { env1.clone }
|
153
153
|
|
154
154
|
let(:factory1) { env.browser_factory(browser1) }
|
155
155
|
let(:factory2) { env2.browser_factory(browser2) }
|
156
156
|
|
157
|
-
context
|
157
|
+
context 'with the same local/remote behavior as before' do
|
158
158
|
before do
|
159
159
|
expect(env1).to receive(:remote?).at_least(:once).and_return(false)
|
160
160
|
expect(env2).to receive(:remote?).at_least(:once).and_return(false)
|
161
161
|
end
|
162
162
|
|
163
|
-
context
|
163
|
+
context 'and the same type of browser as before' do
|
164
164
|
let(:browser1) { :firefox }
|
165
165
|
let(:browser2) { :firefox }
|
166
166
|
|
167
|
-
it
|
167
|
+
it 'returns a cached factory' do
|
168
168
|
expect(factory1).to be(factory2)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
context
|
172
|
+
context 'and a different type of browser than before' do
|
173
173
|
let(:browser1) { :firefox }
|
174
174
|
let(:browser2) { :chrome }
|
175
175
|
|
176
|
-
it
|
176
|
+
it 'returns a new factory' do
|
177
177
|
expect(factory1).not_to be(factory2)
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
context
|
182
|
+
context 'with different local/remote behavior as before' do
|
183
183
|
before do
|
184
184
|
expect(env1).to receive(:remote?).at_least(:once).and_return(false)
|
185
185
|
expect(env2).to receive(:remote?).at_least(:once).and_return(true)
|
186
186
|
end
|
187
187
|
|
188
|
-
context
|
188
|
+
context 'but the same type of browser as before' do
|
189
189
|
let(:browser1) { :firefox }
|
190
190
|
let(:browser2) { :firefox }
|
191
191
|
|
192
|
-
it
|
192
|
+
it 'returns a cached factory' do
|
193
193
|
expect(factory1).not_to be(factory2)
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
context
|
197
|
+
context 'and a different type of browser than before' do
|
198
198
|
let(:browser1) { :firefox }
|
199
199
|
let(:browser2) { :chrome }
|
200
200
|
|
201
|
-
it
|
201
|
+
it 'returns a new factory' do
|
202
202
|
expect(factory1).not_to be(factory2)
|
203
203
|
end
|
204
204
|
end
|
@@ -206,32 +206,32 @@ module MediawikiSelenium
|
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
-
describe
|
209
|
+
describe '#browser_name' do
|
210
210
|
subject { env.browser_name }
|
211
211
|
|
212
|
-
let(:browser) {
|
212
|
+
let(:browser) { 'Chrome' }
|
213
213
|
|
214
|
-
it
|
214
|
+
it 'is always a lowercase symbol' do
|
215
215
|
expect(subject).to be(:chrome)
|
216
216
|
end
|
217
217
|
|
218
|
-
context
|
218
|
+
context 'missing browser configuration' do
|
219
219
|
let(:browser) { nil }
|
220
220
|
|
221
|
-
it
|
221
|
+
it 'defaults to :firefox' do
|
222
222
|
expect(subject).to be(:firefox)
|
223
223
|
end
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
-
describe
|
227
|
+
describe '#env' do
|
228
228
|
subject { env.env }
|
229
229
|
|
230
230
|
it { is_expected.to be(env) }
|
231
231
|
end
|
232
232
|
|
233
|
-
describe
|
234
|
-
it
|
233
|
+
describe '#in_browser' do
|
234
|
+
it 'executes in the new environment with a new browser session' do
|
235
235
|
expect { |block| env.in_browser(:a, &block) }.to yield_with_args(:a)
|
236
236
|
|
237
237
|
env.in_browser(:a) do
|
@@ -239,45 +239,45 @@ module MediawikiSelenium
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
context
|
243
|
-
it
|
244
|
-
expect { |block| env.in_browser(:a, language:
|
245
|
-
to yield_with_args(
|
242
|
+
context 'given browser configuration overrides' do
|
243
|
+
it 'executes in the new environment with the prefixed overrides' do
|
244
|
+
expect { |block| env.in_browser(:a, language: 'eo', &block) }.
|
245
|
+
to yield_with_args('eo', :a)
|
246
246
|
|
247
|
-
env.in_browser(:a, language:
|
248
|
-
expect(env[:browser_language]).to eq(
|
247
|
+
env.in_browser(:a, language: 'eo') do
|
248
|
+
expect(env[:browser_language]).to eq('eo')
|
249
249
|
expect(env[:_browser_session]).to eq(:a)
|
250
250
|
end
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
-
describe
|
255
|
+
describe '#lookup' do
|
256
256
|
subject { env.lookup(key, options) }
|
257
257
|
|
258
|
-
let(:config) { { foo:
|
258
|
+
let(:config) { { foo: 'foo_value', foo_b: 'foo_b_value', bar: 'bar_value' } }
|
259
259
|
|
260
|
-
context
|
260
|
+
context 'for a key that exists' do
|
261
261
|
let(:key) { :foo }
|
262
262
|
let(:options) { {} }
|
263
263
|
|
264
|
-
it
|
265
|
-
expect(subject).to eq(
|
264
|
+
it 'returns the configuration' do
|
265
|
+
expect(subject).to eq('foo_value')
|
266
266
|
end
|
267
267
|
end
|
268
268
|
|
269
269
|
context "for a key that doesn't exist" do
|
270
270
|
let(:key) { :baz }
|
271
271
|
|
272
|
-
context
|
272
|
+
context 'given no default value' do
|
273
273
|
let(:options) { {} }
|
274
274
|
|
275
|
-
it
|
275
|
+
it 'raises a ConfigurationError' do
|
276
276
|
expect { subject }.to raise_error(ConfigurationError)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
|
-
context
|
280
|
+
context 'given a default value' do
|
281
281
|
let(:options) { { default: default } }
|
282
282
|
let(:default) { double(Object) }
|
283
283
|
|
@@ -285,27 +285,27 @@ module MediawikiSelenium
|
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
-
context
|
288
|
+
context 'for an alternative that exists' do
|
289
289
|
let(:key) { :foo }
|
290
290
|
let(:options) { { id: :b } }
|
291
291
|
|
292
|
-
it
|
293
|
-
expect(subject).to eq(
|
292
|
+
it 'returns the configured alternative' do
|
293
|
+
expect(subject).to eq('foo_b_value')
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
297
|
context "for an alternative that doesn't exist" do
|
298
298
|
let(:key) { :foo }
|
299
299
|
|
300
|
-
context
|
300
|
+
context 'given no default value' do
|
301
301
|
let(:options) { { id: :c } }
|
302
302
|
|
303
|
-
it
|
303
|
+
it 'raises a ConfigurationError' do
|
304
304
|
expect { subject }.to raise_error(ConfigurationError)
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
|
-
context
|
308
|
+
context 'given a default value' do
|
309
309
|
let(:options) { { id: :c, default: default } }
|
310
310
|
let(:default) { double(Object) }
|
311
311
|
|
@@ -314,158 +314,193 @@ module MediawikiSelenium
|
|
314
314
|
end
|
315
315
|
end
|
316
316
|
|
317
|
-
describe
|
317
|
+
describe '#on_wiki' do
|
318
318
|
let(:config) do
|
319
319
|
{
|
320
|
-
mediawiki_url:
|
321
|
-
mediawiki_url_b:
|
322
|
-
mediawiki_url_c:
|
320
|
+
mediawiki_url: 'http://an.example/wiki',
|
321
|
+
mediawiki_url_b: 'http://altb.example/wiki',
|
322
|
+
mediawiki_url_c: 'http://altc.example/wiki'
|
323
323
|
}
|
324
324
|
end
|
325
325
|
|
326
|
-
it
|
327
|
-
expect { |block| env.on_wiki(:b, &block) }.to yield_with_args(
|
326
|
+
it 'executes in the new environment using the alternative wiki URL' do
|
327
|
+
expect { |block| env.on_wiki(:b, &block) }.to yield_with_args('http://altb.example/wiki')
|
328
328
|
|
329
329
|
env.on_wiki(:b) do
|
330
|
-
expect(env[:mediawiki_url]).to eq(
|
330
|
+
expect(env[:mediawiki_url]).to eq('http://altb.example/wiki')
|
331
331
|
end
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
-
describe
|
335
|
+
describe '#teardown' do
|
336
|
+
subject { env.teardown(status) }
|
337
|
+
|
338
|
+
let(:status) { :passed }
|
339
|
+
let(:browser_instance) { double(Watir::Browser) }
|
340
|
+
|
341
|
+
before do
|
342
|
+
expect(env.browser_factory).to receive(:each) { |&blk| [browser_instance].each(&blk) }
|
343
|
+
expect(env.browser_factory).to receive(:teardown).with(env, status)
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'yields the given block and closes the browser' do
|
347
|
+
expect(browser_instance).to receive(:close)
|
348
|
+
expect { |blk| env.teardown(status, &blk) }.to yield_with_args(browser_instance)
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'when keep_browser_open is set to "true"' do
|
352
|
+
let(:config) { { keep_browser_open: 'true' } }
|
353
|
+
|
354
|
+
it 'does not close the browser' do
|
355
|
+
expect(browser_instance).not_to receive(:close)
|
356
|
+
subject
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'but browser is "phantomjs"' do
|
360
|
+
let(:config) { { browser: 'phantomjs', keep_browser_open: 'true' } }
|
361
|
+
|
362
|
+
it 'closes the browser anyway' do
|
363
|
+
expect(browser_instance).to receive(:close)
|
364
|
+
subject
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
describe '#user' do
|
336
371
|
subject { env.user(id) }
|
337
372
|
|
338
|
-
let(:config) { { mediawiki_user:
|
373
|
+
let(:config) { { mediawiki_user: 'mw_user', mediawiki_user_b: 'mw_user_b' } }
|
339
374
|
|
340
|
-
context
|
375
|
+
context 'given no alternative ID' do
|
341
376
|
let(:id) { nil }
|
342
377
|
|
343
|
-
it
|
344
|
-
expect(subject).to eq(
|
378
|
+
it 'returns the configured :mediawiki_user' do
|
379
|
+
expect(subject).to eq('mw_user')
|
345
380
|
end
|
346
381
|
end
|
347
382
|
|
348
|
-
context
|
383
|
+
context 'given an alternative ID' do
|
349
384
|
let(:id) { :b }
|
350
385
|
|
351
|
-
it
|
352
|
-
expect(subject).to eq(
|
386
|
+
it 'returns the configured alternative :mediawiki_user' do
|
387
|
+
expect(subject).to eq('mw_user_b')
|
353
388
|
end
|
354
389
|
end
|
355
390
|
end
|
356
391
|
|
357
|
-
describe
|
392
|
+
describe '#user_label' do
|
358
393
|
subject { env.user_label(id) }
|
359
394
|
|
360
|
-
let(:config) { { mediawiki_user:
|
395
|
+
let(:config) { { mediawiki_user: 'mw_user', mediawiki_user_b: 'mw_user_b' } }
|
361
396
|
|
362
|
-
context
|
397
|
+
context 'given no alternative ID' do
|
363
398
|
let(:id) { nil }
|
364
399
|
|
365
|
-
it
|
366
|
-
expect(subject).to eq(
|
400
|
+
it 'returns the configured :mediawiki_user with underscores replaced' do
|
401
|
+
expect(subject).to eq('mw user')
|
367
402
|
end
|
368
403
|
end
|
369
404
|
|
370
|
-
context
|
405
|
+
context 'given an alternative ID' do
|
371
406
|
let(:id) { :b }
|
372
407
|
|
373
|
-
it
|
374
|
-
expect(subject).to eq(
|
408
|
+
it 'returns the configured alternative :mediawiki_user with underscores replaced' do
|
409
|
+
expect(subject).to eq('mw user b')
|
375
410
|
end
|
376
411
|
end
|
377
412
|
end
|
378
413
|
|
379
|
-
describe
|
414
|
+
describe '#wiki_url' do
|
380
415
|
subject { env.wiki_url(url) }
|
381
416
|
|
382
|
-
let(:env) { Environment.new(mediawiki_url:
|
417
|
+
let(:env) { Environment.new(mediawiki_url: 'http://an.example/wiki/') }
|
383
418
|
|
384
|
-
context
|
419
|
+
context 'with no given url' do
|
385
420
|
let(:url) { nil }
|
386
421
|
|
387
|
-
it
|
388
|
-
expect(subject).to eq(
|
422
|
+
it 'is the configured :mediawiki_url' do
|
423
|
+
expect(subject).to eq('http://an.example/wiki/')
|
389
424
|
end
|
390
425
|
end
|
391
426
|
|
392
|
-
context
|
393
|
-
let(:url) {
|
427
|
+
context 'when the given URL is a relative path' do
|
428
|
+
let(:url) { 'some/path' }
|
394
429
|
|
395
|
-
it
|
396
|
-
expect(subject).to eq(
|
430
|
+
it 'is the configured :mediawiki_url with the path appended' do
|
431
|
+
expect(subject).to eq('http://an.example/wiki/some/path')
|
397
432
|
end
|
398
433
|
end
|
399
434
|
|
400
|
-
context
|
401
|
-
let(:url) {
|
435
|
+
context 'when the given URL is an absolute path' do
|
436
|
+
let(:url) { '/some/path' }
|
402
437
|
|
403
|
-
it
|
404
|
-
expect(subject).to eq(
|
438
|
+
it 'is the configured :mediawiki_url with the path replaced' do
|
439
|
+
expect(subject).to eq('http://an.example/some/path')
|
405
440
|
end
|
406
441
|
end
|
407
442
|
|
408
|
-
context
|
409
|
-
let(:url) {
|
443
|
+
context 'when the given URL is an absolute URL' do
|
444
|
+
let(:url) { 'http://another.example' }
|
410
445
|
|
411
|
-
it
|
412
|
-
expect(subject).to eq(
|
446
|
+
it 'is given absolute URL' do
|
447
|
+
expect(subject).to eq('http://another.example')
|
413
448
|
end
|
414
449
|
end
|
415
450
|
|
416
|
-
context
|
417
|
-
let(:url) {
|
451
|
+
context 'when the given URL is a relative path with a namespace' do
|
452
|
+
let(:url) { 'some:path' }
|
418
453
|
|
419
|
-
it
|
420
|
-
expect(subject).to eq(
|
454
|
+
it 'is the configured :mediawiki_url with the path replaced' do
|
455
|
+
expect(subject).to eq('http://an.example/wiki/some:path')
|
421
456
|
end
|
422
457
|
end
|
423
458
|
|
424
459
|
end
|
425
460
|
|
426
|
-
describe
|
461
|
+
describe '#with_alternative' do
|
427
462
|
let(:config) do
|
428
463
|
{
|
429
|
-
mediawiki_url:
|
430
|
-
mediawiki_url_b:
|
431
|
-
mediawiki_api_url:
|
432
|
-
mediawiki_api_url_b:
|
464
|
+
mediawiki_url: 'http://a.example/wiki',
|
465
|
+
mediawiki_url_b: 'http://b.example/wiki',
|
466
|
+
mediawiki_api_url: 'http://a.example/api',
|
467
|
+
mediawiki_api_url_b: 'http://b.example/api'
|
433
468
|
}
|
434
469
|
end
|
435
470
|
|
436
|
-
context
|
437
|
-
it
|
471
|
+
context 'given one option name and an ID' do
|
472
|
+
it 'executes in the new environment that substitutes it using the alternative' do
|
438
473
|
expect { |block| env.with_alternative(:mediawiki_url, :b, &block) }.
|
439
|
-
to yield_with_args(
|
474
|
+
to yield_with_args('http://b.example/wiki')
|
440
475
|
|
441
476
|
env.with_alternative(:mediawiki_url, :b) do
|
442
|
-
expect(env[:mediawiki_url]).to eq(
|
477
|
+
expect(env[:mediawiki_url]).to eq('http://b.example/wiki')
|
443
478
|
end
|
444
479
|
end
|
445
480
|
end
|
446
481
|
|
447
|
-
context
|
448
|
-
it
|
482
|
+
context 'given multiple option names and an ID' do
|
483
|
+
it 'executes in the new environment that substitutes both using the alternatives' do
|
449
484
|
expect { |block| env.with_alternative([:mediawiki_url, :mediawiki_api_url], :b, &block) }.
|
450
|
-
to yield_with_args(
|
485
|
+
to yield_with_args('http://b.example/wiki', 'http://b.example/api')
|
451
486
|
|
452
487
|
env.with_alternative([:mediawiki_url, :mediawiki_api_url], :b) do
|
453
|
-
expect(env[:mediawiki_url]).to eq(
|
454
|
-
expect(env[:mediawiki_api_url]).to eq(
|
488
|
+
expect(env[:mediawiki_url]).to eq('http://b.example/wiki')
|
489
|
+
expect(env[:mediawiki_api_url]).to eq('http://b.example/api')
|
455
490
|
end
|
456
491
|
end
|
457
492
|
end
|
458
493
|
|
459
|
-
context
|
460
|
-
it
|
494
|
+
context 'following block evaluation' do
|
495
|
+
it 'restores the original configuration' do
|
461
496
|
env.with_alternative(:mediawiki_url, :b)
|
462
|
-
expect(env[:mediawiki_url]).to eq(
|
497
|
+
expect(env[:mediawiki_url]).to eq('http://a.example/wiki')
|
463
498
|
end
|
464
499
|
|
465
|
-
context
|
466
|
-
it
|
467
|
-
expect { env.with_alternative(:mediawiki_url, :b) { raise
|
468
|
-
expect(env[:mediawiki_url]).to eq(
|
500
|
+
context 'when an exception is raised within the block' do
|
501
|
+
it 'restores the original configuration and lets the exception be raised' do
|
502
|
+
expect { env.with_alternative(:mediawiki_url, :b) { raise 'error' } }.to raise_error
|
503
|
+
expect(env[:mediawiki_url]).to eq('http://a.example/wiki')
|
469
504
|
end
|
470
505
|
end
|
471
506
|
end
|