casper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/casper.rb CHANGED
@@ -13,17 +13,17 @@ module Casper
13
13
 
14
14
  # Press the given mouse button down (default is 1: primary)
15
15
  def down(button=1)
16
- Libxdo.xdo_mousedown xdo, Libxdo::CurrentWindow, button
16
+ xdo { |xdo| Libxdo.xdo_mousedown(xdo, Libxdo::CurrentWindow, button) }
17
17
  end
18
18
 
19
19
  # Release the given mouse button (default is 1: primary)
20
20
  def up(button=1)
21
- Libxdo.xdo_mouseup xdo, Libxdo::CurrentWindow, button
21
+ xdo { |xdo| Libxdo.xdo_mouseup(xdo, Libxdo::CurrentWindow, button) }
22
22
  end
23
23
 
24
24
  # Click the given mouse button (default is 1: primary)
25
25
  def click(button=1)
26
- Libxdo.xdo_click xdo, Libxdo::CurrentWindow, button
26
+ xdo { |xdo| Libxdo.xdo_click(xdo, Libxdo::CurrentWindow, button) }
27
27
  end
28
28
 
29
29
  # Gives the current mouse position
@@ -31,7 +31,7 @@ module Casper
31
31
  x = FFI::MemoryPointer.new :pointer
32
32
  y = FFI::MemoryPointer.new :pointer
33
33
  s = FFI::MemoryPointer.new :pointer
34
- Libxdo.xdo_mouselocation xdo, x, y, s
34
+ xdo { |xdo| Libxdo.xdo_mouselocation(xdo, x, y, s) }
35
35
  [ x.read_int, y.read_int ]
36
36
  end
37
37
 
@@ -69,7 +69,7 @@ module Casper
69
69
  # drag :distance => [ 20, 0 ] do
70
70
  # drag :distance => [ 0, 30 ]
71
71
  # end
72
- def drag(options={}, &block)
72
+ def drag(options={}, &block)
73
73
  raise ArgumentError.new(":to or :distance is required to provide ending location") unless options.has_key?(:to) || options.has_key?(:distance)
74
74
  raise ArgumentError.new(":increments must be > 0") if options.has_key?(:increments) && options[:increments] <= 0
75
75
 
@@ -90,25 +90,28 @@ module Casper
90
90
  private
91
91
 
92
92
  # Returns a new xdo instance
93
- def xdo
94
- Libxdo.xdo_new(nil)
93
+ def xdo(&block)
94
+ xdo = Libxdo.xdo_new(nil)
95
+ yield(xdo)
96
+ Libxdo.xdo_free(xdo)
95
97
  end
96
98
 
97
99
  # Performs an absolute mouse move
98
100
  def absolute(x, y)
99
- xdor = xdo
100
-
101
- Libxdo.xdo_mousemove(xdor, x, y, 0)
102
- Libxdo.xdo_mouse_wait_for_move_to(xdor, x, y)
101
+ xdo do |xdo|
102
+ Libxdo.xdo_mousemove(xdo, x, y, 0)
103
+ Libxdo.xdo_mouse_wait_for_move_to(xdo, x, y)
104
+ end
103
105
  end
104
106
 
105
107
  # Performs a relative mouse move
106
108
  def relative(x, y)
107
- xdor = xdo
108
- loc = location
109
+ loc = location
109
110
 
110
- Libxdo.xdo_mousemove_relative(xdor, x, y)
111
- Libxdo.xdo_mouse_wait_for_move_to(xdor, loc[0] + x, loc[1] + y)
111
+ xdo do |xdo|
112
+ Libxdo.xdo_mousemove_relative(xdo, x, y)
113
+ Libxdo.xdo_mouse_wait_for_move_to(xdo, loc[0] + x, loc[1] + y)
114
+ end
112
115
  end
113
116
  end
114
117
  end
data/test/casper_test.rb CHANGED
@@ -1,5 +1,4 @@
1
- require File.dirname(__FILE__) + "/lib/test_helper"
2
- require "casper"
1
+ require File.dirname(__FILE__) + "/test_helper"
3
2
 
4
3
  # Yeah, we use Capybara & Selenium & jQuery & Firefox and X11 and all sorts
5
4
  # of other stuff when we could just as easily mock out the xdo lib and
@@ -28,7 +28,7 @@ bash "install ruby 1.9.2" do
28
28
  rvm package install readline
29
29
  rvm install ruby-1.9.2 -C --with-readline-dir=$HOME/.rvm/usr
30
30
  BASH
31
- not_if { ::FileTest.exists?("/usr/local/rvm/rubies/ruby-1.9.2") }
31
+ not_if { ::FileTest.exists?("/usr/local/rvm/rubies/ruby-1.9.2") || ::FileTest.exists?("/usr/local/rvm/rubies/ruby-1.9.2-p0") }
32
32
  end
33
33
 
34
34
  bash "source rvm in bashrc" do
data/test/test_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- Dir[File.expand_path(File.dirname(__FILE__) + "/../..") + "/lib/"].each{ |lib| $:.unshift(lib) }
1
+ Dir[File.expand_path(File.dirname(__FILE__) + "/..") + "/lib/"].each{ |lib| $:.unshift(lib) }
2
2
 
3
3
  $:.unshift(File.dirname(__FILE__))
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Alavi
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-18 00:00:00 -07:00
19
+ date: 2010-09-27 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency