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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  3. data/README.md +32 -42
  4. data/lib/capybara-box.rb +6 -2
  5. data/lib/capybara-box/base.rb +43 -98
  6. data/lib/capybara-box/helper.rb +11 -0
  7. data/lib/capybara-box/screenshot.rb +41 -0
  8. data/lib/capybara-box/version.rb +1 -1
  9. metadata +11 -58
  10. data/spec/lib/capybara_box/base/add_argument_spec.rb +0 -35
  11. data/spec/lib/capybara_box/base/add_preference_spec.rb +0 -35
  12. data/spec/lib/capybara_box/base/apply_arguments_spec.rb +0 -33
  13. data/spec/lib/capybara_box/base/apply_bin_path_spec.rb +0 -34
  14. data/spec/lib/capybara_box/base/apply_preferences_spec.rb +0 -43
  15. data/spec/lib/capybara_box/base/apply_version_spec.rb +0 -37
  16. data/spec/lib/capybara_box/base/arguments_spec.rb +0 -72
  17. data/spec/lib/capybara_box/base/chrome_family_spec.rb +0 -23
  18. data/spec/lib/capybara_box/base/chrome_headless_spec.rb +0 -17
  19. data/spec/lib/capybara_box/base/chrome_spec.rb +0 -17
  20. data/spec/lib/capybara_box/base/configure_screenshot_spec.rb +0 -83
  21. data/spec/lib/capybara_box/base/configure_spec.rb +0 -33
  22. data/spec/lib/capybara_box/base/create_spec.rb +0 -89
  23. data/spec/lib/capybara_box/base/driver_options_spec.rb +0 -74
  24. data/spec/lib/capybara_box/base/driver_spec.rb +0 -97
  25. data/spec/lib/capybara_box/base/firefox_spec.rb +0 -17
  26. data/spec/lib/capybara_box/base/http_client_options_spec.rb +0 -24
  27. data/spec/lib/capybara_box/base/http_client_spec.rb +0 -11
  28. data/spec/lib/capybara_box/base/log_spec.rb +0 -43
  29. data/spec/lib/capybara_box/base/options_spec.rb +0 -43
  30. data/spec/lib/capybara_box/base/preferences_spec.rb +0 -63
  31. data/spec/lib/capybara_box/base/register_spec.rb +0 -17
  32. data/spec/lib/capybara_box/base/self_configure_spec.rb +0 -22
  33. data/spec/lib/capybara_box/base/version_spec.rb +0 -33
  34. data/spec/rails_helper.rb +0 -9
  35. data/spec/support/common.rb +0 -11
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapybaraBox
4
+ module Helper
5
+ module_function
6
+
7
+ def true?(value)
8
+ ['true', true].include?(value)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapybaraBox
4
+ module Screenshot
5
+ module_function
6
+
7
+ def configure(options, browser_name)
8
+ return unless ::CapybaraBox::Helper.true?(options[:enabled])
9
+
10
+ require 'capybara-screenshot/rspec'
11
+
12
+ Capybara::Screenshot.append_timestamp = false
13
+ Capybara::Screenshot.prune_strategy = :keep_last_run
14
+ Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false
15
+
16
+ Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
17
+ example.full_description.downcase.gsub('#', '--').tr ' ', '-'
18
+ end
19
+
20
+ if options[:s3]
21
+ bucket_name = ENV['CAPYBARA_BOX__S3_BUCKET_NAME']
22
+ region = ENV['CAPYBARA_BOX__S3_REGION']
23
+
24
+ Capybara::Screenshot.s3_configuration = {
25
+ bucket_name: bucket_name,
26
+ bucket_host: "#{bucket_name}.#{region}.amazonaws.com",
27
+
28
+ s3_client_credentials: {
29
+ access_key_id: ENV['CAPYBARA_BOX__S3_ACCESS_KEY_ID'],
30
+ region: region,
31
+ secret_access_key: ENV['CAPYBARA_BOX__S3_SECRET_ACCESS_KEY']
32
+ },
33
+ }
34
+ end
35
+
36
+ Capybara::Screenshot.register_driver(browser_name) do |driver, path|
37
+ driver.browser.save_screenshot(path)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CapybaraBox
4
- VERSION = '0.4.0'.freeze
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-25 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara-screenshot
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: chromedriver-helper
56
+ name: webdrivers
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -140,40 +140,19 @@ description: A Tool Box for Capybara.
140
140
  email: wbotelhos@gmail.com
