capybara-experience 0.1.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/capybara-experience.gemspec +2 -0
- data/lib/capybara/experience/pool.rb +54 -0
- data/lib/capybara/experience/rspec.rb +33 -26
- data/lib/capybara/experience/version.rb +1 -1
- data/lib/capybara/experience.rb +22 -24
- metadata +21 -7
- data/lib/capybara/experience/session.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e604603bfb1f0fde33216fc173bd1c4050a93251f8009054c68fc920996a6e6
|
4
|
+
data.tar.gz: 5672e3dd951dbbeb68513427e07c79607cadeb4b6812b7d8b431da06830d126f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e729f9c62eda4bb7d5d446d5215c199c3443419841a3c876a7378cdd8f2a6766e9c5589b2cc320c60d2577f0f9314bd9a3b43a3238562acf6a48283c66d4e97
|
7
|
+
data.tar.gz: 6d913cbe6e6bbde172f82175317d217ef0b1edd8a11a5fa2883e6cf41b13208dcf9cab603cb8c7a51b38997b14e984b0f84ab9cfc7cf272b731edecca19a483c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -36,6 +36,8 @@ This scenario is for your standard user/admin.
|
|
36
36
|
```ruby
|
37
37
|
# spec/support/experiences/user_experience.rb
|
38
38
|
class UserExperience < Capybara::Experience
|
39
|
+
include Rails.application.routes.url_helpers
|
40
|
+
|
39
41
|
def login(user)
|
40
42
|
@user = user
|
41
43
|
login_as user, scope: :user
|
@@ -98,7 +100,7 @@ RSpec.describe "sign up flow", feature: true do
|
|
98
100
|
|
99
101
|
it "works" do
|
100
102
|
behavior "user can sign up" do # behaviors are an added DSL by capybara-experiences to group interactions & assertions
|
101
|
-
guest_ux =
|
103
|
+
guest_ux = GuestExperience.new
|
102
104
|
guest_ux.navigate_to_sign_up
|
103
105
|
|
104
106
|
guest_ux.sign_up(
|
data/capybara-experience.gemspec
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "singleton"
|
3
|
+
|
4
|
+
module Capybara
|
5
|
+
class Experience
|
6
|
+
class Pool < Hash
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
super(key) || begin
|
11
|
+
driver, _session_name, app_object_id = key.split(":")
|
12
|
+
take(driver: driver, app_object_id: app_object_id, key: key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def take(driver: Capybara.current_driver, app_object_id: Capybara.app.object_id, key: nil)
|
17
|
+
session = idle.find { |s| s.mode == driver && s.app.object_id == app_object_id }
|
18
|
+
if session
|
19
|
+
idle.delete(session)
|
20
|
+
self[key] = delete(session_key(session)) if key
|
21
|
+
else
|
22
|
+
session = ::Capybara::Session.new(driver.to_sym, Capybara.app)
|
23
|
+
key ||= session_key(session)
|
24
|
+
self[key] = session
|
25
|
+
end
|
26
|
+
|
27
|
+
session
|
28
|
+
end
|
29
|
+
|
30
|
+
def idle
|
31
|
+
@idle ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
def taken
|
35
|
+
values - idle
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset_idle!
|
39
|
+
each do |key, session|
|
40
|
+
self[session_key(session)] = delete(key)
|
41
|
+
end
|
42
|
+
@idle = values
|
43
|
+
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def session_key(session)
|
50
|
+
"#{session.mode}:#{session.object_id}:#{session.app.object_id}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,30 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
class Experience
|
5
|
+
module BehaviorDSL
|
6
|
+
def behavior(name)
|
7
|
+
metadata[:description_args].push(name)
|
8
|
+
refresh_description unless in_continuous_integration_env?
|
9
|
+
yield
|
10
|
+
metadata[:description_args].pop
|
11
|
+
refresh_description unless in_continuous_integration_env?
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def refresh_description
|
17
|
+
metadata[:description] = metadata[:description_args].join(" ")
|
18
|
+
metadata[:full_description] = [metadata[:example_group][:full_description]].concat(metadata[:description_args]).join(" ")
|
19
|
+
end
|
20
|
+
|
21
|
+
def metadata
|
22
|
+
RSpec.current_example.metadata
|
23
|
+
end
|
24
|
+
|
25
|
+
def in_continuous_integration_env?
|
26
|
+
ENV["CI"].present?
|
27
|
+
end
|
9
28
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.include BehaviorDSL
|
32
|
+
config.prepend_after :each, type: :feature, js: true do
|
33
|
+
Capybara::Experience::Pool.instance.reset_idle!
|
34
|
+
end
|
16
35
|
end
|
17
|
-
|
18
|
-
def metadata
|
19
|
-
RSpec.current_example.metadata
|
20
|
-
end
|
21
|
-
|
22
|
-
def in_continuous_integration_env?
|
23
|
-
ENV["CI"].present?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
RSpec.configure do |config|
|
28
|
-
config.include BehaviorDSL
|
29
36
|
end
|
30
|
-
|
37
|
+
end
|
data/lib/capybara/experience.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "capybara/
|
2
|
+
require "capybara/dsl"
|
3
|
+
require "capybara/experience/pool"
|
3
4
|
|
4
5
|
module Capybara
|
5
6
|
class Experience
|
6
7
|
include Capybara::DSL
|
7
|
-
include Rails.application.routes.url_helpers
|
8
|
-
include Warden::Test::Helpers
|
9
8
|
|
10
|
-
delegate :t, to: I18n
|
9
|
+
delegate :t, to: I18n if defined?(I18n)
|
11
10
|
|
12
11
|
def initialize(driver_name: nil)
|
13
12
|
@driver_name = driver_name
|
@@ -24,36 +23,35 @@ module Capybara
|
|
24
23
|
delegate :driver, to: :page
|
25
24
|
|
26
25
|
def page
|
27
|
-
@page ||= Experience::
|
26
|
+
@page ||= Experience::Pool.instance.take(driver: driver_name)
|
27
|
+
|
28
|
+
Capybara::Screenshot.final_session_name = @page.object_id if defined?(Capybara::Screenshot)
|
29
|
+
|
30
|
+
@page
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.wait_for_pending_requests
|
31
|
-
Experience::
|
34
|
+
Experience::Pool.taken.each do |session|
|
32
35
|
session.server.try(:wait_for_pending_requests)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
class Error < StandardError; end
|
40
|
+
|
41
|
+
module UnifySessionPool
|
42
|
+
def page
|
43
|
+
Capybara::Screenshot.final_session_name = Capybara.session_name if defined?(Capybara::Screenshot)
|
39
44
|
|
40
|
-
|
41
|
-
adapter = ShowMeTheCookies.adapters[driver_name]
|
42
|
-
if adapter.nil?
|
43
|
-
raise(ShowMeTheCookies::UnknownDriverError, "Unsupported driver #{driver_name}, use one of #{ShowMeTheCookies.adapters.keys} or register your new driver with ShowMeTheCookies.register_adapter")
|
45
|
+
super
|
44
46
|
end
|
45
|
-
adapter.new(page.driver)
|
46
|
-
end
|
47
47
|
|
48
|
-
|
49
|
-
xpath = element.path
|
50
|
-
execute_script <<~JS
|
51
|
-
document.evaluate('#{xpath}', document, null, XPathResult.ANY_TYPE, null)
|
52
|
-
.iterateNext()
|
53
|
-
.click()
|
54
|
-
JS
|
55
|
-
end
|
48
|
+
private
|
56
49
|
|
57
|
-
|
50
|
+
def session_pool
|
51
|
+
@session_pool ||= Experience::Pool.instance
|
52
|
+
end
|
53
|
+
end
|
58
54
|
end
|
55
|
+
|
56
|
+
singleton_class.prepend Experience::UnifySessionPool
|
59
57
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-experience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Ong
|
8
8
|
- Britt Lewis
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: capybara
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
56
70
|
description: Abstractions for Capybara to manage multiple user sessions, encapsulate
|
57
71
|
shared test behavior, and semantically contextualize test code.
|
58
72
|
email:
|
@@ -73,15 +87,15 @@ files:
|
|
73
87
|
- capybara-experience.gemspec
|
74
88
|
- lib/capybara-experience.rb
|
75
89
|
- lib/capybara/experience.rb
|
90
|
+
- lib/capybara/experience/pool.rb
|
76
91
|
- lib/capybara/experience/rspec.rb
|
77
|
-
- lib/capybara/experience/session.rb
|
78
92
|
- lib/capybara/experience/version.rb
|
79
93
|
homepage: https://github.com/ryanong/capybara-experience
|
80
94
|
licenses: []
|
81
95
|
metadata:
|
82
96
|
homepage_uri: https://github.com/ryanong/capybara-experience
|
83
97
|
source_code_uri: https://github.com/ryanong/capybara-experience
|
84
|
-
post_install_message:
|
98
|
+
post_install_message:
|
85
99
|
rdoc_options: []
|
86
100
|
require_paths:
|
87
101
|
- lib
|
@@ -96,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
110
|
- !ruby/object:Gem::Version
|
97
111
|
version: '0'
|
98
112
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
100
|
-
signing_key:
|
113
|
+
rubygems_version: 3.3.17
|
114
|
+
signing_key:
|
101
115
|
specification_version: 4
|
102
116
|
summary: Simplify Capybara testing for larger applications
|
103
117
|
test_files: []
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capybara
|
4
|
-
class Experience
|
5
|
-
module Session
|
6
|
-
class << self
|
7
|
-
def next(driver:)
|
8
|
-
pool.next(driver)
|
9
|
-
end
|
10
|
-
|
11
|
-
def create(driver)
|
12
|
-
::Capybara::Session.new(driver, Capybara.app)
|
13
|
-
end
|
14
|
-
|
15
|
-
def pool
|
16
|
-
@pool ||= Pool.new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Pool
|
21
|
-
attr_accessor :idle, :taken
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@idle = []
|
25
|
-
@taken = []
|
26
|
-
end
|
27
|
-
|
28
|
-
def next(driver)
|
29
|
-
take_idle(driver) || create(driver)
|
30
|
-
end
|
31
|
-
|
32
|
-
def release
|
33
|
-
taken.each(&:reset!)
|
34
|
-
idle.concat(taken)
|
35
|
-
taken.clear
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def take_idle(driver)
|
41
|
-
idle.find { |s| s.mode == driver }.tap do |session|
|
42
|
-
if session
|
43
|
-
idle.delete(session)
|
44
|
-
taken.push(session)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def create(driver)
|
50
|
-
::Capybara::Experience::Session.create(driver).tap do |session|
|
51
|
-
taken.push(session)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|