-
Notifications
You must be signed in to change notification settings - Fork 6
/
application_spec.rb
147 lines (121 loc) · 4.34 KB
/
application_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
include Autogui::Input
include Autogui::Logging
describe Autogui::Application do
describe "driving calc.exe" do
before(:all) do
@calculator = Calculator.new
@calculator.set_focus
end
after(:all) do
@calculator.close(:wait_for_close => true) if @calculator.running?
@calculator.should_not be_running
end
it "should start when initialized" do
@calculator.should be_running
end
it "should die when sending the kill signal" do
killme = Calculator.new
killme.should be_running
killme.kill
killme.should_not be_running
end
it "should have the title 'Calculator' that matches the main_window title" do
@calculator.main_window.title.should == 'Calculator'
@calculator.main_window.title.should == @calculator.title
end
it "should have an inspect method showing child window information" do
@calculator.inspect.should match(/children=</)
end
it "should raise an error if setting focus and the application title is incorrect" do
goodcalc = Calculator.new :title => "Calculator"
lambda { goodcalc.set_focus }.should_not raise_error
goodcalc.close
badcalc = Calculator.new :title => "BaDTitle"
lambda {
begin
badcalc.setfocus
ensure
badcalc.kill
end
}.should raise_error
end
it "should control the focus with 'set_focus'" do
@calculator.set_focus
keystroke(VK_9)
@calculator.edit_window.text.strip.should == "9."
calculator2 = Calculator.new
calculator2.pid.should_not == @calculator.pid
calculator2.set_focus
keystroke(VK_1, VK_0)
calculator2.edit_window.text.strip.should == "10."
@calculator.set_focus
@calculator.edit_window.text.strip.should == "9."
calculator2.close(:wait_for_close => true)
end
it "should open and close the 'About Calculator' dialog via (VK_MENU, VK_H, VK_A)" do
@calculator.set_focus
dialog_about = @calculator.dialog_about(:timeout => 0)
dialog_about.should be_nil
keystroke(VK_MENU, VK_H, VK_A)
dialog_about = @calculator.dialog_about
dialog_about.title.should == "About Calculator"
dialog_about.close
@calculator.dialog_about(:timeout => 0).should be_nil
end
describe "calculations" do
before(:each) do
@calculator.clear_entry
end
it "should calculate '2+2=4' using the keystroke method" do
@calculator.set_focus
keystroke(VK_2, VK_ADD, VK_2, VK_RETURN)
@calculator.edit_window.text.strip.should == "4."
end
it "should calculate '2+12=14' using the type_in method" do
@calculator.set_focus
type_in("2+12=")
@calculator.edit_window.text.strip.should == "14."
end
end
describe "clipboard" do
before(:each) do
@calculator.clear_entry
@calculator.clipboard.text = ""
@calculator.clipboard.text.should == ""
end
it "should not change the original text data" do
original_text = "the cow jumped over the moon"
copy_of_text = original_text.dup
copy_of_text.should == original_text
@calculator.clipboard.text = original_text
copy_of_text.should == original_text
@calculator.clipboard.text.should == original_text
original_text.should == "the cow jumped over the moon"
end
it "should memoize the clipboard object" do
clipboard = @calculator.clipboard
clipboard.should == @calculator.clipboard
end
describe "copy (VK_CONTROL, VK_C)" do
it "should copy the edit window" do
@calculator.set_focus
type_in("3002")
@calculator.edit_window.text.strip.should match(/3,?002\./)
@calculator.edit_window.set_focus
keystroke(VK_CONTROL, VK_C)
@calculator.clipboard.text.should == "3002"
end
end
describe "paste (VK_CONTROL, VK_V)" do
it "should paste into the edit window" do
@calculator.edit_window.set_focus
@calculator.clipboard.text = "12345"
@calculator.edit_window.text.strip.should == "0."
keystroke(VK_CONTROL, VK_V)
@calculator.edit_window.text.strip.should match(/12,?345\./)
end
end
end
end
end