capybara-experience 0.2 → 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: 66f9abbe2b8c449fd5757456f39cf7c376adbf1fb456ed462cb452adf4cb5aa6
4
- data.tar.gz: 4a8c6b7d01a40beaa5653a46693272239dfbb826f7403c8ff16549bf0a3ed6d3
3
+ metadata.gz: fa23c291ab266996334e99319fcfd89632d9aed1ebe672841f6a1fcbf9a1f4bf
4
+ data.tar.gz: 3ef627697145e07f4a780ae21b9ff85d1d2c57d824cdf93e15f7c921bd756779
5
5
  SHA512:
6
- metadata.gz: 3889ec278546633b65a980942773fec6c0f5517812328ed687eeff7056774ada49f3e9fe96f460b18df380c512eb30fdf171bbf87500358887887e6621efb8e4
7
- data.tar.gz: d950c605b5aa346db94b184a56d39f5c12b8f97c6f594a5a2fe2f3a8059fc2588bd7e970d090871b950ee8e06128aea9b341e24ff9de09d8bb260df8ba3c1ee4
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
@@ -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
@@ -29,6 +29,9 @@ module Capybara
29
29
 
30
30
  RSpec.configure do |config|
31
31
  config.include BehaviorDSL
32
+ config.prepend_after :each, type: :feature, js: true do
33
+ Capybara::Experience::Pool.instance.reset_idle!
34
+ end
32
35
  end
33
36
  end
34
37
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  class Experience
3
- VERSION = "0.2"
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "capybara/dsl"
3
- require "capybara/experience/session"
3
+ require "capybara/experience/pool"
4
4
 
5
5
  module Capybara
6
6
  class Experience
@@ -23,28 +23,35 @@ module Capybara
23
23
  delegate :driver, to: :page
24
24
 
25
25
  def page
26
- @page ||= Experience::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
27
31
  end
28
32
 
29
33
  def self.wait_for_pending_requests
30
- Experience::Session.pool.taken.each do |session|
34
+ Experience::Pool.taken.each do |session|
31
35
  session.server.try(:wait_for_pending_requests)
32
36
  end
33
37
  end
34
38
 
35
- def save_and_open_screenshot_full(path = nil, options = {})
36
- save_and_open_screenshot(path, options.merge(full: true))
37
- end
39
+ class Error < StandardError; end
38
40
 
39
- def click_with_js(element)
40
- xpath = element.path
41
- execute_script <<~JS
42
- document.evaluate('#{xpath}', document, null, XPathResult.ANY_TYPE, null)
43
- .iterateNext()
44
- .click()
45
- JS
46
- end
41
+ module UnifySessionPool
42
+ def page
43
+ Capybara::Screenshot.final_session_name = Capybara.session_name if defined?(Capybara::Screenshot)
47
44
 
48
- class Error < StandardError; end
45
+ super
46
+ end
47
+
48
+ private
49
+
50
+ def session_pool
51
+ @session_pool ||= Experience::Pool.instance
52
+ end
53
+ end
49
54
  end
55
+
56
+ singleton_class.prepend Experience::UnifySessionPool
50
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-experience
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Ong
@@ -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,8 +87,8 @@ 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: []
@@ -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