pouch 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pouch.rb CHANGED
@@ -21,7 +21,7 @@ module Pouch
21
21
 
22
22
  @browser = browser
23
23
  @context = standardize opts[:context] if opts[:context]
24
- @timeout = opts[:timeout] || 10
24
+ @timeout = opts[:timeout] || 5
25
25
 
26
26
  set_timer if self.respond_to? :set_timer
27
27
  visit if self.respond_to?(:visit) && start
@@ -2,10 +2,10 @@ module Pouch
2
2
  module Elements
3
3
 
4
4
  def element tag, name, identifier, *args, &block
5
- define_method name do
6
- timer { browser.element(tag, identifier).visible? }
5
+ define_method name, ->(time = nil) do
6
+ timer(time){ browser.element(tag, identifier).visible? }
7
7
  return browser.element tag, identifier unless block_given?
8
- block.call browser.send(:element, tag, identifier), *args
8
+ block.call browser.send(:element, tag, identifier), *args
9
9
  end
10
10
 
11
11
  define_waiting_methods tag, name, identifier, *args, &block
@@ -121,23 +121,23 @@ module Pouch
121
121
  private
122
122
 
123
123
  def define_waiting_methods tag, name, identifier, *args, &block
124
- define_method "when_#{name}_not_visible" do
125
- result = negative_timer { !browser.element(tag, identifier).visible? }
124
+ define_method "when_#{name}_not_visible", ->(time = nil) do
125
+ result = negative_timer(time){ !browser.element(tag, identifier).visible? }
126
126
  unless result
127
127
  raise VisibilityError, "#{name} element is still visible"
128
128
  end
129
129
  self
130
130
  end
131
131
 
132
- define_method "when_#{name}_present" do
133
- timer { browser.element(tag, identifier).present? }
132
+ define_method "when_#{name}_present", ->(time = nil) do
133
+ timer(time){ browser.element(tag, identifier).present? }
134
134
  html_element = browser.element tag, identifier
135
135
  return located_element unless block_given?
136
136
  block.call located_element, *args
137
137
  end
138
138
 
139
- define_method "when_#{name}_not_present" do
140
- result = negative_timer { !browser.element(tag, identifier).present? }
139
+ define_method "when_#{name}_not_present", ->(time = nil) do
140
+ result = negative_timer(time){ !browser.element(tag, identifier).present? }
141
141
  unless result
142
142
  raise PresenceError, "#{name} element is still present"
143
143
  end
@@ -145,7 +145,8 @@ module Pouch
145
145
  end
146
146
  end
147
147
 
148
- def timer &block
148
+ def timer n, &block
149
+ interval = n.nil? ? timeout : n
149
150
  timed_out = Time.now + timeout
150
151
  until Time.now > timed_out
151
152
  result = yield block rescue false
@@ -153,8 +154,9 @@ module Pouch
153
154
  end
154
155
  end
155
156
 
156
- def negative_timer &block
157
- timed_out = Time.now + timeout
157
+ def negative_timer n, &block
158
+ interval = n.nil? ? timeout : n
159
+ timed_out = Time.now + interval
158
160
  until Time.now > timed_out
159
161
  result = yield block rescue false
160
162
  return result if result
data/lib/pouch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pouch
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -28,11 +28,16 @@ describe Pouch::Elements do
28
28
  expect(page.blocked).to eq "www.test.com"
29
29
  end
30
30
 
31
- it "calls #timer to wait for visible element" do
31
+ it "calls #timer to wait for default interval" do
32
32
  expect(page).to receive(:timer)
33
33
  page.generic
34
34
  end
35
35
 
36
+ it "calls #timer with custom interval" do
37
+ expect(page).to receive(:timer).with(20)
38
+ page.generic 20
39
+ end
40
+
36
41
  it "generates #when_generic_not_visible" do
37
42
  expect(page).to respond_to :when_generic_not_visible
38
43
  end
@@ -81,6 +86,11 @@ describe Pouch::Elements do
81
86
  expect(page).to receive(:negative_timer).and_return(false)
82
87
  expect{ page.when_invisible_not_visible }.to raise_error Pouch::VisibilityError, /invisible element/
83
88
  end
89
+
90
+ it "accepts an optional interval for timeout" do
91
+ expect(page).to receive(:negative_timer).with(20).and_return(true)
92
+ page.when_invisible_not_visible 20
93
+ end
84
94
  end
85
95
 
86
96
  describe "#when_element_not_present" do
@@ -97,6 +107,11 @@ describe Pouch::Elements do
97
107
  expect(page).to receive(:negative_timer).and_return(false)
98
108
  expect{ page.when_gone_not_present }.to raise_error Pouch::PresenceError, /gone element/
99
109
  end
110
+
111
+ it "accepts an optional interval for timeout" do
112
+ expect(page).to receive(:negative_timer).with(20).and_return(true)
113
+ page.when_gone_not_present 20
114
+ end
100
115
  end
101
116
 
102
117
  describe "#button" do
data/spec/pouch_spec.rb CHANGED
@@ -21,13 +21,13 @@ describe Pouch do
21
21
 
22
22
  it "creates @timeout variable" do
23
23
  obj = Page2.new 'webdriver'
24
- expect(obj.instance_variable_get :@timeout).to eq 10
24
+ expect(obj.instance_variable_get :@timeout).to eq 5
25
25
  end
26
26
 
27
27
  context "with :timeout option" do
28
28
  it "creates @timeout variable" do
29
- obj = Page2.new 'webdriver', timeout: 5
30
- expect(obj.instance_variable_get :@timeout).to eq 5
29
+ obj = Page2.new 'webdriver', timeout: 10
30
+ expect(obj.instance_variable_get :@timeout).to eq 10
31
31
  end
32
32
  end
33
33
 
@@ -125,14 +125,14 @@ describe Pouch do
125
125
  context "without setting a custom timeout interval" do
126
126
  it "returns the page object default timeout" do
127
127
  obj = Page.new 'webdriver'
128
- expect(obj.timeout).to eq 10
128
+ expect(obj.timeout).to eq 5
129
129
  end
130
130
  end
131
131
 
132
132
  context "after passing :timeout option to #initialize" do
133
133
  it "returns the custom timeout" do
134
- obj = Page.new 'webdriver', timeout: 5
135
- expect(obj.timeout).to eq 5
134
+ obj = Page.new 'webdriver', timeout: 10
135
+ expect(obj.timeout).to eq 10
136
136
  end
137
137
  end
138
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pouch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: