capybara-box 0.4.0 → 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/CHANGELOG.md +15 -2
- data/README.md +32 -42
- data/lib/capybara-box.rb +6 -2
- data/lib/capybara-box/base.rb +43 -98
- data/lib/capybara-box/helper.rb +11 -0
- data/lib/capybara-box/screenshot.rb +41 -0
- data/lib/capybara-box/version.rb +1 -1
- metadata +11 -58
- data/spec/lib/capybara_box/base/add_argument_spec.rb +0 -35
- data/spec/lib/capybara_box/base/add_preference_spec.rb +0 -35
- data/spec/lib/capybara_box/base/apply_arguments_spec.rb +0 -33
- data/spec/lib/capybara_box/base/apply_bin_path_spec.rb +0 -34
- data/spec/lib/capybara_box/base/apply_preferences_spec.rb +0 -43
- data/spec/lib/capybara_box/base/apply_version_spec.rb +0 -37
- data/spec/lib/capybara_box/base/arguments_spec.rb +0 -72
- data/spec/lib/capybara_box/base/chrome_family_spec.rb +0 -23
- data/spec/lib/capybara_box/base/chrome_headless_spec.rb +0 -17
- data/spec/lib/capybara_box/base/chrome_spec.rb +0 -17
- data/spec/lib/capybara_box/base/configure_screenshot_spec.rb +0 -83
- data/spec/lib/capybara_box/base/configure_spec.rb +0 -33
- data/spec/lib/capybara_box/base/create_spec.rb +0 -89
- data/spec/lib/capybara_box/base/driver_options_spec.rb +0 -74
- data/spec/lib/capybara_box/base/driver_spec.rb +0 -97
- data/spec/lib/capybara_box/base/firefox_spec.rb +0 -17
- data/spec/lib/capybara_box/base/http_client_options_spec.rb +0 -24
- data/spec/lib/capybara_box/base/http_client_spec.rb +0 -11
- data/spec/lib/capybara_box/base/log_spec.rb +0 -43
- data/spec/lib/capybara_box/base/options_spec.rb +0 -43
- data/spec/lib/capybara_box/base/preferences_spec.rb +0 -63
- data/spec/lib/capybara_box/base/register_spec.rb +0 -17
- data/spec/lib/capybara_box/base/self_configure_spec.rb +0 -22
- data/spec/lib/capybara_box/base/version_spec.rb +0 -33
- data/spec/rails_helper.rb +0 -9
- data/spec/support/common.rb +0 -11
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.chrome_family?' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
context 'when :browser is chrome' do
|
7
|
-
let!(:parameters) { { browser: :chrome } }
|
8
|
-
|
9
|
-
specify { expect(subject).to be_chrome_family }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when :browser is chrome headless' do
|
13
|
-
let!(:parameters) { { browser: :chrome_headless } }
|
14
|
-
|
15
|
-
specify { expect(subject).to be_chrome_family }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'when :browser is not chrome nor chrome headless' do
|
19
|
-
let!(:parameters) { { browser: :firefox } }
|
20
|
-
|
21
|
-
specify { expect(subject).not_to be_chrome_family }
|
22
|
-
end
|
23
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.chrome_headless?' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
context 'when :browser is chrome headless' do
|
7
|
-
let!(:parameters) { { browser: :chrome_headless } }
|
8
|
-
|
9
|
-
specify { expect(subject).to be_chrome_headless }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when :browser is not chrome headless' do
|
13
|
-
let!(:parameters) { { browser: :not_chrome_headless } }
|
14
|
-
|
15
|
-
specify { expect(subject).not_to be_chrome_headless }
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.chrome?' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
context 'when :browser is chrome' do
|
7
|
-
let!(:parameters) { { browser: :chrome } }
|
8
|
-
|
9
|
-
specify { expect(subject).to be_chrome }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when :browser is not chrome' do
|
13
|
-
let!(:parameters) { { browser: :not_chrome } }
|
14
|
-
|
15
|
-
specify { expect(subject).not_to be_chrome }
|
16
|
-
end
|
17
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
require 'capybara-screenshot'
|
3
|
-
|
4
|
-
RSpec.describe CapybaraBox::Base, '.configure_screenshot' do
|
5
|
-
subject { described_class.new parameters }
|
6
|
-
|
7
|
-
context 'when enabled tag is false' do
|
8
|
-
let!(:parameters) { { screenshot: { enabled: false } } }
|
9
|
-
|
10
|
-
specify { expect(subject.configure_screenshot).to eq false }
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when enabled tag is "false"' do
|
14
|
-
let!(:parameters) { { screenshot: { enabled: 'false' } } }
|
15
|
-
|
16
|
-
specify { expect(subject.configure_screenshot).to eq false }
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when enabled' do
|
20
|
-
let!(:parameters) { { screenshot: {} } }
|
21
|
-
|
22
|
-
it 'does not appends timestamp' do
|
23
|
-
subject.configure_screenshot
|
24
|
-
|
25
|
-
expect(Capybara::Screenshot.append_timestamp).to eq false
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'prunes as keep_last_run' do
|
29
|
-
subject.configure_screenshot
|
30
|
-
|
31
|
-
expect(Capybara::Screenshot.prune_strategy).to eq :keep_last_run
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'does not add link to screenshot on example description' do
|
35
|
-
subject.configure_screenshot
|
36
|
-
|
37
|
-
expect(Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples).to eq false
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'configures a file name format for rspec' do
|
41
|
-
subject.configure_screenshot
|
42
|
-
|
43
|
-
example_object = OpenStruct.new(full_description: 'name#of file')
|
44
|
-
block_object = Capybara::Screenshot.filename_prefix_formatters[:rspec]
|
45
|
-
|
46
|
-
expect(block_object.call example_object).to eq 'name--of-file'
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'register a driver for given browser' do
|
50
|
-
driver = double
|
51
|
-
path = '/tmp'
|
52
|
-
|
53
|
-
subject.configure_screenshot
|
54
|
-
|
55
|
-
expect(driver).to receive_message_chain(:browser, :save_screenshot).with path
|
56
|
-
|
57
|
-
Capybara::Screenshot.registered_drivers[:chrome].call driver, path
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when s3 store is configured' do
|
61
|
-
before do
|
62
|
-
parameters[:screenshot][:s3] = {
|
63
|
-
access_key_id: :access_key_id,
|
64
|
-
bucket: :bucket,
|
65
|
-
secret_access_key: :secret_access_key
|
66
|
-
}
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'configures the s3 metadata' do
|
70
|
-
subject.configure_screenshot
|
71
|
-
|
72
|
-
expect(Capybara::Screenshot.s3_configuration).to eq(
|
73
|
-
s3_client_credentials: {
|
74
|
-
access_key_id: :access_key_id,
|
75
|
-
secret_access_key: :secret_access_key
|
76
|
-
},
|
77
|
-
|
78
|
-
bucket_name: :bucket
|
79
|
-
)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.configure' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
let!(:parameters) { { browser: :driver } }
|
7
|
-
|
8
|
-
it 'configure the javascript driver' do
|
9
|
-
subject.configure
|
10
|
-
|
11
|
-
expect(Capybara.javascript_driver).to eq :driver
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when max wait time is not given' do
|
15
|
-
it 'does not writes and uses the default' do
|
16
|
-
default = Capybara.default_max_wait_time
|
17
|
-
|
18
|
-
subject.configure
|
19
|
-
|
20
|
-
expect(Capybara.default_max_wait_time).to eq default
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when max wait time is given' do
|
25
|
-
before { parameters[:max_wait_time] = 7 }
|
26
|
-
|
27
|
-
it 'is used' do
|
28
|
-
subject.configure
|
29
|
-
|
30
|
-
expect(Capybara.default_max_wait_time).to eq 7
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '#create' do
|
4
|
-
context 'with no parameters' do
|
5
|
-
it 'applies the arguments' do
|
6
|
-
expect(subject).to receive(:apply_arguments)
|
7
|
-
|
8
|
-
subject.create
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'applies the preferences' do
|
12
|
-
expect(subject).to receive(:apply_preferences)
|
13
|
-
|
14
|
-
subject.create
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'register chrome browser as default' do
|
18
|
-
expect(subject).to receive(:register).with :chrome
|
19
|
-
|
20
|
-
subject.create
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'applies the capybara configurations' do
|
24
|
-
expect(subject).to receive :configure
|
25
|
-
|
26
|
-
subject.create
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when :bin_path is given' do
|
31
|
-
subject { described_class.new parameters }
|
32
|
-
|
33
|
-
let!(:parameters) { { bin_path: '/tmp/bin' } }
|
34
|
-
|
35
|
-
it 'applies the bin path' do
|
36
|
-
expect(subject).to receive(:apply_bin_path)
|
37
|
-
|
38
|
-
subject.create
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when :version is given' do
|
43
|
-
subject { described_class.new parameters }
|
44
|
-
|
45
|
-
let!(:parameters) { { version: '2.31' } }
|
46
|
-
|
47
|
-
it 'applies the version' do
|
48
|
-
expect(subject).to receive(:apply_version)
|
49
|
-
|
50
|
-
subject.create
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when :screenshot config is given' do
|
55
|
-
subject { described_class.new parameters }
|
56
|
-
|
57
|
-
let!(:parameters) { { screenshot: {} } }
|
58
|
-
|
59
|
-
it 'applies the screenshot' do
|
60
|
-
expect(subject).to receive(:configure_screenshot)
|
61
|
-
|
62
|
-
subject.create
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when :browser is given' do
|
67
|
-
subject { described_class.new parameters }
|
68
|
-
|
69
|
-
context 'as firefox' do
|
70
|
-
let!(:parameters) { { browser: :firefox } }
|
71
|
-
|
72
|
-
it 'registers the given browser' do
|
73
|
-
expect(subject).to receive(:register).with :firefox
|
74
|
-
|
75
|
-
subject.create
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'as chrome_headless' do
|
80
|
-
let!(:parameters) { { browser: :chrome_headless } }
|
81
|
-
|
82
|
-
it 'registers the given browser' do
|
83
|
-
expect(subject).to receive(:register).with :chrome_headless
|
84
|
-
|
85
|
-
subject.create
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.register' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
let!(:args) { { log_path: 'log/capybara-box.log', verbose: true } }
|
7
|
-
let!(:service) { instance_double 'Selenium::WebDriver::Service' }
|
8
|
-
|
9
|
-
before do
|
10
|
-
allow(Selenium::WebDriver::Service).to receive(:chrome).with(args: args).and_return service
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when is chrome' do
|
14
|
-
let!(:parameters) { { browser: :chrome } }
|
15
|
-
|
16
|
-
it 'uses the default driver options' do
|
17
|
-
expect(subject.driver_options).to eq(
|
18
|
-
browser: :chrome,
|
19
|
-
clear_local_storage: true,
|
20
|
-
clear_session_storage: true,
|
21
|
-
service: service
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when :driver_options is given' do
|
26
|
-
before { parameters[:driver_options] = { key: :value } }
|
27
|
-
|
28
|
-
it 'is used' do
|
29
|
-
expect(subject.driver_options).to eq(key: :value)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when is chrome headless' do
|
35
|
-
let!(:parameters) { { browser: :chrome_headless } }
|
36
|
-
|
37
|
-
it 'uses the default driver options' do
|
38
|
-
expect(subject.driver_options).to eq(
|
39
|
-
browser: :chrome,
|
40
|
-
clear_local_storage: true,
|
41
|
-
clear_session_storage: true,
|
42
|
-
service: service
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'when :driver_options is given' do
|
47
|
-
before { parameters[:driver_options] = { key: :value } }
|
48
|
-
|
49
|
-
it 'is used' do
|
50
|
-
expect(subject.driver_options).to eq(key: :value)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when is firefox' do
|
56
|
-
let!(:parameters) { { browser: :firefox } }
|
57
|
-
|
58
|
-
it 'uses the default driver options' do
|
59
|
-
expect(subject.driver_options).to eq(
|
60
|
-
browser: :firefox,
|
61
|
-
clear_local_storage: true,
|
62
|
-
clear_session_storage: true
|
63
|
-
)
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when :driver_options is given' do
|
67
|
-
before { parameters[:driver_options] = { key: :value } }
|
68
|
-
|
69
|
-
it 'is used' do
|
70
|
-
expect(subject.driver_options).to eq(key: :value)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.shared_context 'driver_with_options' do
|
4
|
-
it 'creates the selenium driver with default options' do
|
5
|
-
options = subject.driver_options
|
6
|
-
options[:options] = subject.options
|
7
|
-
|
8
|
-
expect(Capybara::Selenium::Driver).to receive(:new).with(:app, options)
|
9
|
-
|
10
|
-
subject.driver :app
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec.shared_context 'driver_with_no_options' do
|
15
|
-
it 'creates the selenium driver with no default options' do
|
16
|
-
options = subject.driver_options
|
17
|
-
|
18
|
-
expect(Capybara::Selenium::Driver).to receive(:new).with(:app, options)
|
19
|
-
|
20
|
-
subject.driver :app
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
RSpec.shared_context 'driver_with_options_and_http_client' do
|
25
|
-
it 'adds http client options' do
|
26
|
-
options = subject.driver_options
|
27
|
-
options[:options] = subject.options
|
28
|
-
options[:http_client] = subject.http_client
|
29
|
-
|
30
|
-
expect(Capybara::Selenium::Driver).to receive(:new).with(:app, options)
|
31
|
-
|
32
|
-
subject.driver :app
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
RSpec.shared_context 'driver_with_not_options_but_with_http_client' do
|
37
|
-
it 'adds http client options' do
|
38
|
-
options = subject.driver_options
|
39
|
-
options[:http_client] = subject.http_client
|
40
|
-
|
41
|
-
expect(Capybara::Selenium::Driver).to receive(:new).with(:app, options)
|
42
|
-
|
43
|
-
subject.driver :app
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
RSpec.describe CapybaraBox::Base, '.driver' do
|
48
|
-
subject { described_class.new parameters }
|
49
|
-
|
50
|
-
let!(:args) { { log_path: 'log/capybara-box.log', verbose: true } }
|
51
|
-
let!(:service) { instance_double 'Selenium::WebDriver::Service' }
|
52
|
-
let!(:old_ci) { ENV['CI'] }
|
53
|
-
|
54
|
-
before do
|
55
|
-
ENV['CI'] = 'false'
|
56
|
-
|
57
|
-
allow(Selenium::WebDriver::Service).to receive(:chrome).with(args: args).and_return service
|
58
|
-
end
|
59
|
-
|
60
|
-
after { ENV['CI'] = old_ci }
|
61
|
-
|
62
|
-
context 'when is chrome' do
|
63
|
-
let!(:parameters) { { browser: :chrome } }
|
64
|
-
|
65
|
-
it_behaves_like 'driver_with_options'
|
66
|
-
|
67
|
-
context 'when env is CI' do
|
68
|
-
before { ENV['CI'] = 'true' }
|
69
|
-
|
70
|
-
it_behaves_like 'driver_with_options_and_http_client'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when is chrome headless' do
|
75
|
-
let!(:parameters) { { browser: :chrome_headless } }
|
76
|
-
|
77
|
-
it_behaves_like 'driver_with_options'
|
78
|
-
|
79
|
-
context 'when env is CI' do
|
80
|
-
before { ENV['CI'] = 'true' }
|
81
|
-
|
82
|
-
it_behaves_like 'driver_with_options_and_http_client'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when is firefox' do
|
87
|
-
let!(:parameters) { { browser: :firefox } }
|
88
|
-
|
89
|
-
it_behaves_like 'driver_with_no_options'
|
90
|
-
|
91
|
-
context 'when env is CI' do
|
92
|
-
before { ENV['CI'] = 'true' }
|
93
|
-
|
94
|
-
it_behaves_like 'driver_with_not_options_but_with_http_client'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe CapybaraBox::Base, '.firefox?' do
|
4
|
-
subject { described_class.new parameters }
|
5
|
-
|
6
|
-
context 'when :browser is firefox' do
|
7
|
-
let!(:parameters) { { browser: :firefox } }
|
8
|
-
|
9
|
-
specify { expect(subject).to be_firefox }
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when :browser is not firefox' do
|
13
|
-
let!(:parameters) { { browser: :not_firefox } }
|
14
|
-
|
15
|
-
specify { expect(subject).not_to be_firefox }
|
16
|
-
end
|
17
|
-
end
|