sleipnir-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +41 -0
  4. data/README.txt +56 -0
  5. data/Rakefile +201 -0
  6. data/TODO.txt +11 -0
  7. data/examples/reload.rb +18 -0
  8. data/helper/helper.rb +3 -0
  9. data/helper/rake.rb +58 -0
  10. data/helper/rake_sh_filter.rb +23 -0
  11. data/helper/util.rb +19 -0
  12. data/lib/sleipnir_api.rb +177 -0
  13. data/lib/sleipnir_api/dialog.rb +155 -0
  14. data/lib/sleipnir_api/key_state.rb +49 -0
  15. data/lib/sleipnir_api/output.rb +319 -0
  16. data/lib/sleipnir_api/process.rb +69 -0
  17. data/lib/sleipnir_api/profile.rb +332 -0
  18. data/lib/sleipnir_api/registry.rb +30 -0
  19. data/lib/sleipnir_api/security.rb +263 -0
  20. data/lib/sleipnir_api/sleipnir.rb +489 -0
  21. data/lib/sleipnir_api/tab.rb +359 -0
  22. data/lib/sleipnir_api/util.rb +16 -0
  23. data/lib/sleipnir_api/version.rb +9 -0
  24. data/lib/sleipnir_api/win32api.rb +17 -0
  25. data/scripts/rdoc_filter.rb +74 -0
  26. data/setup.rb +1585 -0
  27. data/spec/matchers/path_eql.rb +41 -0
  28. data/spec/sleipnir_api/dialog_mock_spec.rb +99 -0
  29. data/spec/sleipnir_api/key_state_mock_spec.rb +72 -0
  30. data/spec/sleipnir_api/output_spec.rb +242 -0
  31. data/spec/sleipnir_api/profile_mock_spec.rb +128 -0
  32. data/spec/sleipnir_api/registry_spec.rb +13 -0
  33. data/spec/sleipnir_api/security_mock_spec.rb +82 -0
  34. data/spec/sleipnir_api/security_spec.rb +129 -0
  35. data/spec/sleipnir_api/sleipnir_mock_spec.rb +70 -0
  36. data/spec/sleipnir_api/sleipnir_spec.rb +295 -0
  37. data/spec/sleipnir_api/tab_mock_spec.rb +98 -0
  38. data/spec/sleipnir_api/tab_spec.rb +105 -0
  39. data/spec/sleipnir_api_spec.rb +17 -0
  40. data/spec/spec.opts +0 -0
  41. data/spec/spec_helper.rb +8 -0
  42. metadata +91 -0
