capybara-experience 0.1.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 481ac53f31988f2b33cf5fe8cf21f1e5a283ad0e33500b727384c66ac68ec18c
4
- data.tar.gz: 58e8aa2c7002f148b85817b744a518f71b97e5f923cff42161e738487a000be3
3
+ metadata.gz: fa23c291ab266996334e99319fcfd89632d9aed1ebe672841f6a1fcbf9a1f4bf
4
+ data.tar.gz: 3ef627697145e07f4a780ae21b9ff85d1d2c57d824cdf93e15f7c921bd756779
5
5
  SHA512:
6
- metadata.gz: 2c6b11b8f1306cd98fa93f10ab444b440466cc53a3341abb16581af2cbdfcbe86c8172d41c5854e50e581408ee7978f69998dfa45401dea3fe575063083af61d
7
- data.tar.gz: 726c207dc4b809cb05da765029f6027eb876b6f16ef5c4e3163a3e2d0a0e24de6ac9af0dc2968b65b49b2bd4d1e9e339410b7bbdcdf9c99c69bbd0ca0b4a4c78
6
+ metadata.gz: 2b10d6314a8a1d958b3d9e195abca3084cde7daeb8c48010765ee052f3d52191eb9166bee74f4d419bd1a4f21eb34fb6b2a82da1a1a35c55ff9dcd1ff1fc0ac8
7
+ data.tar.gz: dacf0ca724bae746890fd5c9a7a3a4a2e3503500644878c05b8965af00b34c9e062ade9f8379ea83cfc2fe17c557c5822c6acc6ff5af6d945e4ca3b3e8b0bca6
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
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 = GuestExpereince.new
103
+ guest_ux = GuestExperience.new
102
104
  guest_ux.navigate_to_sign_up
103
105
 
104
106
  guest_ux.sign_up(
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler", "~> 2.0"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
+
32
+ spec.add_runtime_dependency "capybara", "~> 3.0"
31
33
  end
@@ -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
- module BehaviorDSL
3
- def behavior(name, &block)
4
- metadata[:description_args].push(name)
5
- refresh_description unless in_continuous_integration_env?
6
- yield
7
- metadata[:description_args].pop
8
- refresh_description unless in_continuous_integration_env?
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
- private
12
-
13
- def refresh_description
14
- metadata[:description] = metadata[:description_args].join(" ")
15
- metadata[:full_description] = [metadata[:example_group][:full_description]].concat(metadata[:description_args]).join(" ")
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
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  class Experience
3
- VERSION = "0.1.1"
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
- require "capybara/experience/version"
3
- require "capybara/experience/session"
2
+ require "capybara/dsl"
3
+ require "capybara/experience/pool"
4
4
 
5
5
  module Capybara
6
6
  class Experience
7
7
  include Capybara::DSL
8
- include Rails.application.routes.url_helpers
9
- include Warden::Test::Helpers
10
8
 
11
- delegate :t, to: I18n
9
+ delegate :t, to: I18n if defined?(I18n)
12
10
 
13
11
  def initialize(driver_name: nil)
14
12
  @driver_name = driver_name
@@ -25,36 +23,35 @@ module Capybara
25
23
  delegate :driver, to: :page
26
24
 
27
25
  def page
28
- @page ||= Experiences::Session.next(driver: driver_name)
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
29
31
  end
30
32
 
31
33
  def self.wait_for_pending_requests
32
- Experiences::Session.pool.taken.each do |session|
34
+ Experience::Pool.taken.each do |session|
33
35
  session.server.try(:wait_for_pending_requests)
34
36
  end
35
37
  end
36
38
 
37
- def save_and_open_screenshot_full(path = nil, options = {})
38
- save_and_open_screenshot(path, options.merge(full: true))
39
- end
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)
40
44
 
41
- def current_driver_adapter
42
- adapter = ShowMeTheCookies.adapters[driver_name]
43
- if adapter.nil?
44
- raise(ShowMeTheCookies::UnknownDriverError, "Unsupported driver #{driver_name}, use one of #{ShowMeTheCookies.adapters.keys} or register your new driver with ShowMeTheCookies.register_adapter")
45
+ super
45
46
  end
46
- adapter.new(page.driver)
47
- end
48
47
 
49
- def click_with_js(element)
50
- xpath = element.path
51
- execute_script <<~JS
52
- document.evaluate('#{xpath}', document, null, XPathResult.ANY_TYPE, null)
53
- .iterateNext()
54
- .click()
55
- JS
56
- end
48
+ private
57
49
 
58
- class Error < StandardError; end
50
+ def session_pool
51
+ @session_pool ||= Experience::Pool.instance
52
+ end
53
+ end
59
54
  end
55
+
56
+ singleton_class.prepend Experience::UnifySessionPool
60
57
  end
@@ -0,0 +1 @@
1
+ require "capybara/experience"
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.1
4
+ version: '0.3'
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: 2020-04-20 00:00:00.000000000 Z
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:
@@ -71,16 +85,17 @@ files:
71
85
  - bin/console
72
86
  - bin/setup
73
87
  - capybara-experience.gemspec
88
+ - lib/capybara-experience.rb
74
89
  - lib/capybara/experience.rb
90
+ - lib/capybara/experience/pool.rb
75
91
  - lib/capybara/experience/rspec.rb
76
- - lib/capybara/experience/session.rb
77
92
  - lib/capybara/experience/version.rb
78
93
  homepage: https://github.com/ryanong/capybara-experience
79
94
  licenses: []
80
95
  metadata:
81
96
  homepage_uri: https://github.com/ryanong/capybara-experience
82
97
  source_code_uri: https://github.com/ryanong/capybara-experience
83
- post_install_message:
98
+ post_install_message:
84
99
  rdoc_options: []
85
100
  require_paths:
86
101
  - lib
@@ -95,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
110
  - !ruby/object:Gem::Version
96
111
  version: '0'
97
112
  requirements: []
98
- rubygems_version: 3.1.2
99
- signing_key:
113
+ rubygems_version: 3.3.17
114
+ signing_key:
100
115
  specification_version: 4
101
116
  summary: Simplify Capybara testing for larger applications
102
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