capybara-lockstep 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8335399770451283be7443be41f3f1e5c2b0401f16a64a7722fb6b39ec2f3143
4
- data.tar.gz: 601249c76c50789b44199e734a64fb039cd3b77c1db3e9f9068b1e7dea188216
3
+ metadata.gz: 86f6aba93856539de9e2df301e720cced0c444de2d62436e72ea620765f9b3e1
4
+ data.tar.gz: 1ae5dc301b4761d7c51796313ea4a6210596b5975e02f639410916ddc53060b5
5
5
  SHA512:
6
- metadata.gz: 638b0671d9f919c85b972cb2af4df763932a8c00ab21cd8387e3b483fda43448bb3c28b434aa821c0c6e75d4c67d82acb1dad0788128a5b1761bae0ae45400d6
7
- data.tar.gz: eed68edd632b78dea169e208162e4a041cfc1ed2a78c6593eebf55d27d2fe54d9161e1c65f21771cb66de2ef4e2e2ce92573569118e30e8a3148368ffaaafe53
6
+ metadata.gz: b1dc1f1e4a8af3d4d02f4d7b2aec3ae99844ba42bd3713028a138842bdc296c6bc0ed39688b8c15d7976830cc97df9ebc96cee3f3cfc9ab5f799e99ec59fee23
7
+ data.tar.gz: 50e27f5304cc7fbc1ed0c74ee87311ef8c8a333ecd4395af7cf155305ce0607f4b0f20defdf901d8f5cb3cbe8fc1ddb23638d9587c27f15e2071aea59c24297c
@@ -7,9 +7,13 @@ on:
7
7
  pull_request:
8
8
  branches:
9
9
  - master
10
+ workflow_dispatch:
11
+ branches:
12
+ - master
10
13
  jobs:
11
14
  test:
12
15
  runs-on: ubuntu-20.04
16
+ timeout-minutes: 3
13
17
  strategy:
14
18
  fail-fast: false
15
19
  matrix:
@@ -33,4 +37,8 @@ jobs:
33
37
  gem install bundler:2.2.15
34
38
  bundle install --no-deployment
35
39
  - name: Run tests
36
- run: bundle exec rake spec
40
+ uses: nick-invision/retry@v2
41
+ with:
42
+ timeout_seconds: 30
43
+ max_attempts: 3
44
+ command: bundle exec rake spec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capybara-lockstep (0.7.0)
4
+ capybara-lockstep (1.0.0)
5
5
  activesupport (>= 3.2)
6
6
  capybara (>= 2.0)
7
7
  ruby2_keywords
@@ -44,10 +44,8 @@ GEM
44
44
  rake
45
45
  jasmine-core (3.6.0)
46
46
  mini_mime (1.1.0)
47
- mini_portile2 (2.5.1)
48
47
  minitest (5.14.4)
49
- nokogiri (1.11.3)
50
- mini_portile2 (~> 2.5.0)
48
+ nokogiri (1.11.3-x86_64-linux)
51
49
  racc (~> 1.4)
52
50
  phantomjs (2.1.1.0)
53
51
  public_suffix (4.0.6)
data/README.md CHANGED
@@ -249,22 +249,6 @@ To enable logging in the browser console (but not STDOUT), include the snippet w
249
249
  capybara_lockstep(debug: true)
250
250
  ```
251
251
 
252
-
253
- ## Disabling synchronization
254
-
255
- Sometimes you want to disable browser synchronization, e.g. to observe a loading spinner during a long-running request.
256
-
257
- To disable synchronization:
258
-
259
- ```ruby
260
- begin
261
- Capybara::Lockstep.enabled = false
262
- do_unsynchronized_work
263
- ensure
264
- Capybara::Lockstep.enabled = true
265
- end
266
- ```
267
-
268
252
  ## Synchronization timeout
269
253
 
270
254
  By default capybara-lockstep will wait `Capybara.default_max_wait_time` seconds for the page initialize and for JavaScript and AJAX request to finish.
@@ -300,6 +284,32 @@ You may also synchronize from your client-side JavaScript. The following will ru
300
284
  CapybaraLockstep.synchronize(callback)
301
285
  ```
302
286
 
287
+
288
+ ## Disabling synchronization
289
+
290
+ Sometimes you want to disable browser synchronization, e.g. to observe a loading spinner during a long-running request.
291
+
292
+ To disable automatic synchronization:
293
+
294
+ ```ruby
295
+ begin
296
+ Capybara::Lockstep.mode = :manual
297
+ do_unsynchronized_work
298
+ ensure
299
+ Capybara::Lockstep.mode = :auto
300
+ end
301
+ ```
302
+
303
+ Note that you may still force synchronization by calling `Capybara::Lockstep.synchronize` manually.
304
+
305
+ To completely disable synchronization:
306
+
307
+ ```ruby
308
+ Capybara::Lockstep.mode = :off
309
+ Capybara::Lockstep.synchronize # will not synchronize
310
+ ```
311
+
312
+
303
313
  ## Signaling asynchronous work
304
314
 
305
315
  If for some reason you want capybara-lockstep to consider additional asynchronous work as "busy", you can do so:
@@ -55,8 +55,7 @@ module Capybara
55
55
  # we force a non-lazy synchronization so we pick up all client-side changes
56
56
  # that have not been caused by Capybara commands.
57
57
  script_may_navigate_away = script =~ /\b(location|history)\b/
58
- Lockstep.log "Synchronizing before script: #{script}"
59
- Lockstep.synchronize(lazy: !script_may_navigate_away)
58
+ Lockstep.auto_synchronize(lazy: !script_may_navigate_away, log: "Synchronizing before script: #{script}")
60
59
  end
61
60
 
62
61
  super(script, *args, &block).tap do
@@ -143,9 +142,10 @@ module Capybara
143
142
  module Lockstep
144
143
  module SynchronizeWithCatchUp
145
144
  ruby2_keywords def synchronize(*args, &block)
146
- # This method is called very frequently by capybara.
145
+ # This method is called by Capybara before most interactions with
146
+ # the browser. It is a different method than Capybara::Lockstep.synchronize!
147
147
  # We use the { lazy } option to only synchronize when we're out of sync.
148
- Capybara::Lockstep.synchronize(lazy: true)
148
+ Capybara::Lockstep.auto_synchronize(lazy: true)
149
149
 
150
150
  super(*args, &block)
151
151
  end
@@ -29,16 +29,30 @@ module Capybara
29
29
  @debug
30
30
  end
31
31
 
32
- def enabled?
32
+ def mode
33
33
  if javascript_driver?
34
- @enabled.nil? ? true : @enabled
34
+ @mode.nil? ? :auto : @mode
35
35
  else
36
- false
36
+ :off
37
37
  end
38
38
  end
39
39
 
40
+ def mode=(mode)
41
+ @mode = mode
42
+ end
43
+
40
44
  def enabled=(enabled)
41
- @enabled = enabled
45
+ case enabled
46
+ when true
47
+ log "Setting `Capybara::Lockstep.enabled = true` is deprecated. Set `Capybara::Lockstep.mode = :auto` instead."
48
+ self.mode = :auto
49
+ when false
50
+ log "Setting `Capybara::Lockstep.enabled = false` is deprecated. Set `Capybara::Lockstep.mode = :manual` or `Capybara::Lockstep.mode = :off` instead."
51
+ self.mode = :manual
52
+ when nil
53
+ # Reset to default
54
+ self.mode = nil
55
+ end
42
56
  end
43
57
 
44
58
  def wait_tasks
@@ -55,10 +69,6 @@ module Capybara
55
69
  @wait_tasks
56
70
  end
57
71
 
58
- def disabled?
59
- !enabled?
60
- end
61
-
62
72
  private
63
73
 
64
74
  def javascript_driver?
@@ -23,14 +23,26 @@ module Capybara
23
23
  page.instance_variable_set(:@lockstep_synchronized, value)
24
24
  end
25
25
 
26
- def synchronize(lazy: false)
27
- if (lazy && synchronized?) || synchronizing? || disabled?
26
+ def synchronize(lazy: false, log: nil)
27
+ if (lazy && synchronized?) || synchronizing? || mode == :off
28
28
  return
29
29
  end
30
30
 
31
+ # Allow passing a log message that is only logged
32
+ # when we're actually synchronizing.
33
+ if log
34
+ self.log(log)
35
+ end
36
+
31
37
  synchronize_now
32
38
  end
33
39
 
40
+ def auto_synchronize(**options)
41
+ if mode == :auto
42
+ synchronize(**options)
43
+ end
44
+ end
45
+
34
46
  private
35
47
 
36
48
  def synchronize_now
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Lockstep
3
- VERSION = "0.7.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-lockstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.0.3
119
+ rubygems_version: 3.2.6
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Synchronize Capybara commands with client-side JavaScript and AJAX requests