capybara-box 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE +21 -0
  4. data/README.md +126 -0
  5. data/lib/capybara-box.rb +6 -0
  6. data/lib/capybara-box/base.rb +226 -0
  7. data/lib/capybara-box/version.rb +5 -0
  8. data/spec/lib/capybara_box/base/add_argument_spec.rb +35 -0
  9. data/spec/lib/capybara_box/base/add_preference_spec.rb +35 -0
  10. data/spec/lib/capybara_box/base/apply_arguments_spec.rb +33 -0
  11. data/spec/lib/capybara_box/base/apply_bin_path_spec.rb +34 -0
  12. data/spec/lib/capybara_box/base/apply_preferences_spec.rb +43 -0
  13. data/spec/lib/capybara_box/base/apply_version_spec.rb +35 -0
  14. data/spec/lib/capybara_box/base/arguments_spec.rb +72 -0
  15. data/spec/lib/capybara_box/base/browser_spec.rb +27 -0
  16. data/spec/lib/capybara_box/base/chrome_family_spec.rb +23 -0
  17. data/spec/lib/capybara_box/base/chrome_headless_spec.rb +17 -0
  18. data/spec/lib/capybara_box/base/chrome_spec.rb +17 -0
  19. data/spec/lib/capybara_box/base/configure_screenshot_spec.rb +83 -0
  20. data/spec/lib/capybara_box/base/configure_spec.rb +33 -0
  21. data/spec/lib/capybara_box/base/create_spec.rb +77 -0
  22. data/spec/lib/capybara_box/base/driver_options_spec.rb +23 -0
  23. data/spec/lib/capybara_box/base/driver_spec.rb +87 -0
  24. data/spec/lib/capybara_box/base/firefox_spec.rb +17 -0
  25. data/spec/lib/capybara_box/base/http_client_options_spec.rb +24 -0
  26. data/spec/lib/capybara_box/base/http_client_spec.rb +11 -0
  27. data/spec/lib/capybara_box/base/options_spec.rb +43 -0
  28. data/spec/lib/capybara_box/base/preferences_spec.rb +63 -0
  29. data/spec/lib/capybara_box/base/register_spec.rb +17 -0
  30. data/spec/lib/capybara_box/base/self_configure_spec.rb +22 -0
  31. data/spec/lib/capybara_box/base/version_spec.rb +33 -0
  32. data/spec/rails_helper.rb +9 -0
  33. data/spec/support/common.rb +11 -0
  34. metadata +227 -0
