pagetience 0.2.1 → 0.3.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
  SHA1:
3
- metadata.gz: 2491b3175c6c081319a2770d23ba063bbf9496dc
4
- data.tar.gz: b0fa1d4c7e49dabda5d514ca3ae181bd2d9febca
3
+ metadata.gz: 05f8f8ddbf769b62605052f8378282c011a3cb71
4
+ data.tar.gz: 18c1edeecdc20fff221975e926019a21836fd454
5
5
  SHA512:
6
- metadata.gz: ea47b415838475065ab06d1d218ceb847127463b746dcfc831d896c43aa4013954a007d7aa03ca090ec5c1f3a64be4d98105066bce73453e4bdad97801bd2b94
7
- data.tar.gz: ea2e6d984b97bac32d28041d344682ee98ab05297f0d5456b1617a8e91fefb5edc5e9d241350269dc544157d4cea9869c8dcc56714c609c26aa59753c9cf3bb3
6
+ metadata.gz: 1c6933320f5286a4614ba5f54248495ed6f1135498b92f80bf5f633fa10b8c012a62096a634ce122c84d22805382d366dc61cc32167ce52c2110e1d13ae1babe
7
+ data.tar.gz: 8ceafa985213dc9416312bdb1f1b1c7491754a6141ea98d4869c1471a0fcbdddb80d5c94d95e19724e1abbf26071424cf0aa265b8a7741956fc5e47b51ce574a
@@ -1,24 +1,35 @@
1
1
  module Pagetience
2
2
  class Meditate
3
+ DEFAULT_TIMEOUT_MESSAGE = 'Timed out waiting for the expected result.'
4
+
3
5
  attr_accessor :timeout, :polling, :block
4
6
 
7
+ class << self
8
+ def for(opts, &block)
9
+ opts[:timeout] ||= 30
10
+ opts[:polling] ||= 1
11
+ opts[:msg] ||= DEFAULT_TIMEOUT_MESSAGE
12
+ Meditate.new(opts[:timeout], opts[:polling]) { block.call }.until_enlightened opts[:expecting], opts[:msg]
13
+ end
14
+ end
15
+
5
16
  def initialize(timeout=30, polling=1, &block)
6
17
  @timeout = timeout
7
18
  @polling = polling
8
19
  @block = block
9
20
  end
10
21
 
11
- def until_enlightened(expected=nil, msg='Timed out waiting for the expected result.')
22
+ def until_enlightened(expected=nil, msg=DEFAULT_TIMEOUT_MESSAGE)
12
23
  raise ArgumentError, 'Timeout cannot be lower than the polling value.' unless @timeout > @polling
13
24
 
14
25
  while @timeout > 0 && @timeout > @polling
15
26
  @latest_result = @block.call
16
- break unless expected && @latest_result != expected
27
+ break if @latest_result == expected
17
28
  sleep @polling
18
29
  @timeout = @timeout - @polling
19
30
  end
20
31
 
21
- raise Pagetience::Exceptions::Timeout, msg unless @latest_result
32
+ raise Pagetience::Exceptions::Timeout, msg unless @latest_result == expected
22
33
 
23
34
  @latest_result
24
35
  end
@@ -1,3 +1,3 @@
1
1
  module Pagetience
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/pagetience.rb CHANGED
@@ -80,6 +80,12 @@ module Pagetience
80
80
  end
81
81
  end
82
82
 
83
+ def transition_to(page, timeout=30, polling=1)
84
+ page = page.new browser
85
+ Pagetience::Meditate.for(timeout: timeout, polling: polling, msg: 'Timed out waiting for page transition.', expecting: true) { page.loaded? }
86
+ page
87
+ end
88
+
83
89
  private
84
90
 
85
91
  def determine_platform
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagetience
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek McNeil
@@ -184,3 +184,4 @@ signing_key:
184
184
  specification_version: 4
185
185
  summary: A simple gem for making page object waiting easy.
186
186
  test_files: []
187
+ has_rdoc: