forked from youpy/mac-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac-robot_spec.rb
57 lines (50 loc) · 1.55 KB
/
mac-robot_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
# how to test???
describe Mac::Robot do
subject do
Mac::Robot.new
end
describe 'mouse event' do
it 'should simulate mouse event' do
subject.mouse_move(20, 0)
subject.mouse_press(:left)
subject.mouse_move(20, 250)
subject.mouse_release(:left)
end
end
describe 'scroll wheel event' do
it 'should simulate scroll wheel event' do
subject.scroll_wheel_line(:y => 10) # down 10 lines
subject.scroll_wheel(:y => -10) # up 10 lines
subject.scroll_wheel_pixel(:x => 10, :y => -20, :z => 5)
subject.scroll_wheel_pixel(:y => 20, :x => -10, :z => -5)
end
end
describe 'keyboard event' do
it 'should simulate keyboard event' do
[0x04, 0x0e, 0x25, 0x25, 0x1f].each do |keycode|
subject.key_press(keycode)
subject.key_release(keycode)
end
end
end
describe 'color' do
it 'should get color from given coordinate' do
color = subject.get_pixel_color(0, 0)
color.red.should be_a_kind_of(Float)
color.green.should be_a_kind_of(Float)
color.blue.should be_a_kind_of(Float)
color.alpha.should be_a_kind_of(Float)
end
it 'should raise if given coordinate is out of resolution' do
[9999, -1].each do |p|
lambda {
subject.get_pixel_color(p, 0)
}.should raise_error(Mac::Robot::OutOfResolution)
lambda {
subject.get_pixel_color(0, p)
}.should raise_error(Mac::Robot::OutOfResolution)
end
end
end
end