141
141
  executables: []
142
142
  extensions: []
143
- extra_rdoc_files: []
143
+ extra_rdoc_files:
144
+ - CHANGELOG.md
145
+ - LICENSE
146
+ - README.md
144
147
  files:
145
148
  - CHANGELOG.md
146
149
  - LICENSE
147
150
  - README.md
148
151
  - lib/capybara-box.rb
149
152
  - lib/capybara-box/base.rb
153
+ - lib/capybara-box/helper.rb
154
+ - lib/capybara-box/screenshot.rb
150
155
  - lib/capybara-box/version.rb
151
- - spec/lib/capybara_box/base/add_argument_spec.rb
152
- - spec/lib/capybara_box/base/add_preference_spec.rb
153
- - spec/lib/capybara_box/base/apply_arguments_spec.rb
154
- - spec/lib/capybara_box/base/apply_bin_path_spec.rb
155
- - spec/lib/capybara_box/base/apply_preferences_spec.rb
156
- - spec/lib/capybara_box/base/apply_version_spec.rb
157
- - spec/lib/capybara_box/base/arguments_spec.rb
158
- - spec/lib/capybara_box/base/chrome_family_spec.rb
159
- - spec/lib/capybara_box/base/chrome_headless_spec.rb
160
- - spec/lib/capybara_box/base/chrome_spec.rb
161
- - spec/lib/capybara_box/base/configure_screenshot_spec.rb
162
- - spec/lib/capybara_box/base/configure_spec.rb
163
- - spec/lib/capybara_box/base/create_spec.rb
164
- - spec/lib/capybara_box/base/driver_options_spec.rb
165
- - spec/lib/capybara_box/base/driver_spec.rb
166
- - spec/lib/capybara_box/base/firefox_spec.rb
167
- - spec/lib/capybara_box/base/http_client_options_spec.rb
168
- - spec/lib/capybara_box/base/http_client_spec.rb
169
- - spec/lib/capybara_box/base/log_spec.rb
170
- - spec/lib/capybara_box/base/options_spec.rb
171
- - spec/lib/capybara_box/base/preferences_spec.rb
172
- - spec/lib/capybara_box/base/register_spec.rb
173
- - spec/lib/capybara_box/base/self_configure_spec.rb
174
- - spec/lib/capybara_box/base/version_spec.rb
175
- - spec/rails_helper.rb
176
- - spec/support/common.rb
177
156
  homepage: https://github.com/wbotelhos/capybara-box
178
157
  licenses:
179
158
  - MIT
@@ -197,30 +176,4 @@ rubygems_version: 3.1.2
197
176
  signing_key:
198
177
  specification_version: 4
199
178
  summary: A Tool Box for Capybara.
200
- test_files:
201
- - spec/support/common.rb
202
- - spec/lib/capybara_box/base/http_client_spec.rb
203
- - spec/lib/capybara_box/base/apply_preferences_spec.rb
204
- - spec/lib/capybara_box/base/firefox_spec.rb
205
- - spec/lib/capybara_box/base/apply_arguments_spec.rb
206
- - spec/lib/capybara_box/base/driver_spec.rb
207
- - spec/lib/capybara_box/base/self_configure_spec.rb
208
- - spec/lib/capybara_box/base/add_argument_spec.rb
209
- - spec/lib/capybara_box/base/apply_bin_path_spec.rb
210
- - spec/lib/capybara_box/base/version_spec.rb
211
- - spec/lib/capybara_box/base/options_spec.rb
212
- - spec/lib/capybara_box/base/register_spec.rb
213
- - spec/lib/capybara_box/base/log_spec.rb
214
- - spec/lib/capybara_box/base/add_preference_spec.rb
215
- - spec/lib/capybara_box/base/create_spec.rb
216
- - spec/lib/capybara_box/base/chrome_headless_spec.rb
217
- - spec/lib/capybara_box/base/chrome_family_spec.rb
218
- - spec/lib/capybara_box/base/apply_version_spec.rb
219
- - spec/lib/capybara_box/base/chrome_spec.rb
220
- - spec/lib/capybara_box/base/arguments_spec.rb
221
- - spec/lib/capybara_box/base/http_client_options_spec.rb
222
- - spec/lib/capybara_box/base/driver_options_spec.rb
223
- - spec/lib/capybara_box/base/configure_screenshot_spec.rb
224
- - spec/lib/capybara_box/base/preferences_spec.rb
225
- - spec/lib/capybara_box/base/configure_spec.rb
226
- - spec/rails_helper.rb
179
+ test_files: []
@@ -1,35 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe CapybaraBox::Base, '.add_argument' do
4
- subject { described_class.new parameters }
5
-
6
- context 'when is chrome' do
7
- let!(:parameters) { { browser: :chrome } }
8
-
9
- it 'adds the argument' do
10
- subject.add_argument '--argument'
11
-
12
- expect(subject.options.args).to eq Set['--argument']
13
- end
14
- end
15
-
16
- context 'when is chrome headless' do
17
- let!(:parameters) { { browser: :chrome_headless } }
18
-
19
- it 'adds the argument' do
20
- subject.add_argument '--argument'
21
-
22
- expect(subject.options.args).to eq Set['--argument']
23
- end
24
- end
25
-
26
- context 'when is firefox' do
27
- let!(:parameters) { { browser: :firefox } }
28
-
29
- it 'does not applies options' do
30
- subject.add_argument '--argument'
31
-
32
- expect(subject.options).to be_nil
33
- end
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- require 'rails_helper'
2
-
3
- RSpec.describe CapybaraBox::Base, '.add_preference' do
4
- subject { described_class.new parameters }
5
-
6
- context 'when is chrome' do
7
- let!(:parameters) { { browser: :chrome } }
8
-
9
- it 'adds the argument' do
10
- subject.add_preference :key, :value
11
-
12
- expect(subject.options.prefs).to eq(key: :value)
13
- end
14
- end
15
-
16
- context 'when is chrome headless' do
17
- let!(:parameters) { { browser: :chrome_headless } }
18
-
19
- it 'adds the argument' do
20
- subject.add_preference :key, :value
21
-
22
- expect(subject.options.prefs).to eq(key: :value)
23
- end
24
- end
25
-
26
- context 'when is firefox' do
27
- let!(:parameters) { { browser: :firefox } }
28
-
29
- it 'does not applies options' do
30
- subject.add_preference :key, :value
31
-
32
- expect(subject.options).to be_nil
33
- end
34
- end
35
- end
@@ -1,33 +0,0 @@
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) { Set['--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 Set.new
15
-
16
- subject.apply_arguments
17
-
18
- expect(subject.options.args).to eq Set['--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 Set.new
27
-
28
- subject.apply_arguments
29
-
30
- expect(subject.options.args).to eq Set['--argument', '--headless']
31
- end
32
- end
33
- end
@@ -1,34 +0,0 @@
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
@@ -1,43 +0,0 @@
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
@@ -1,37 +0,0 @@
1
- require 'rails_helper'
2
-
3
- require 'chromedriver/helper'
4
-
5
- RSpec.describe CapybaraBox::Base, '.apply_version' do
6
- subject { described_class.new parameters }
7
-
8
- context 'when browser is chrome' do
9
- let!(:parameters) { { browser: :chrome } }
10
-
11
- it 'is used' do
12
- subject.apply_version '2.31'
13
-
14
- expect(subject.version).to eq '2.31'
15
- end
16
- end
17
-
18
- context 'when browser is chrome headless' do
19
- let!(:parameters) { { browser: :chrome_headless } }
20
-
21
- it 'is used' do
22
- subject.apply_version '2.31'
23
-
24
- expect(subject.version).to eq '2.31'
25
- end
26
- end
27
-
28
- context 'when browser is firefox' do
29
- let!(:parameters) { { browser: :firefox } }
30
-
31
- it 'does not applies options' do
32
- subject.apply_preferences
33
-
34
- expect(subject.options).to be_nil
35
- end
36
- end
37
- end
@@ -1,72 +0,0 @@
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