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,23 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.register' do
4
+ subject { described_class.new parameters }
5
+
6
+ let!(:parameters) { { browser: :browser } }
7
+
8
+ it 'returns the driver options' do
9
+ expect(subject.driver_options).to eq(
10
+ browser: :browser,
11
+ clear_local_storage: true,
12
+ clear_session_storage: true
13
+ )
14
+ end
15
+
16
+ context 'when :driver_options is given' do
17
+ let!(:parameters) { { driver_options: { key: :value }, browser: :browser } }
18
+
19
+ it 'is used' do
20
+ expect(subject.driver_options).to eq(key: :value)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,87 @@
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
+ before { ENV['CI'] = 'false' }
51
+
52
+ context 'when is chrome' do
53
+ let!(:parameters) { { browser: :chrome } }
54
+
55
+ it_behaves_like 'driver_with_options'
56
+
57
+ context 'when env is CI' do
58
+ before { ENV['CI'] = 'true' }
59
+
60
+ it_behaves_like 'driver_with_options_and_http_client'
61
+ end
62
+ end
63
+
64
+ context 'when is chrome headless' do
65
+ let!(:parameters) { { browser: :chrome_headless } }
66
+
67
+ it_behaves_like 'driver_with_options'
68
+
69
+ context 'when env is CI' do
70
+ before { ENV['CI'] = 'true' }
71
+
72
+ it_behaves_like 'driver_with_options_and_http_client'
73
+ end
74
+ end
75
+
76
+ context 'when is firefox' do
77
+ let!(:parameters) { { browser: :firefox } }
78
+
79
+ it_behaves_like 'driver_with_no_options'
80
+
81
+ context 'when env is CI' do
82
+ before { ENV['CI'] = 'true' }
83
+
84
+ it_behaves_like 'driver_with_not_options_but_with_http_client'
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.http_client_options' do
4
+ context 'when :http_client_options is not given' do
5
+ subject { described_class.new }
6
+
7
+ it 'returns the http client options' do
8
+ expect(subject.http_client_options).to eq(
9
+ open_timeout: nil,
10
+ read_timeout: 120
11
+ )
12
+ end
13
+ end
14
+
15
+ context 'when :http_client_options is given' do
16
+ subject { described_class.new parameters }
17
+
18
+ let!(:parameters) { { http_client_options: { key: :value } } }
19
+
20
+ it 'is used' do
21
+ expect(subject.http_client_options).to eq(key: :value)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.http_client' do
4
+ before do
5
+ allow(Selenium::WebDriver::Remote::Http::Default).to receive(:new).with(subject.http_client_options) { :client }
6
+ end
7
+
8
+ it 'returns the default http client' do
9
+ expect(subject.http_client).to eq :client
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.options' do
4
+ subject { described_class.configure parameters }
5
+
6
+ context 'when is chrome' do
7
+ let!(:parameters) { { browser: :chrome } }
8
+
9
+ let!(:options) do
10
+ instance_double(Selenium::WebDriver::Chrome::Options).as_null_object
11
+ end
12
+
13
+ before do
14
+ allow(Selenium::WebDriver::Chrome::Options).to receive(:new).with(no_args) { options }
15
+ end
16
+
17
+ it 'returns a instance of chrome options' do
18
+ expect(subject.options).to eq options
19
+ end
20
+ end
21
+
22
+ context 'when is chrome headless' do
23
+ let!(:parameters) { { browser: :chrome_headless } }
24
+
25
+ let!(:options) do
26
+ instance_double(Selenium::WebDriver::Chrome::Options).as_null_object
27
+ end
28
+
29
+ before do
30
+ allow(Selenium::WebDriver::Chrome::Options).to receive(:new).with(no_args) { options }
31
+ end
32
+
33
+ it 'returns a instance of chrome options' do
34
+ expect(subject.options).to eq options
35
+ end
36
+ end
37
+
38
+ context 'when is firefox' do
39
+ let!(:parameters) { { browser: :firefox } }
40
+
41
+ specify { expect(subject.options).to be_nil }
42
+ end
43
+ end
@@ -0,0 +1,63 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.preferences' do
4
+ subject { described_class.new parameters }
5
+
6
+ let!(:chrome_family_preferences) do
7
+ {
8
+ credentials_enable_service: false,
9
+
10
+ profile: {
11
+ password_manager_enabled: false
12
+ }
13
+ }
14
+ end
15
+
16
+ context 'when is chrome' do
17
+ let!(:parameters) { { browser: :chrome } }
18
+
19
+ it 'receives the right preferences' do
20
+ expect(subject.preferences).to eq chrome_family_preferences
21
+ end
22
+
23
+ context 'and :preferences is given' do
24
+ before { parameters[:preferences] = { key: :value } }
25
+
26
+ it 'is used' do
27
+ expect(subject.preferences).to eq(key: :value)
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'when is chrome headless' do
33
+ let!(:parameters) { { browser: :chrome_headless } }
34
+
35
+ it 'receives the right preferences' do
36
+ expect(subject.preferences).to eq chrome_family_preferences
37
+ end
38
+
39
+ context 'and :preferences is given' do
40
+ before { parameters[:preferences] = { key: :value } }
41
+
42
+ it 'is used' do
43
+ expect(subject.preferences).to eq(key: :value)
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'when is firefox' do
49
+ let!(:parameters) { { browser: :firefox } }
50
+
51
+ it 'receives the right preferences' do
52
+ expect(subject.preferences).to eq({})
53
+ end
54
+
55
+ context 'and :preferences is given' do
56
+ before { parameters[:preferences] = { key: :value } }
57
+
58
+ it 'is used' do
59
+ expect(subject.preferences).to eq(key: :value)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.register' do
4
+ subject { described_class.new }
5
+
6
+ let!(:app) { double }
7
+
8
+ before do
9
+ allow(Capybara).to receive(:register_driver).with(:name).and_yield app
10
+ end
11
+
12
+ it 'register the driver with given name' do
13
+ expect(subject).to receive(:driver).with app
14
+
15
+ subject.register :name
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '#configure' do
4
+ let!(:parameters) { { key: :value } }
5
+ let!(:box) { instance_double(CapybaraBox::Base).as_null_object }
6
+
7
+ before do
8
+ allow(described_class).to receive(:new).with(parameters) { box }
9
+ end
10
+
11
+ it 'creates the box with given parameters' do
12
+ expect(box).to receive :create
13
+
14
+ described_class.configure parameters
15
+ end
16
+
17
+ it 'returns the created box' do
18
+ expect(described_class.configure(parameters)).to eq box
19
+
20
+ described_class.configure parameters
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CapybaraBox::Base, '.version' do
4
+ subject { described_class.configure parameters }
5
+
6
+ context 'when version is given' do
7
+ let!(:parameters) { { version: '2.30' } }
8
+
9
+ context 'and browser is chrome' do
10
+ before { parameters[:browser] = :chrome }
11
+
12
+ it 'applies the version' do
13
+ expect(subject.version).to eq '2.30'
14
+ end
15
+ end
16
+
17
+ context 'and browser is chrome headless' do
18
+ before { parameters[:browser] = :chrome_headless }
19
+
20
+ it 'applies the version' do
21
+ expect(subject.version).to eq '2.30'
22
+ end
23
+ end
24
+
25
+ context 'and browser is not chrome headless' do
26
+ before { parameters[:browser] = :firefox }
27
+
28
+ it 'does not apply the version' do
29
+ expect(subject.version).to be_nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require 'capybara'
6
+ require 'capybara-box'
7
+ require 'pry-byebug'
8
+
9
+ Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+
5
+ RSpec.configure do |config|
6
+ config.filter_run_when_matching :focus
7
+
8
+ config.disable_monkey_patching!
9
+
10
+ config.order = :random
11
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Washington Botelho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara-screenshot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chromedriver-helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack_session_access
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: selenium-webdriver
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Tool Box for Capybara.
140
+ email: wbotelhos@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - CHANGELOG.md
146
+ - LICENSE
147
+ - README.md
148
+ - lib/capybara-box.rb
149
+ - lib/capybara-box/base.rb
150
+ - 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/browser_spec.rb
159
+ - spec/lib/capybara_box/base/chrome_family_spec.rb
160
+ - spec/lib/capybara_box/base/chrome_headless_spec.rb
161
+ - spec/lib/capybara_box/base/chrome_spec.rb
162
+ - spec/lib/capybara_box/base/configure_screenshot_spec.rb
163
+ - spec/lib/capybara_box/base/configure_spec.rb
164
+ - spec/lib/capybara_box/base/create_spec.rb
165
+ - spec/lib/capybara_box/base/driver_options_spec.rb
166
+ - spec/lib/capybara_box/base/driver_spec.rb
167
+ - spec/lib/capybara_box/base/firefox_spec.rb
168
+ - spec/lib/capybara_box/base/http_client_options_spec.rb
169
+ - spec/lib/capybara_box/base/http_client_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
+ homepage: https://github.com/wbotelhos/capybara-box
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.12
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: A Tool Box for Capybara.
201
+ test_files:
202
+ - spec/lib/capybara_box/base/add_argument_spec.rb
203
+ - spec/lib/capybara_box/base/add_preference_spec.rb
204
+ - spec/lib/capybara_box/base/apply_arguments_spec.rb
205
+ - spec/lib/capybara_box/base/apply_bin_path_spec.rb
206
+ - spec/lib/capybara_box/base/apply_preferences_spec.rb
207
+ - spec/lib/capybara_box/base/apply_version_spec.rb
208
+ - spec/lib/capybara_box/base/arguments_spec.rb
209
+ - spec/lib/capybara_box/base/browser_spec.rb
210
+ - spec/lib/capybara_box/base/chrome_family_spec.rb
211
+ - spec/lib/capybara_box/base/chrome_headless_spec.rb
212
+ - spec/lib/capybara_box/base/chrome_spec.rb
213
+ - spec/lib/capybara_box/base/configure_screenshot_spec.rb
214
+ - spec/lib/capybara_box/base/configure_spec.rb
215
+ - spec/lib/capybara_box/base/create_spec.rb
216
+ - spec/lib/capybara_box/base/driver_options_spec.rb
217
+ - spec/lib/capybara_box/base/driver_spec.rb
218
+ - spec/lib/capybara_box/base/firefox_spec.rb
219
+ - spec/lib/capybara_box/base/http_client_options_spec.rb
220
+ - spec/lib/capybara_box/base/http_client_spec.rb
221
+ - spec/lib/capybara_box/base/options_spec.rb
222
+ - spec/lib/capybara_box/base/preferences_spec.rb
223
+ - spec/lib/capybara_box/base/register_spec.rb
224
+ - spec/lib/capybara_box/base/self_configure_spec.rb
225
+ - spec/lib/capybara_box/base/version_spec.rb
226
+ - spec/rails_helper.rb
227
+ - spec/support/common.rb