@@ -0,0 +1,33 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.apply_arguments' do
4
+ subject { described_class.new parameters }
5
+
6
+ before do
7
+ allow(subject).to receive(:arguments) { ['--argument'] }
8
+ end
9
+
10
+ context 'when is not chrome' do
11
+ let!(:parameters) { { browser: :chrome } }
12
+
13
+ it 'applies' do
14
+ expect(subject.options.args).to eq []
15
+
16
+ subject.apply_arguments
17
+
18
+ expect(subject.options.args).to eq ['--argument']
19
+ end
20
+ end
21
+
22
+ context 'when is chrome headless' do
23
+ let!(:parameters) { { browser: :chrome_headless } }
24
+
25
+ it 'applies' do
26
+ expect(subject.options.args).to eq []
27
+
28
+ subject.apply_arguments
29
+
30
+ expect(subject.options.args).to eq ['--argument', '--headless']
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.apply_bin_path' do
4
+ subject { described_class.new parameters }
5
+
6
+ before :all do
7
+ File.open('/tmp/bin', 'w') { |file| file.write 'echo "capybara-box/bin"' }
8
+ FileUtils.chmod 0755, '/tmp/bin'
9
+ end
10
+
11
+ context 'when is chrome' do
12
+ let!(:parameters) { { browser: :chrome } }
13
+
14
+ it 'does not apply' do
15
+ expect(subject.apply_bin_path('/tmp/bin')).to be_nil
16
+ end
17
+ end
18
+
19
+ context 'when is chrome headless' do
20
+ let!(:parameters) { { browser: :chrome_headless } }
21
+
22
+ it 'does not apply' do
23
+ expect(subject.apply_bin_path('/tmp/bin')).to be_nil
24
+ end
25
+ end
26
+
27
+ context 'when is firefox' do
28
+ let!(:parameters) { { browser: :firefox } }
29
+
30
+ it 'does not applies options' do
31
+ expect(subject.apply_bin_path('/tmp/bin')).to eq '/tmp/bin'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.apply_preferences' do
4
+ subject { described_class.new parameters }
5
+
6
+ before do
7
+ allow(subject).to receive(:preferences) { { key: :value } }
8
+ end
9
+
10
+ context 'when is chrome' do
11
+ let!(:parameters) { { browser: :chrome } }
12
+
13
+ it 'applies' do
14
+ expect(subject.options.prefs).to eq({})
15
+
16
+ subject.apply_preferences
17
+
18
+ expect(subject.options.prefs).to eq(key: :value)
19
+ end
20
+ end
21
+
22
+ context 'when is chrome headless' do
23
+ let!(:parameters) { { browser: :chrome_headless } }
24
+
25
+ it 'applies' do
26
+ expect(subject.options.prefs).to eq({})
27
+
28
+ subject.apply_preferences
29
+
30
+ expect(subject.options.prefs).to eq(key: :value)
31
+ end
32
+ end
33
+
34
+ context 'when is firefox' do
35
+ let!(:parameters) { { browser: :firefox } }
36
+
37
+ it 'does not applies options' do
38
+ subject.apply_preferences
39
+
40
+ expect(subject.options).to be_nil
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.apply_version' do
4
+ subject { described_class.new parameters }
5
+
6
+ context 'when browser is chrome' do
7
+ let!(:parameters) { { browser: :chrome } }
8
+
9
+ it 'is used' do
10
+ subject.apply_version '2.31'
11
+
12
+ expect(subject.version).to eq '2.31'
13
+ end
14
+ end
15
+
16
+ context 'when browser is chrome headless' do
17
+ let!(:parameters) { { browser: :chrome_headless } }
18
+
19
+ it 'is used' do
20
+ subject.apply_version '2.31'
21
+
22
+ expect(subject.version).to eq '2.31'
23
+ end
24
+ end
25
+
26
+ context 'when browser is firefox' do
27
+ let!(:parameters) { { browser: :firefox } }
28
+
29
+ it 'does not applies options' do
30
+ subject.apply_preferences
31
+
32
+ expect(subject.options).to be_nil
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,72 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.arguments' do
4
+ subject { described_class.new parameters }
5
+
6
+ let!(:chrome_family_arguments) do
7
+ %w[
8
+ --disable-default-apps
9
+ --disable-extensions
10
+ --disable-infobars
11
+ --disable-notifications
12
+ --disable-password-generation
13
+ --disable-password-manager-reauthentication
14
+ --disable-password-separated-signin-flow
15
+ --disable-popup-blocking
16
+ --disable-save-password-bubble
17
+ --disable-translate
18
+ --incognito
19
+ --mute-audio
20
+ --no-default-browser-check
21
+ --start-fullscreen
22
+ ]
23
+ end
24
+
25
+ context 'when is chrome' do
26
+ let!(:parameters) { { browser: :chrome } }
27
+
28
+ it 'receives the right arguments' do
29
+ expect(subject.arguments).to eq chrome_family_arguments
30
+ end
31
+
32
+ context 'when arguments is given' do
33
+ let!(:parameters) { { arguments: ['--custom'], browser: :firefox } }
34
+
35
+ it 'is used' do
36
+ expect(subject.arguments).to eq ['--custom']
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'when is chrome headless' do
42
+ let!(:parameters) { { browser: :chrome_headless } }
43
+
44
+ it 'receives the right arguments' do
45
+ expect(subject.arguments).to eq chrome_family_arguments
46
+ end
47
+
48
+ context 'when arguments is given' do
49
+ let!(:parameters) { { arguments: ['--custom'], browser: :chrome_headless } }
50
+
51
+ it 'is used' do
52
+ expect(subject.arguments).to eq ['--custom']
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'when is firefox' do
58
+ let!(:parameters) { { browser: :firefox } }
59
+
60
+ it 'receives the right arguments' do
61
+ expect(subject.arguments).to eq []
62
+ end
63
+
64
+ context 'when arguments is given' do
65
+ let!(:parameters) { { arguments: ['--custom'], browser: :firefox } }
66
+
67
+ it 'is used' do
68
+ expect(subject.arguments).to eq ['--custom']
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,27 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.browser' do
4
+ context 'when :browser is chrome family' do
5
+ before do
6
+ allow(subject).to receive(:chrome_family?) { true }
7
+ end
8
+
9
+ it 'is considered chrome' do
10
+ expect(subject.browser).to eq :chrome
11
+ end
12
+ end
13
+
14
+ context 'when :browser is not chrome family' do
15
+ subject { described_class.new parameters }
16
+
17
+ let!(:parameters) { { browser: :original_name } }
18
+
19
+ before do
20
+ allow(subject).to receive(:chrome_family?) { false }
21
+ end
22
+
23
+ it 'returns the original name' do
24
+ expect(subject.browser).to eq :original_name
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,77 @@
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
+ let!(:parameters) { { browser: :firefox } }
70
+
71
+ it 'registers the given browser' do
72
+ expect(subject).to receive(:register).with :firefox
73
+
74
+ subject.create
75
+ end
76
+ end
77
+ end