@@ -0,0 +1,41 @@
1
+ require "pathname"
2
+
3
+ class String
4
+ def path_normalize
5
+ Pathname.new(self).cleanpath.to_s.downcase
6
+ end
7
+ end
8
+
9
+
10
+ module Spec
11
+ module Matchers
12
+
13
+ class PathEql #:nodoc:
14
+ def initialize(expected)
15
+ @expected = expected.path_normalize
16
+ end
17
+
18
+ def matches?(actual)
19
+ @actual = actual.path_normalize
20
+ @actual.eql?(@expected)
21
+ end
22
+
23
+ def failure_message
24
+ return "expected #{@expected.inspect}, got #{@actual.inspect} (using path_normalize -> .eql?)", @expected, @actual
25
+ end
26
+
27
+ def negative_failure_message
28
+ return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using path_normalize -> .eql?)", @expected, @actual
29
+ end
30
+
31
+ def description
32
+ "path_eql #{@expected.inspect}"
33
+ end
34
+ end
35
+
36
+ def path_eql(expected)
37
+ Matchers::PathEql.new(expected)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,99 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe SleipnirAPI::Dialog, "(Sleipnir)" do
4
+
5
+ before(:all) do
6
+ @pnir = SleipnirAPI.connect
7
+ @api = @pnir.instance_variable_get(:@api)
8
+ end
9
+
10
+ after(:all) do
11
+ @pnir.instance_variable_set(:@api, @api)
12
+ end
13
+
14
+ before do
15
+ @mock = mock("Sleipnir.API")
16
+ @pnir.instance_variable_set(:@api, @mock)
17
+ end
18
+
19
+
20
+ it "#message_box should send MessageBox" do
21
+ @mock.should_receive(:MessageBox).with("hello")
22
+ @pnir.message_box("hello")
23
+ end
24
+
25
+ it "#msgbox should send MsgBox" do
26
+ @mock.should_receive(:MsgBox).with("prompt", "title", 123)
27
+ @pnir.msgbox("prompt", "title", 123)
28
+ end
29
+
30
+
31
+ it "#input_box should send InputBox (ok)" do
32
+ @mock.should_receive(:InputBox).with("name", nil).and_return("matz")
33
+ @mock.should_receive(:Result).with(no_args()).and_return(1)
34
+ @pnir.input_box("name").should eql([:ok, "matz"])
35
+ end
36
+
37
+ it "#input_box(maksed => true) should send MaskedInputBox (ok)" do
38
+ @mock.should_receive(:MaskedInputBox).with("name", nil).and_return("matz")
39
+ @mock.should_receive(:Result).with(no_args()).and_return(1)
40
+ @pnir.input_box("name", :masked => true).should eql([:ok, "matz"])
41
+ end
42
+
43
+ it "#input_box should return nil when cancel" do
44
+ @mock.should_receive(:InputBox).with("your lang", nil).and_return(nil)
45
+ @mock.should_receive(:Result).with(no_args()).and_return(0)
46
+ @pnir.input_box("your lang").should eql([:cancel, nil])
47
+ end
48
+
49
+ it "#input_box(default => xxx) should return default value when cancel" do
50
+ @mock.should_receive(:InputBox).with("your lang", "ruby").and_return("ruby")
51
+ @mock.should_receive(:Result).with(no_args()).and_return(0)
52
+ @pnir.input_box("your lang", :default => "ruby").should eql([:cancel, "ruby"])
53
+ end
54
+
55
+ it "#input_box(mask => true, default => xxx)" do
56
+ @mock.should_receive(:MaskedInputBox).with("your lang", "ruby").and_return("perl")
57
+ @mock.should_receive(:Result).with(no_args()).and_return(1)
58
+ @pnir.input_box("your lang", :mask => true, :default => "ruby").should eql([:ok, "perl"])
59
+ end
60
+
61
+ end
62
+
63
+
64
+ describe SleipnirAPI::Dialog, "(Tab)" do
65
+
66
+ before(:all) do
67
+ @pnir = SleipnirAPI.connect
68
+ @blank = @pnir.new_tab
69
+ @api = @pnir.instance_variable_get(:@api)
70
+ end
71
+
72
+ after(:all) do
73
+ @pnir.instance_variable_set(:@api, @api)
74
+ @blank.close
75
+ end
76
+
77
+ before do
78
+ @mock = mock("Sleipnir.API")
79
+ @pnir.instance_variable_set(:@api, @mock)
80
+ end
81
+
82
+
83
+ it "#message_box should send MessageBox" do
84
+ @mock.should_receive(:MessageBox).with("hello")
85
+ @blank.message_box("hello")
86
+ end
87
+
88
+ it "#msgbox should send MsgBox" do
89
+ @mock.should_receive(:MsgBox).with("prompt", "title", 123)
90
+ @blank.msgbox("prompt", "title", 123)
91
+ end
92
+
93
+ it "#input_box should send InputBox (ok)" do
94
+ @mock.should_receive(:InputBox).with("name", nil).and_return("matz")
95
+ @mock.should_receive(:Result).with(no_args()).and_return(1)
96
+ @blank.input_box("name").should eql([:ok, "matz"])
97
+ end
98
+
99
+ end
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe SleipnirAPI::KeyState, "(Sleipnir)" do
4
+
5
+ before(:all) do
6
+ @pnir = SleipnirAPI.connect
7
+ @api = @pnir.instance_variable_get(:@api)
8
+ end
9
+
10
+ after(:all) do
11
+ @pnir.instance_variable_set(:@api, @api)
12
+ end
13
+
14
+ before do
15
+ @mock = mock("Sleipnir.API")
16
+ @pnir.instance_variable_set(:@api, @mock)
17
+ end
18
+
19
+
20
+ it "#alt_down? should send AltDown" do
21
+ @mock.should_receive(:AltDown).with(no_args())
22
+ @pnir.alt_down?
23
+ end
24
+
25
+ it "#shift_down? should send ShiftDown" do
26
+ @mock.should_receive(:ShiftDown).with(no_args())
27
+ @pnir.shift_down?
28
+ end
29
+
30
+ it "#ctrl_down? should send CtrlDown" do
31
+ @mock.should_receive(:CtrlDown).with(no_args())
32
+ @pnir.ctrl_down?
33
+ end
34
+
35
+ end
36
+
37
+
38
+ describe SleipnirAPI::KeyState, "(Tab)" do
39
+
40
+ before(:all) do
41
+ @pnir = SleipnirAPI.connect
42
+ @blank = @pnir.new_tab
43
+ @api = @pnir.instance_variable_get(:@api)
44
+ end
45
+
46
+ after(:all) do
47
+ @pnir.instance_variable_set(:@api, @api)
48
+ @blank.close
49
+ end
50
+
51
+ before do
52
+ @mock = mock("Sleipnir.API")
53
+ @pnir.instance_variable_set(:@api, @mock)
54
+ end
55
+
56
+
57
+ it "#alt_down? should send AltDown" do
58
+ @mock.should_receive(:AltDown).with(no_args())
59
+ @blank.alt_down?
60
+ end
61
+
62
+ it "#shift_down? should send ShiftDown" do
63
+ @mock.should_receive(:ShiftDown).with(no_args())
64
+ @blank.shift_down?
65
+ end
66
+
67
+ it "#ctrl_down? should send CtrlDown" do
68
+ @mock.should_receive(:CtrlDown).with(no_args())
69
+ @blank.ctrl_down?
70
+ end
71
+
72
+ end
@@ -0,0 +1,242 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe SleipnirAPI::Output do
4
+
5
+ before(:all) do
6
+ @pnir = SleipnirAPI.connect
7
+ @output = @pnir.output
8
+ @output.hide
9
+ @output.clear
10
+ end
11
+
12
+ after do
13
+ @output.hide
14
+ @output.clear
15
+ end
16
+
17
+
18
+ it "#visible[?=], #hide, #show" do
19
+ @output.visible?.should be_false
20
+
21
+ @output.visible = true
22
+ @output.visible?.should be_true
23
+
24
+ @output.hide
25
+ @output.visible?.should be_false
26
+
27
+ @output.show
28
+ @output.visible?.should be_true
29
+ end
30
+
31
+ it "#cursor[=] should set/get cursor line number" do
32
+ @output.cursor.should == -1
33
+
34
+ @output.cursor = 0
35
+ @output.cursor.should == -1
36
+
37
+ @output.cursor = 100
38
+ @output.cursor.should == -1
39
+
40
+ @output << "a"
41
+ @output << "b"
42
+ @output.cursor = 0
43
+ @output.cursor.should == 0
44
+
45
+ @output.cursor = 100
46
+ @output.cursor.should == -1
47
+ end
48
+
49
+ it "#script[=] should set/get script filename" do
50
+ saved = @output.script
51
+ begin
52
+ @output.script = "foobar"
53
+ @output.script.should == "foobar"
54
+ @output.script = "barbaz"
55
+ @output.script.should == "barbaz"
56
+ ensure
57
+ @output.script = saved
58
+ end
59
+ end
60
+
61
+ it "#count should return # of outputs" do
62
+ @output.count.should == 0
63
+ @output << "A"
64
+ @output << "b"
65
+ @output.count.should == 2
66
+ end
67
+
68
+ it "#add should insert string to last" do
69
+ @output.cursor.should == -1
70
+ @output.add "A"
71
+ @output.add "b"
72
+ @output.add "d"
73
+
74
+ @output.cursor.should == 2
75
+ @output.getlines.should == ["A", "b", "d"]
76
+
77
+ @output << "e"
78
+ @output << "f"
79
+
80
+ @output.cursor.should == 4
81
+ @output.getlines.should == ["A", "b", "d", "e", "f"]
82
+ end
83
+
84
+ it "#concat should insert multiple string to last" do
85
+ @output.concat(%W(a b c d))
86
+ @output.concat("e", ["f"], ["g", "h"])
87
+ @output.getlines.should == %W(a b c d e f g h)
88
+
89
+ @output.concat("i", "j", "k")
90
+ @output.getlines.should == %W(a b c d e f g h i j k)
91
+ end
92
+
93
+
94
+ it "#insert_before should insert string to current cursor" do
95
+ @output.add "a"
96
+ @output.add "b"
97
+ @output.add "c"
98
+
99
+ @output.cursor = 1
100
+
101
+ @output.insert_before "e"
102
+ @output.get.should == "b"
103
+
104
+ @output.insert_before "f"
105
+ @output.get.should == "b"
106
+
107
+ @output.getlines.should == ["a", "e", "f", "b", "c"]
108
+ end
109
+
110
+ it "#insert_after should insert string to current cursor" do
111
+ @output.add "a"
112
+ @output.add "b"
113
+ @output.add "c"
114
+
115
+ @output.cursor = 1
116
+
117
+ @output.insert_after "e"
118
+ @output.get.should == "b"
119
+
120
+ @output.insert_after "f"
121
+ @output.get.should == "b"
122
+
123
+ @output.getlines.should == ["a", "b", "f", "e", "c"]
124
+ end
125
+
126
+ it "#insert should insert string to specified lineno" do
127
+ @output.add "a"
128
+ @output.add "b"
129
+ @output.add "c"
130
+
131
+ @output.insert(1, "e")
132
+ @output.cursor.should == 1
133
+
134
+ @output.insert(3, "f")
135
+ @output.cursor.should == 3
136
+
137
+ @output.insert(5, "g")
138
+ @output.cursor.should == 5
139
+
140
+ @output.insert(500, "h")
141
+ @output.cursor.should == -1
142
+
143
+ @output.getlines.should == ["a", "e", "b", "f", "c", "g"]
144
+ end
145
+
146
+ it "#clear should clear output buffer" do
147
+ @output.add "a"
148
+ @output.add "b"
149
+ @output.clear
150
+ @output.count.should == 0
151
+ end
152
+
153
+ it "#get should return nil if index is out of range" do
154
+ @output.get.should be_nil
155
+ @output.get(-1).should be_nil
156
+ @output.get(1000).should be_nil
157
+ end
158
+
159
+ it "#getlines should return all lines" do
160
+ @output.getlines.should == []
161
+ @output.add "a"
162
+ @output.add "b"
163
+ @output.getlines.should == ["a", "b"]
164
+ end
165
+ end
166
+
167
+
168
+ describe SleipnirAPI::Output, "(with outputs)" do
169
+
170
+ before(:all) do
171
+ @pnir = SleipnirAPI.connect
172
+ @output = @pnir.output
173
+ end
174
+
175
+ after(:all) do
176
+ @output.clear
177
+ @output.hide
178
+ end
179
+
180
+ before do
181
+ @output.clear
182
+ @output.show
183
+ @arr = %W(a b c d e f g)
184
+ @arr.each {|e| @output << e }
185
+ end
186
+
187
+ it "#each should enumerate all outputs." do
188
+ outputs = []
189
+ cursors = []
190
+
191
+ @output.each {|e| outputs << e; cursors << @output.cursor }
192
+
193
+ @output.getlines.should == outputs
194
+ cursors.should == [0, 1, 2, 3, 4, 5, 6]
195
+ end
196
+
197
+ it "#each with delete works properly." do
198
+ @output.each {|e| @output.delete(0) }
199
+ @arr.each{|e| @arr.delete_at(0) }
200
+
201
+ @output.getlines.should == @arr
202
+ end
203
+
204
+ it "#each with delete works properly." do
205
+ @output.each {|e| @output.delete }
206
+ @arr.each{|e| @arr.delete(e) }
207
+
208
+ @output.getlines.should == @arr
209
+ end
210
+
211
+ it "#delete should delete specified index" do
212
+ @output.delete(0)
213
+ @output.delete(0)
214
+ @output.getlines.should == %W(c d e f g)
215
+ end
216
+
217
+ it "#delete should delete specified indices" do
218
+ @output.delete(1, 3, 5)
219
+ @output.getlines.should == %W(a c e g)
220
+ end
221
+
222
+ it "#delete should delete specified indices" do
223
+ @output.delete([0, 2, 4, 6])
224
+ @output.getlines.should == %W(b d f)
225
+ end
226
+
227
+ it "#delete should delete specified range" do
228
+ @output.delete(0...7)
229
+ @output.getlines.should == []
230
+ end
231
+
232
+ it "#delete should delete specified range" do
233
+ @output.delete(0...2, 4..5)
234
+ @output.getlines.should == %W(c d g)
235
+ end
236
+
237
+ it "#delete should delete specified indices/range" do
238
+ @output.delete(0, 4...6, [1, 2], 3)
239
+ @output.getlines.should == %W(g)
240
+ end
241
+
242
+ end