caius-culerity 0.1.6 → 0.1.7

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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 6
4
+ :patch: 7
data/culerity.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{culerity}
5
- s.version = "0.1.6"
5
+ s.version = "0.1.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alexander Lang"]
@@ -8,7 +8,38 @@ module Culerity
8
8
  configure_browser browser_options
9
9
  @remote_object_id = nil
10
10
  end
11
-
11
+ end
12
+
13
+ #
14
+ # Calls the block until it returns true or +time_to_wait+ is reached.
15
+ # +time_to_wait+ is 30 seconds by default
16
+ #
17
+ # Returns true upon success
18
+ # Raises Timeout::Error when +time_to_wait+ is reached.
19
+ #
20
+ def wait_until time_to_wait=30, &block
21
+ Timeout.timeout(time_to_wait) do
22
+ until block.call
23
+ sleep 0.1
24
+ end
25
+ end
26
+ true
27
+ end
28
+
29
+ #
30
+ # Calls the block until it doesn't return true or +time_to_wait+ is reached.
31
+ # +time_to_wait+ is 30 seconds by default
32
+ #
33
+ # Returns true upon success
34
+ # Raises Timeout::Error when +time_to_wait+ is reached.
35
+ #
36
+ def wait_while time_to_wait=30, &block
37
+ Timeout.timeout(time_to_wait) do
38
+ while block.call
39
+ sleep 0.1
40
+ end
41
+ end
42
+ true
12
43
  end
13
44
 
14
45
  private
@@ -13,8 +13,10 @@ module Culerity
13
13
  @io = io
14
14
  end
15
15
 
16
+ #
16
17
  # Commonly used to get the HTML id attribute
17
18
  # Use `object_id` to get the local objects' id.
19
+ #
18
20
  def id
19
21
  send_remote(:id)
20
22
  end
@@ -23,6 +25,10 @@ module Culerity
23
25
  send_remote(name, *args)
24
26
  end
25
27
 
28
+ #
29
+ # Calls the passed method on the remote object with any arguments specified.
30
+ # Behaves the same as <code>Object#send</code>.
31
+ #
26
32
  def send_remote(name, *args)
27
33
  @io << "[#{remote_object_id}, \"#{name}\", #{args.map{|a| a.inspect}.join(', ')}]\n"
28
34
  process_result @io.gets.to_s.strip
@@ -20,4 +20,32 @@ describe Culerity::RemoteBrowserProxy do
20
20
  proxy = Culerity::RemoteBrowserProxy.new io, {:browser => :firefox}
21
21
  end
22
22
 
23
+ it "should timeout if wait_until takes too long" do
24
+ io = stub 'io', :gets => "[:return, :okay]", :<< => nil
25
+ proxy = Culerity::RemoteBrowserProxy.new io
26
+ lambda {
27
+ proxy.wait_until(1) { false }
28
+ }.should raise_error(Timeout::Error)
29
+ end
30
+
31
+ it "should return successfully when wait_until returns true" do
32
+ io = stub 'io', :gets => "[:return, :okay]", :<< => nil
33
+ proxy = Culerity::RemoteBrowserProxy.new io
34
+ proxy.wait_until(1) { true }.should == true
35
+ end
36
+
37
+ it "should timeout if wait_while takes too long" do
38
+ io = stub 'io', :gets => "[:return, :okay]", :<< => nil
39
+ proxy = Culerity::RemoteBrowserProxy.new io
40
+ lambda {
41
+ proxy.wait_while(1) { true }
42
+ }.should raise_error(Timeout::Error)
43
+ end
44
+
45
+ it "should return successfully when wait_while returns !true" do
46
+ io = stub 'io', :gets => "[:return, :okay]", :<< => nil
47
+ proxy = Culerity::RemoteBrowserProxy.new io
48
+ proxy.wait_while(1) { false }.should == true
49
+ end
50
+
23
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caius-culerity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang