quke 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,270 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Quke::Configuration do
6
+ describe "#features_folder" do
7
+ context "when specified NOT specified in config file" do
8
+ it "defaults to 'features'" do
9
+ Quke::Configuration.file_location = data_path(".no_file.yml")
10
+ expect(subject.features_folder).to eq("features")
11
+ end
12
+ end
13
+
14
+ context "when specified in config file" do
15
+ it "matches the config file" do
16
+ Quke::Configuration.file_location = data_path(".simple.yml")
17
+ expect(subject.features_folder).to eq("spec")
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#app_host" do
23
+ context "when NOT specified in the config file" do
24
+ it "defaults to ''" do
25
+ Quke::Configuration.file_location = data_path(".no_file.yml")
26
+ expect(subject.app_host).to eq("")
27
+ end
28
+ end
29
+
30
+ context "when specified in config file" do
31
+ it "matches the config file" do
32
+ Quke::Configuration.file_location = data_path(".simple.yml")
33
+ expect(subject.app_host).to eq("http://localhost:4567")
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#driver" do
39
+ context "when NOT specified in the config file" do
40
+ it "defaults to 'phantomjs'" do
41
+ Quke::Configuration.file_location = data_path(".no_file.yml")
42
+ expect(subject.driver).to eq("phantomjs")
43
+ end
44
+ end
45
+
46
+ context "when specified in the config file" do
47
+ it "matches the config file" do
48
+ Quke::Configuration.file_location = data_path(".simple.yml")
49
+ expect(subject.driver).to eq("chrome")
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#pause" do
55
+ context "when NOT specified in the config file" do
56
+ it "defaults to 0" do
57
+ Quke::Configuration.file_location = data_path(".no_file.yml")
58
+ expect(subject.pause).to eq(0)
59
+ end
60
+ end
61
+
62
+ context "when specified in config file" do
63
+ it "matches the config file" do
64
+ Quke::Configuration.file_location = data_path(".simple.yml")
65
+ expect(subject.pause).to eq(1)
66
+ end
67
+ end
68
+
69
+ context "when in the config file as a string" do
70
+ it "matches the config file" do
71
+ Quke::Configuration.file_location = data_path(".as_string.yml")
72
+ expect(subject.pause).to eq(1)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#stop_on_error" do
78
+ context "when NOT specified in the config file" do
79
+ it "defaults to false" do
80
+ Quke::Configuration.file_location = data_path(".no_file.yml")
81
+ expect(subject.stop_on_error).to eq(false)
82
+ end
83
+ end
84
+
85
+ context "when specified in config file" do
86
+ it "matches the config file" do
87
+ Quke::Configuration.file_location = data_path(".simple.yml")
88
+ expect(subject.stop_on_error).to eq(true)
89
+ end
90
+ end
91
+
92
+ context "when in the config file as a string" do
93
+ it "matches the config file" do
94
+ Quke::Configuration.file_location = data_path(".as_string.yml")
95
+ expect(subject.stop_on_error).to eq(true)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "#max_wait_time" do
101
+ context "when NOT specified in the config file" do
102
+ it "defaults to whatever the Capybara default is" do
103
+ Quke::Configuration.file_location = data_path(".no_file.yml")
104
+ expect(subject.max_wait_time).to eq(Capybara.default_max_wait_time)
105
+ end
106
+ end
107
+
108
+ context "when specified in config file" do
109
+ it "matches the config file" do
110
+ Quke::Configuration.file_location = data_path(".simple.yml")
111
+ expect(subject.max_wait_time).to eq(3)
112
+ end
113
+ end
114
+
115
+ context "when in the config file as a string" do
116
+ it "matches the config file" do
117
+ Quke::Configuration.file_location = data_path(".as_string.yml")
118
+ expect(subject.max_wait_time).to eq(3)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "#user_agent" do
124
+ context "when NOT specified in the config file" do
125
+ it "defaults to ''" do
126
+ Quke::Configuration.file_location = data_path(".no_file.yml")
127
+ expect(subject.user_agent).to eq("")
128
+ end
129
+ end
130
+
131
+ context "when specified in the config file" do
132
+ it "matches the config file" do
133
+ Quke::Configuration.file_location = data_path(".user_agent.yml")
134
+ expect(subject.user_agent).to eq("Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)")
135
+ end
136
+ end
137
+ end
138
+
139
+ describe "#javascrip_errors" do
140
+ context "when NOT specified in the config file" do
141
+ it "defaults to true" do
142
+ Quke::Configuration.file_location = data_path(".no_file.yml")
143
+ expect(subject.javascript_errors).to eq(true)
144
+ end
145
+ end
146
+
147
+ context "when specified in config file" do
148
+ it "matches the config file" do
149
+ Quke::Configuration.file_location = data_path(".javascript_errors.yml")
150
+ expect(subject.javascript_errors).to eq(false)
151
+ end
152
+ end
153
+
154
+ context "when in the config file as a string" do
155
+ it "matches the config file" do
156
+ Quke::Configuration.file_location = data_path(".as_string.yml")
157
+ expect(subject.javascript_errors).to eq(false)
158
+ end
159
+ end
160
+ end
161
+
162
+ describe "#proxy" do
163
+ context "when NOT specified in the config file" do
164
+ it "defaults to blank values" do
165
+ Quke::Configuration.file_location = data_path(".no_file.yml")
166
+ expect(subject.proxy).to eq("host" => "", "port" => 0, "no_proxy" => "")
167
+ end
168
+ end
169
+
170
+ context "when specified in the config file" do
171
+ it "matches the config file" do
172
+ Quke::Configuration.file_location = data_path(".proxy.yml")
173
+ expect(subject.proxy).to eq(
174
+ "host" => "10.10.2.70",
175
+ "port" => 8080,
176
+ "no_proxy" => "127.0.0.1,192.168.0.1"
177
+ )
178
+ end
179
+ end
180
+
181
+ context "when port is specified in the config file as a string" do
182
+ it "matches the config file" do
183
+ Quke::Configuration.file_location = data_path(".as_string.yml")
184
+ expect(subject.proxy).to eq(
185
+ "host" => "",
186
+ "port" => 8080,
187
+ "no_proxy" => ""
188
+ )
189
+ end
190
+ end
191
+ end
192
+
193
+ describe "#use_proxy?" do
194
+ context "when proxy host details are NOT specified in the config file" do
195
+ it "returns false" do
196
+ Quke::Configuration.file_location = data_path(".no_file.yml")
197
+ expect(subject.use_proxy?).to eq(false)
198
+ end
199
+ end
200
+
201
+ context "when proxy host details are specified in the config file" do
202
+ it "returns true" do
203
+ Quke::Configuration.file_location = data_path(".proxy_basic.yml")
204
+ expect(subject.use_proxy?).to eq(true)
205
+ end
206
+ end
207
+ end
208
+
209
+ describe "#custom" do
210
+ context "when NOT specified in the config file" do
211
+ it "defaults to nothing" do
212
+ Quke::Configuration.file_location = data_path(".no_file.yml")
213
+ expect(subject.custom).to be(nil)
214
+ end
215
+ end
216
+
217
+ context "when 'custom' in the config file holds simple key value pairs" do
218
+ it "returns the key value pair if there is just one" do
219
+ Quke::Configuration.file_location = data_path(".custom_key_value_pair.yml")
220
+ expect(subject.custom).to eq("my_key" => "my_value")
221
+ end
222
+
223
+ it "returns all key value pairs if there are multiples" do
224
+ Quke::Configuration.file_location = data_path(".custom_key_value_pairs.yml")
225
+ expect(subject.custom).to eq(
226
+ "my_key1" => "my_value1",
227
+ "my_key2" => "my_value2",
228
+ "my_key3" => "my_value3",
229
+ "my_key4" => "my_value4",
230
+ "my_key5" => "my_value5"
231
+ )
232
+ end
233
+ end
234
+
235
+ context "when 'custom' in the config file holds a hierachical object" do
236
+ it "returns a representation of the object" do
237
+ Quke::Configuration.file_location = data_path(".custom_complex_object.yml")
238
+ expect(subject.custom).to eq(
239
+ "my_key" => "my_value",
240
+ "accounts" => {
241
+ "account1" => {
242
+ "username" => "yoda",
243
+ "password" => "greenisgood"
244
+ },
245
+ "account2" => {
246
+ "username" => "vadar",
247
+ "password" => "redrules"
248
+ },
249
+ "account3" => {
250
+ "username" => "luke",
251
+ "password" => "fatherissues"
252
+ }
253
+ },
254
+ "troop_numbers" => {
255
+ "dark_side_count" => 1_000_000,
256
+ "light_side_count" => 5
257
+ }
258
+ )
259
+ end
260
+ end
261
+ end
262
+
263
+ describe ".file_name" do
264
+ context "environment variable not set" do
265
+ it "returns the default value '.config.yml'" do
266
+ expect(Quke::Configuration.file_name).to eq(".config.yml")
267
+ end
268
+ end
269
+ end
270
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Quke::CukeRunner do
6
+ let(:default_args) do
7
+ features_folder = __dir__.sub!("spec/quke", "lib/features")
8
+ ["spec", "-r", features_folder, "-r", "spec"]
9
+ end
10
+ describe "#initialize" do
11
+ context "no additional Cucumber arguments passed" do
12
+ let(:subject) { Quke::CukeRunner.new("spec") }
13
+ it "returns just the default args used by Quke" do
14
+ expect(subject.args).to eq(default_args)
15
+ end
16
+ end
17
+ context "additional Cucumber arguments passed" do
18
+ let(:args) { ["--tags", "test"] }
19
+ let(:subject) { Quke::CukeRunner.new("spec", args) }
20
+ it "returns the default args plus those passed in" do
21
+ expect(subject.args).to eq(default_args + args)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "#run" do
27
+ before(:example) do
28
+ Quke::Configuration.file_location = data_path(".no_file.yml")
29
+ Quke::Quke.config = Quke::Configuration.new
30
+ end
31
+ let(:subject) { Quke::CukeRunner.new("spec") }
32
+ it "does not raise an error when called" do
33
+ expect { subject.run }.not_to raise_error
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,279 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Quke::DriverConfiguration do
6
+
7
+ describe "#poltergeist" do
8
+
9
+ context "proxy details have NOT been set in the .config.yml" do
10
+ it "returns a hash containing only the default options" do
11
+ Quke::Configuration.file_location = data_path(".no_file.yml")
12
+ config = Quke::Configuration.new
13
+ expect(Quke::DriverConfiguration.new(config).poltergeist).to eq(
14
+ js_errors: true,
15
+ timeout: 30,
16
+ debug: false,
17
+ phantomjs_options: [
18
+ "--load-images=no",
19
+ "--disk-cache=false",
20
+ "--ignore-ssl-errors=yes"
21
+ ],
22
+ inspector: true
23
+ )
24
+ end
25
+ end
26
+
27
+ context "proxy details have been set in the .config.yml" do
28
+ it "returns a hash containing both default options and proxy settings" do
29
+ Quke::Configuration.file_location = data_path(".proxy_basic.yml")
30
+ config = Quke::Configuration.new
31
+ expect(Quke::DriverConfiguration.new(config).poltergeist).to eq(
32
+ js_errors: true,
33
+ timeout: 30,
34
+ debug: false,
35
+ phantomjs_options: [
36
+ "--load-images=no",
37
+ "--disk-cache=false",
38
+ "--ignore-ssl-errors=yes",
39
+ "--proxy=#{config.proxy['host']}:#{config.proxy['port']}"
40
+ ],
41
+ inspector: true
42
+ )
43
+ end
44
+ end
45
+
46
+ context "user has set javascript_errors to false in the .config.yml" do
47
+ it "returns a hash where js_errors is set to 'false'" do
48
+ Quke::Configuration.file_location = data_path(".javascript_errors.yml")
49
+ config = Quke::Configuration.new
50
+ expect(Quke::DriverConfiguration.new(config).poltergeist).to eq(
51
+ js_errors: false,
52
+ timeout: 30,
53
+ debug: false,
54
+ phantomjs_options: [
55
+ "--load-images=no",
56
+ "--disk-cache=false",
57
+ "--ignore-ssl-errors=yes"
58
+ ],
59
+ inspector: true
60
+ )
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ describe "#phantomjs" do
67
+
68
+ context "proxy details have NOT been set in the .config.yml" do
69
+ it "returns an array containing only the default options" do
70
+ Quke::Configuration.file_location = data_path(".no_file.yml")
71
+ config = Quke::Configuration.new
72
+ expect(Quke::DriverConfiguration.new(config).phantomjs).to eq(
73
+ [
74
+ "--load-images=no",
75
+ "--disk-cache=false",
76
+ "--ignore-ssl-errors=yes"
77
+ ]
78
+ )
79
+ end
80
+ end
81
+
82
+ context "proxy details have been set in the .config.yml" do
83
+ it "returns an array containing both default options and proxy settings" do
84
+ Quke::Configuration.file_location = data_path(".proxy_basic.yml")
85
+ config = Quke::Configuration.new
86
+ expect(Quke::DriverConfiguration.new(config).phantomjs).to eq(
87
+ [
88
+ "--load-images=no",
89
+ "--disk-cache=false",
90
+ "--ignore-ssl-errors=yes",
91
+ "--proxy=#{config.proxy['host']}:#{config.proxy['port']}"
92
+ ]
93
+ )
94
+ end
95
+ end
96
+
97
+ context "a user agent has been set in the .config.yml" do
98
+ it "is not in the array returned. Unlike the other drivers we can only override the user agent when registering the driver" do
99
+ Quke::Configuration.file_location = data_path(".user_agent.yml")
100
+ config = Quke::Configuration.new
101
+ expect(Quke::DriverConfiguration.new(config).phantomjs).to eq(
102
+ [
103
+ "--load-images=no",
104
+ "--disk-cache=false",
105
+ "--ignore-ssl-errors=yes"
106
+ ]
107
+ )
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ describe "#chrome" do
114
+
115
+ context "proxy details have NOT been set in the .config.yml" do
116
+ it "returns an empty array if no proxy has been set" do
117
+ Quke::Configuration.file_location = data_path(".no_file.yml")
118
+ config = Quke::Configuration.new
119
+ expect(Quke::DriverConfiguration.new(config).chrome).to eq([])
120
+ end
121
+ end
122
+
123
+ context "basic proxy details have been set in the .config.yml" do
124
+ it "returns an array containing basic proxy settings" do
125
+ Quke::Configuration.file_location = data_path(".proxy_basic.yml")
126
+ config = Quke::Configuration.new
127
+ expect(Quke::DriverConfiguration.new(config).chrome).to eq(
128
+ [
129
+ "--proxy-server=#{config.proxy['host']}:#{config.proxy['port']}"
130
+ ]
131
+ )
132
+ end
133
+ end
134
+
135
+ context "proxy details including addresses not to connect via the proxy server have been set in the .config.yml" do
136
+ it "returns an array containing proxy settings including no-proxy details" do
137
+ Quke::Configuration.file_location = data_path(".proxy.yml")
138
+ config = Quke::Configuration.new
139
+ expect(Quke::DriverConfiguration.new(config).chrome).to eq(
140
+ [
141
+ "--proxy-server=#{config.proxy['host']}:#{config.proxy['port']}",
142
+ "--proxy-bypass-list=127.0.0.1;192.168.0.1"
143
+ ]
144
+ )
145
+ end
146
+ end
147
+
148
+ context "a user agent has been set in the .config.yml" do
149
+ it "returns an array containing the specified user-agent" do
150
+ Quke::Configuration.file_location = data_path(".user_agent.yml")
151
+ config = Quke::Configuration.new
152
+ expect(Quke::DriverConfiguration.new(config).chrome).to eq(
153
+ [
154
+ "--user-agent=#{config.user_agent}"
155
+ ]
156
+ )
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+ describe "#firefox" do
163
+
164
+ context "proxy details have NOT been set in the .config.yml" do
165
+ it "returns a profile where the proxy details are NOT set" do
166
+ Quke::Configuration.file_location = data_path(".no_file.yml")
167
+ config = Quke::Configuration.new
168
+ profile = Quke::DriverConfiguration.new(config).firefox
169
+
170
+ # See spec/helpers.rb#read_profile_preferences for details of why we
171
+ # need to test the profile's properties in this way
172
+ preferences = read_profile_preferences(profile)
173
+
174
+ expect(preferences).not_to include('user_pref("network.proxy.http", "")')
175
+ expect(preferences).not_to include('user_pref("network.proxy.http_port", 8080)')
176
+ end
177
+ end
178
+
179
+ context "basic proxy details have been set in the .config.yml" do
180
+ it "returns a profile where the basic proxy details are set" do
181
+ Quke::Configuration.file_location = data_path(".proxy_basic.yml")
182
+ config = Quke::Configuration.new
183
+ profile = Quke::DriverConfiguration.new(config).firefox
184
+
185
+ # See spec/helpers.rb#read_profile_preferences for details of why we
186
+ # need to test the profile's properties in this way
187
+ preferences = read_profile_preferences(profile)
188
+
189
+ expect(preferences).to include('user_pref("network.proxy.http", "10.10.2.70")')
190
+ expect(preferences).to include('user_pref("network.proxy.http_port", 8080)')
191
+ end
192
+ end
193
+
194
+ context "proxy details including addresses not to connect via the proxy server have been set in the .config.yml" do
195
+ it "returns a profile where the proxy details are set including no-proxy details" do
196
+ Quke::Configuration.file_location = data_path(".proxy.yml")
197
+ config = Quke::Configuration.new
198
+ profile = Quke::DriverConfiguration.new(config).firefox
199
+
200
+ # See spec/helpers.rb#read_profile_preferences for details of why we
201
+ # need to test the profile's properties in this way
202
+ preferences = read_profile_preferences(profile)
203
+
204
+ expect(preferences).to include('user_pref("network.proxy.http", "10.10.2.70")')
205
+ expect(preferences).to include('user_pref("network.proxy.http_port", 8080)')
206
+ expect(preferences).to include('user_pref("network.proxy.no_proxies_on", "127.0.0.1,192.168.0.1")')
207
+ end
208
+ end
209
+
210
+ context "a user agent has been set in the .config.yml" do
211
+ it "returns an array containing the specified user-agent" do
212
+ Quke::Configuration.file_location = data_path(".user_agent.yml")
213
+ config = Quke::Configuration.new
214
+ profile = Quke::DriverConfiguration.new(config).firefox
215
+
216
+ # See spec/helpers.rb#read_profile_preferences for details of why we
217
+ # need to test the profile's properties in this way
218
+ preferences = read_profile_preferences(profile)
219
+
220
+ expect(preferences).to include(
221
+ 'user_pref("general.useragent.override", "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)")'
222
+ )
223
+ end
224
+ end
225
+
226
+ end
227
+
228
+ describe "#browserstack" do
229
+
230
+ context "browserstack details have NOT been set in the .config.yml" do
231
+ it "returns capabilities set to Selenium::WebDriver::Remote::Capabilities defaults" do
232
+ Quke::Configuration.file_location = data_path(".no_file.yml")
233
+ config = Quke::Configuration.new
234
+ capabilities = Quke::DriverConfiguration.new(config).browserstack
235
+
236
+ expect(capabilities.as_json.keys.count).to eq(8)
237
+ expect(capabilities["browserName"]).to eq(nil)
238
+ expect(capabilities["version"]).to eq(nil)
239
+ expect(capabilities["platform"]).to eq(nil)
240
+ expect(capabilities["javascriptEnabled"]).to eq(nil)
241
+ expect(capabilities["cssSelectorsEnabled"]).to eq(nil)
242
+ expect(capabilities["takesScreenshot"]).to eq(nil)
243
+ expect(capabilities["nativeEvents"]).to eq(nil)
244
+ expect(capabilities["rotatable"]).to eq(nil)
245
+ end
246
+ end
247
+
248
+ context "browserstack details have been set in the .config.yml" do
249
+ it "returns capabilities that match those set" do
250
+ Quke::Configuration.file_location = data_path(".browserstack.yml")
251
+ config = Quke::Configuration.new
252
+ capabilities = Quke::DriverConfiguration.new(config).browserstack
253
+ expected_capabilities = YAML.load_file(data_path(".browserstack.yml"))["browserstack"]["capabilities"]
254
+
255
+ expect(capabilities["build"]).to eq(expected_capabilities["build"])
256
+ expect(capabilities["project"]).to eq(expected_capabilities["project"])
257
+ expect(capabilities["name"]).to eq(expected_capabilities["name"])
258
+
259
+ expect(capabilities["acceptSslCerts"]).to eq(expected_capabilities["acceptSslCerts"])
260
+ expect(capabilities["browserstack.debug"]).to eq(expected_capabilities["browserstack.debug"])
261
+ expect(capabilities["browserstack.video"]).to eq(expected_capabilities["browserstack.video"])
262
+ expect(capabilities["browserstack.local"]).to eq(expected_capabilities["browserstack.local"])
263
+ expect(capabilities["browserstack.maskSendKeys"]).to eq(expected_capabilities["browserstack.maskSendKeys"])
264
+
265
+ expect(capabilities["platform"]).to eq(expected_capabilities["platform"])
266
+ expect(capabilities["browserName"]).to eq(expected_capabilities["browserName"])
267
+ expect(capabilities["version"]).to eq(expected_capabilities["version"])
268
+ expect(capabilities["device"]).to eq(expected_capabilities["device"])
269
+ expect(capabilities["os"]).to eq(expected_capabilities["os"])
270
+ expect(capabilities["os_version"]).to eq(expected_capabilities["os_version"])
271
+ expect(capabilities["browser"]).to eq(expected_capabilities["browser"])
272
+ expect(capabilities["browser_version"]).to eq(expected_capabilities["browser_version"])
273
+ expect(capabilities["resolution"]).to eq(expected_capabilities["resolution"])
274
+ end
275
+ end
276
+
277
+ end
278
+
279
+ end