osaka 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,37 @@ describe "Osaka::ApplicationWrapper" do
7
7
  quoted_name = "\"#{name}\""
8
8
  subject { Osaka::ApplicationWrapper.new(name) }
9
9
 
10
+ before (:each) do
11
+ Osaka::ScriptRunner.enable_debug_prints
12
+ end
13
+
14
+ after (:each) do
15
+ Osaka::ScriptRunner.disable_debug_prints
16
+ end
17
+
18
+ it "Should be able to clone wrappers" do
19
+ subject.set_current_window "Window"
20
+ new_wrapper = subject.clone
21
+ new_wrapper.should == subject
22
+ new_wrapper.should_not.equal?(subject)
23
+ end
24
+
25
+ it "Should be able to compare objects using names" do
26
+ subject.should == Osaka::ApplicationWrapper.new(name)
27
+ subject.should_not == Osaka::ApplicationWrapper.new("otherName")
28
+ end
29
+
30
+ it "Should be able to compare objects using window" do
31
+ equal_object = Osaka::ApplicationWrapper.new(name)
32
+ unequal_object = Osaka::ApplicationWrapper.new(name)
33
+ equal_object.set_current_window("Window")
34
+ subject.set_current_window("Window")
35
+ unequal_object.set_current_window "Another Window"
36
+
37
+ subject.should == equal_object
38
+ subject.should_not == unequal_object
39
+ end
40
+
10
41
  def check_for_warning(action)
11
42
  Osaka::ScriptRunner.should_receive(:execute).and_return("Blah")
12
43
  subject.should_receive(:print_warning).with(action, "Blah")
@@ -42,6 +73,11 @@ describe "Osaka::ApplicationWrapper" do
42
73
  subject.system_event!("quit")
43
74
  end
44
75
 
76
+ it "Should be possible to check whether an application is still running" do
77
+ Osaka::ScriptRunner.should_receive(:execute).with("tell application \"System Events\"; (name of processes) contains \"#{name}\"; end tell").and_return("false")
78
+ subject.running?.should == false
79
+ end
80
+
45
81
  it "Should be able to generate events via the Systems Events and activate the application first" do
46
82
  subject.should_receive(:activate)
47
83
  subject.should_receive(:system_event!).with("quit")
@@ -50,7 +86,7 @@ describe "Osaka::ApplicationWrapper" do
50
86
 
51
87
  it "Should be able to check whether a specific element exists" do
52
88
  Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true\n")
53
- subject.check.exists("window 1").should == true
89
+ subject.check.exists(at.window(1)).should == true
54
90
  end
55
91
 
56
92
  it "Should be able to wait for for a specific element existing" do
@@ -59,18 +95,18 @@ describe "Osaka::ApplicationWrapper" do
59
95
  counter = counter + 1
60
96
  (counter == 5).to_s
61
97
  }
62
- subject.wait_until!.exists("window 1")
98
+ subject.wait_until!.exists(at.window(1))
63
99
  end
64
100
 
65
101
  it "Should be able to wait until exists and activate the application first" do
66
102
  subject.should_receive(:activate)
67
103
  Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
68
- subject.wait_until.exists("window 1")
104
+ subject.wait_until.exists(at.window(1))
69
105
  end
70
106
 
71
107
  it "Should be able to wait for a specific element to not exist anymore" do
72
108
  Osaka::ScriptRunner.should_receive(:execute).with(/not exists window 1/).and_return("true")
73
- subject.wait_until!.not_exists("window 1")
109
+ subject.wait_until!.not_exists(at.window(1))
74
110
  end
75
111
 
76
112
  it "Should be able to generate keystroke events" do
@@ -103,7 +139,7 @@ describe "Osaka::ApplicationWrapper" do
103
139
  it "Should be able to do a keystroke and wait until something happen in one easy line" do
104
140
  Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
105
141
  Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
106
- subject.keystroke!("p", []).wait_until!.exists("window 1")
142
+ subject.keystroke!("p", []).wait_until!.exists(at.window(1))
107
143
  end
108
144
 
109
145
  it "Should be able to keystroke_and_wait_until_exists and activate" do
@@ -111,12 +147,12 @@ describe "Osaka::ApplicationWrapper" do
111
147
  subject.should_receive(:focus)
112
148
  Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
113
149
  Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
114
- subject.keystroke("p", []).wait_until!.exists("window 1")
150
+ subject.keystroke("p", []).wait_until!.exists(at.window(1))
115
151
  end
116
152
 
117
153
  it "Should be able to do clicks" do
118
154
  Osaka::ScriptRunner.should_receive(:execute).with(/click menu button "PDF"/).and_return("")
119
- subject.click!('menu button "PDF"')
155
+ subject.click!(at.menu_button("PDF"))
120
156
  end
121
157
 
122
158
  it "Should be able to do click and activate" do
@@ -124,55 +160,56 @@ describe "Osaka::ApplicationWrapper" do
124
160
  subject.should_receive(:click!).with("button")
125
161
  subject.click("button")
126
162
  end
127
-
163
+
128
164
  it "Should be able to do clicks and wait until something happened in one easy line" do
129
165
  Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
130
- Osaka::ScriptRunner.should_receive(:execute).with(/exists window/).and_return("true")
131
- subject.click!("button").wait_until!.exists("window")
166
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
167
+ subject.click!("button").wait_until!.exists(at.window(1))
132
168
  end
133
169
 
134
170
  it "Should be able to click_and_wait_until_exists and activate" do
135
171
  subject.should_receive(:activate)
136
172
  Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
137
- Osaka::ScriptRunner.should_receive(:execute).with(/exists window/).and_return("true")
138
- subject.click("button").wait_until!.exists("window")
173
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
174
+ subject.click("button").wait_until!.exists(at.window(1))
175
+ end
176
+
177
+ it "Should be able to click on menu bar items" do
178
+ subject.should_receive("activate")
179
+ subject.should_receive("click!").with(at.menu_item("Hey").menu(1).menu_bar_item("File").menu_bar(1))
180
+ subject.click_menu_bar(at.menu_item("Hey"), "File")
139
181
  end
140
182
 
141
183
  it "Should be able to set a value to an element" do
142
- subject.should_receive(:system_event!).with(/set value of window to "newvalue"/).and_return("")
143
- subject.set!("value", "window", "newvalue")
184
+ subject.should_receive(:system_event!).with(/set value of window 1 to "newvalue"/).and_return("")
185
+ subject.set!("value", at.window(1), "newvalue")
144
186
  end
145
187
 
146
188
  it "Prints a warning when setting and element and output is received" do
147
189
  check_for_warning("set")
148
- subject.set!("value", "window", "newvalue")
190
+ subject.set!("value", at.window(1), "newvalue")
149
191
  end
150
192
 
151
193
  it "Should be able to set to boolean values" do
152
- subject.should_receive(:system_event!).with(/set value of window to true/).and_return("")
153
- subject.set!("value", "window", true)
194
+ subject.should_receive(:system_event!).with(/set value of window 1 to true/).and_return("")
195
+ subject.set!("value", at.window(1), true)
154
196
  end
155
197
 
156
198
  it "Should be able to get a value from an element" do
157
- subject.should_receive(:system_event!).with(/get value of window/).and_return("1\n")
158
- subject.get!("value", "window").should == "1"
199
+ subject.should_receive(:system_event!).with(/get value of window 1/).and_return("1\n")
200
+ subject.get!("value", at.window(1)).should == "1"
159
201
  end
160
202
 
161
203
  it "Should use the locally stored window when that one is set." do
162
- subject.window = "1"
204
+ subject.set_current_window("1")
163
205
  subject.should_receive(:system_event!).with(/get value of window \"1\"/).and_return("1\n")
164
206
  subject.get!("value").should == "1"
165
207
  end
166
-
167
- it "Should throw an exception when window is set multiple times." do
168
- subject.window = "Untitled"
169
- lambda {subject.get!("value", "window 1")}.should raise_error(Osaka::InvalidLocation, "Invalid location for command: of window 1 of window \"Untitled\"")
170
- end
171
-
208
+
172
209
  it "Should combine the location and the window" do
173
- subject.window = "1"
210
+ subject.set_current_window("1")
174
211
  subject.should_receive(:system_event!).with(/get value of dialog 2 of window "1"/).and_return("1\n")
175
- subject.get!("value", "dialog 2").should == "1"
212
+ subject.get!("value", at.dialog(2)).should == "1"
176
213
  end
177
214
 
178
215
  it "Should be able to get values from the application itself" do
@@ -182,13 +219,13 @@ describe "Osaka::ApplicationWrapper" do
182
219
 
183
220
  it "Should be able to set a value and activate" do
184
221
  subject.should_receive(:activate)
185
- subject.should_receive(:set!).with("value", "window", "newvalue")
186
- subject.set("value", "window", "newvalue")
222
+ subject.should_receive(:set!).with("value", at.window(1), "newvalue")
223
+ subject.set("value", at.window(1), "newvalue")
187
224
  end
188
225
 
189
226
  it "Should be able to loop over some script until something happens" do
190
227
  counter = 0
191
- Osaka::ScriptRunner.should_receive(:execute).exactly(3).times.with(/exists window/).and_return {
228
+ Osaka::ScriptRunner.should_receive(:execute).exactly(3).times.with(/exists window 1/).and_return {
192
229
  counter = counter + 1
193
230
  if counter > 2
194
231
  "true"
@@ -197,7 +234,7 @@ describe "Osaka::ApplicationWrapper" do
197
234
  end
198
235
  }
199
236
  subject.should_receive(:activate).twice
200
- subject.until!.exists("window") {
237
+ subject.until!.exists(at.window(1)) {
201
238
  subject.activate
202
239
  }
203
240
  end
@@ -218,9 +255,9 @@ describe "Osaka::ApplicationWrapper" do
218
255
  end
219
256
 
220
257
  it "Should initialize the current window when it is not focused yet" do
221
- subject.should_receive(:window_list).and_return(["1"])
258
+ subject.should_receive(:window_list).and_return(["1"])
222
259
  subject.focus
223
- subject.window.should == "1"
260
+ subject.current_window_name.should == "1"
224
261
  end
225
262
 
226
263
  it "Shouldn't initialize current window when it is already set" do
@@ -230,7 +267,7 @@ describe "Osaka::ApplicationWrapper" do
230
267
  subject.should_receive(:window_list).and_return(["2", "1"])
231
268
  subject.should_receive(:set!)
232
269
  subject.focus
233
- subject.window.should == "1"
270
+ subject.current_window_name.should == "1"
234
271
  end
235
272
 
236
273
  it "Should re-initialize the current window when it doesn't exist anymore" do
@@ -239,7 +276,7 @@ describe "Osaka::ApplicationWrapper" do
239
276
 
240
277
  subject.should_receive(:window_list).and_return(["2"])
241
278
  subject.focus
242
- subject.window.should == "2"
279
+ subject.current_window_name.should == "2"
243
280
  end
244
281
 
245
282
  it "Should focus the current window when it doesn't have focus" do
@@ -247,8 +284,8 @@ describe "Osaka::ApplicationWrapper" do
247
284
  subject.focus
248
285
 
249
286
  subject.should_receive(:window_list).and_return(["2", "1"])
250
- subject.should_receive(:set!).with("value", "attribute \"AXMain\" of window \"1\"", true )
287
+ subject.should_receive(:set!).with("value", "attribute \"AXMain\"", true )
251
288
  subject.focus
252
- end
253
-
289
+ end
290
+
254
291
  end
Binary file
Binary file
Binary file
Binary file
@@ -16,16 +16,15 @@ describe "Mac GUI Calculator" do
16
16
  # TODO: Fix this duplication between this and TextEdit.
17
17
 
18
18
  @wrapper.should_receive(:activate)
19
- @wrapper.should_receive(:window).and_return(nil)
19
+ @wrapper.should_receive(:current_window_name).and_return("")
20
20
  subject.should_receive(:wait_for_new_window).with([])
21
21
  @wrapper.should_receive(:window_list).and_return(["Calculator"])
22
- @wrapper.should_receive(:window=).with("Calculator")
22
+ @wrapper.should_receive(:set_current_window).with("Calculator")
23
23
  subject.activate
24
24
  end
25
-
26
-
25
+
27
26
  it "Should be able to click a button on the calculator" do
28
- expect_click!('button "1" of group 2 of window "Calculator"')
27
+ expect_click!(at.button("1").group(2))
29
28
  subject.click("1")
30
29
  end
31
30
 
@@ -35,12 +34,13 @@ describe "Mac GUI Calculator" do
35
34
  end
36
35
 
37
36
  it "Should be able to quit the calculator" do
37
+ @wrapper.should_receive(:running?).and_return(true)
38
38
  @wrapper.should_receive(:quit)
39
39
  subject.quit
40
40
  end
41
41
 
42
42
  it "Should be able to get the value from the screen" do
43
- @wrapper.should_receive(:get!).with("value", 'static text 1 of group 1').and_return("0")
43
+ @wrapper.should_receive(:get!).with("value", at.static_text(1).group(1)).and_return("0")
44
44
  subject.result.should == "0"
45
45
  end
46
46
 
@@ -15,7 +15,6 @@ describe "Integration test using the Calculator" do
15
15
 
16
16
  it "Should be able to get info from the calculator" do
17
17
  app_info = subject.get_info
18
-
19
18
  end
20
19
 
21
20
  it "Should be able to do calculations with mouse" do
@@ -0,0 +1,29 @@
1
+ require 'tmpdir'
2
+ require 'osaka'
3
+
4
+ describe "Integration tests for Keynote and Common Flows" do
5
+
6
+ it "Should be able to do a combine with just one file" do
7
+
8
+ assets_directory = File.join(File.dirname(__FILE__), "assets")
9
+
10
+ keynote_file = File.join(assets_directory, "01_first_slides.key")
11
+ Dir.mktmpdir { |dir|
12
+ results_file = File.join(dir, "results.key")
13
+ CommonFlows.keynote_combine_files(results_file, keynote_file)
14
+ File.exists?(results_file).should == true
15
+ }
16
+ end
17
+
18
+ it "Should be able to combine multiple files" do
19
+ assets_directory = File.join(File.dirname(__FILE__), "assets")
20
+
21
+ Dir.mktmpdir { |dir|
22
+ results_file = File.join(dir, "results.key")
23
+ CommonFlows.keynote_combine_files_from_directory_sorted(results_file, assets_directory)
24
+ File.exists?(results_file).should == true
25
+ }
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'tmpdir'
2
+ require 'osaka'
3
+
4
+ describe "Integration of mail merge flow with Pages and Numbers" do
5
+
6
+ it "Should mail merge the assets and generate a PDF" do
7
+
8
+ assets_directory = File.join(File.dirname(__FILE__), "assets")
9
+ numbers_data = File.join(assets_directory, "mail_merge_data.numbers")
10
+ pages_template = File.join(assets_directory, "mail_merge_template.pages")
11
+ Dir.mktmpdir { |dir|
12
+ pdf_output_file = File.join(dir, "output.pdf")
13
+ CommonFlows::number_and_pages_mail_merge(numbers_data, pages_template, pdf_output_file)
14
+ File.exists?(pdf_output_file).should == true
15
+ }
16
+ end
17
+ end
@@ -6,28 +6,32 @@ describe "Integration test using TextEdit" do
6
6
  subject { Osaka::TextEdit.new }
7
7
 
8
8
  before (:each) do
9
+ if subject.running?
10
+ subject.quit(:dont_save)
11
+ end
9
12
  end
10
13
 
11
14
  after (:each) do
12
15
  subject.quit(:dont_save)
13
16
  end
14
17
 
15
- it "can type in the window" do
18
+ it "can type in the window" do
16
19
  subject.activate
17
20
  subject.type("Hello World")
18
21
  subject.text.should == "Hello World"
19
22
  end
20
23
 
21
24
  it "can type in two windows using two instances" do
25
+
22
26
  editor1 = subject
23
27
  editor2 = Osaka::TextEdit.new
24
-
28
+
25
29
  editor1.activate
26
30
  editor2.new_document
27
31
 
28
32
  editor1.type("Typing in window 1")
29
33
  editor2.type("Typing in window 2")
30
-
34
+
31
35
  editor1.text.should == "Typing in window 1"
32
36
  editor2.text.should == "Typing in window 2"
33
37
 
@@ -0,0 +1,62 @@
1
+
2
+ require "osaka"
3
+
4
+ describe "Common flows in keynote" do
5
+
6
+ before(:each) do
7
+ @mock_keynote = double(:Keynote)
8
+ end
9
+
10
+ it "Should be able to combine just one single file" do
11
+ Osaka::Keynote.should_receive(:new).and_return(@mock_keynote)
12
+ @mock_keynote.should_receive(:open).with("one_file.key")
13
+ @mock_keynote.should_receive(:save_as).with("result.key")
14
+ @mock_keynote.should_receive(:save)
15
+ @mock_keynote.should_receive(:quit)
16
+ CommonFlows.keynote_combine_files("result.key", "one_file.key")
17
+ end
18
+
19
+ it "Should be able to combine multiple files in one result" do
20
+ mock2_keynote = double(:Keynote)
21
+ mock3_keynote = double(:Keynote)
22
+ Osaka::Keynote.should_receive(:new).and_return(@mock_keynote, mock2_keynote, mock3_keynote)
23
+ @mock_keynote.should_receive(:open).with("one_file.key")
24
+ @mock_keynote.should_receive(:save_as).with("result.key")
25
+ @mock_keynote.should_receive(:select_all_slides).exactly(2).times
26
+ @mock_keynote.should_receive(:paste).exactly(2).times
27
+ @mock_keynote.should_receive(:save)
28
+
29
+
30
+ mock2_keynote.should_receive(:open).with("two_file.key")
31
+ mock2_keynote.should_receive(:select_all_slides)
32
+ mock2_keynote.should_receive(:copy)
33
+ mock2_keynote.should_receive(:close)
34
+
35
+ mock3_keynote.should_receive(:open).with("three_file.key")
36
+ mock3_keynote.should_receive(:select_all_slides)
37
+ mock3_keynote.should_receive(:copy)
38
+ mock3_keynote.should_receive(:close)
39
+
40
+ @mock_keynote.should_receive(:quit)
41
+ CommonFlows.keynote_combine_files("result.key", ["one_file.key", "two_file.key", "three_file.key"])
42
+ end
43
+
44
+ it "Should be able to combine multiple files from one directory sorted" do
45
+ files_in_dir = [".", "..", "one.key", "05_file.key", "02key.wrong", "another", "01hey.key", "last"]
46
+ files_matching = ["./05_file.key", "./01hey.key", "./one.key"]
47
+ Dir.should_receive(:new).with(".").and_return(files_in_dir)
48
+ CommonFlows.should_receive(:keynote_combine_files).with("results.key", files_matching.sort)
49
+ CommonFlows.keynote_combine_files_from_directory_sorted("results.key")
50
+ end
51
+
52
+ it "Should be able to combine multiple files from one directory sorted with pattern" do
53
+ files_in_dir = [".", "..", "05_file.key", "02key.wrong", "another", "01hey.key", "last"]
54
+ files_in_dir_to_be_used = ["dirname/01hey.key", "dirname/05_file.key"]
55
+ mocked_dir = double(:Dir)
56
+ Dir.should_receive(:new).with("dirname").and_return(mocked_dir)
57
+ mocked_dir.should_receive(:entries).and_return(files_in_dir)
58
+ CommonFlows.should_receive(:keynote_combine_files).with("results.key", files_in_dir_to_be_used)
59
+ CommonFlows.keynote_combine_files_from_directory_sorted("results.key", "dirname", /^\d+.*\.key$/)
60
+ end
61
+
62
+ end
data/spec/keynote_spec.rb CHANGED
@@ -3,14 +3,34 @@ require 'osaka'
3
3
 
4
4
  describe "Osaka::Keynote" do
5
5
 
6
+ include(*Osaka::ApplicationWrapperExpectations)
7
+
6
8
  subject { Osaka::Keynote.new }
7
9
 
8
10
  before (:each) do
9
- subject.wrapper = double("Osaka::ApplicationWrapper").as_null_object
11
+ @wrapper = subject.wrapper = double("Osaka::ApplicationWrapper").as_null_object
10
12
  end
11
13
 
12
14
  it "Should create the correct keynote print dialog" do
13
15
  subject.create_print_dialog("window").class.should == Osaka::KeynotePrintDialog
14
16
  end
15
17
 
18
+ it "Should be possible to select all the slides in the default location" do
19
+ slides_button_location = at.button("Slides").group(1).outline(1).scroll_area(2).splitter_group(1).splitter_group(1)
20
+ should_check!(:exists, slides_button_location, true)
21
+ expect_click(slides_button_location)
22
+ subject.should_receive(:select_all)
23
+ subject.select_all_slides
24
+ end
25
+
26
+ it "Should be possible to select all the slides in the alternative location" do
27
+ slides_button_location = at.button("Slides").group(1).outline(1).scroll_area(2).splitter_group(1).splitter_group(1)
28
+ alternative_slides_button_location = at.button("Slides").group(1).outline(1).scroll_area(1).splitter_group(1).splitter_group(1)
29
+ should_check!(:exists, slides_button_location, false)
30
+ expect_click(alternative_slides_button_location)
31
+ subject.should_receive(:select_all)
32
+ subject.select_all_slides
33
+ end
34
+
35
+
16
36
  end
@@ -0,0 +1,53 @@
1
+
2
+ require 'osaka'
3
+
4
+ describe "Location path for an applescript command" do
5
+
6
+ it "Should be able to create a valid location when appending two locations" do
7
+ location = Osaka::Location.new("scrollbar") + Osaka::Location.new("window 1")
8
+ location.to_s.should == "scrollbar of window 1"
9
+ end
10
+
11
+ it "Should be able to add empty locations" do
12
+ location = Osaka::Location.new("location") + ""
13
+ location.to_s.should == "location"
14
+ end
15
+
16
+ it "Should be able to create locations using at" do
17
+ at.button(1).to_s.should == "button 1"
18
+ end
19
+
20
+ it "Should be able to create empty prefixed locations" do
21
+ Osaka::Location.new("").as_prefixed_location.should == ""
22
+ end
23
+
24
+ it "Should be able to check whether the location already has a window" do
25
+ Osaka::Location.new("").has_window?.should == false
26
+ at.window("one").has_window?.should == true
27
+ end
28
+
29
+ it "Should be able to create groups" do
30
+ at.group(1).to_s.should == "group 1"
31
+ end
32
+
33
+ it "Should be able to combine buttons with groups" do
34
+ at.button("1").group(2).to_s.should == 'button "1" of group 2'
35
+ end
36
+
37
+ it "Should be able to combine groups with windows" do
38
+ at.button(1).group(2).window("Name").to_s.should == 'button 1 of group 2 of window "Name"'
39
+ end
40
+
41
+ it "Can compare different locations" do
42
+ at.button(1).should == at.button(1)
43
+ end
44
+
45
+ it "Should be able to convert to a prefixed location" do
46
+ at.button(1).as_prefixed_location == " of button 1"
47
+ end
48
+
49
+ it "Cannot create a location with two times window" do
50
+ lambda {at.window(1).window(1)}.should raise_error(Osaka::InvalidLocation, "Invalid location: window 1 of window 1")
51
+ end
52
+
53
+ end
@@ -0,0 +1,40 @@
1
+
2
+ require "osaka"
3
+
4
+ describe "Mail Merge to PDF common flow" do
5
+
6
+ before(:each) do
7
+ @mock_numbers = double(:Numbers)
8
+ @mock_pages = double(:Pages)
9
+ end
10
+
11
+ it "Should do a good mail merge with Pages and Keynote flow" do
12
+ Osaka::Numbers.should_receive(:new).and_return(@mock_numbers)
13
+ Osaka::Pages.should_receive(:new).and_return(@mock_pages)
14
+
15
+ @mock_numbers.should_receive(:open).with("/template/numbers")
16
+ @mock_numbers.should_receive(:save)
17
+
18
+ @mock_pages.should_receive(:open).with("/template/pages")
19
+ @mock_pages.should_receive(:mail_merge_to_pdf).with("/output/file.pdf")
20
+
21
+ @mock_numbers.should_receive(:quit).with(:dont_save)
22
+ @mock_pages.should_receive(:quit).with(:dont_save)
23
+
24
+ CommonFlows.number_and_pages_mail_merge("/template/numbers", "/template/pages", "/output/file.pdf") {}
25
+ end
26
+
27
+ it "Should yield for filling in the numbers fields" do
28
+ @mock_numbers.as_null_object
29
+ @mock_pages.as_null_object
30
+ Osaka::Numbers.should_receive(:new).and_return(@mock_numbers)
31
+ Osaka::Pages.should_receive(:new).and_return(@mock_pages)
32
+
33
+ retrieved_numbers = nil
34
+ CommonFlows.number_and_pages_mail_merge("1", "2", "3") { |numbers|
35
+ retrieved_numbers = numbers
36
+ }
37
+ retrieved_numbers.should == @mock_numbers
38
+ end
39
+
40
+ end
data/spec/pages_spec.rb CHANGED
@@ -25,18 +25,18 @@ describe "Osaka::Pages" do
25
25
  end
26
26
 
27
27
  it "Should be able to select the Mail Merge" do
28
- expect_system_event('tell menu bar 1; tell menu "Edit"; click menu item 20; end tell; end tell')
29
- should_wait_until(:exists, 'button "Merge" of sheet 1 of window 1')
28
+ @wrapper.should_receive(:current_window_name).any_number_of_times.and_return("Pages.pages")
29
+ expect_click_menu_bar(at.menu_item(20), "Edit")
30
+ should_wait_until(:exists, at.button("Merge").sheet(1))
30
31
  subject.mail_merge
31
32
  end
32
33
 
33
34
  it "Should click the merge button of the mail merge dialog" do
34
- expect_click!('button "Merge" of sheet 1 of window 1')
35
- should_wait_until!(:exists, 'menu button "PDF" of window "Print"')
35
+ @wrapper.should_receive(:current_window_name).any_number_of_times.and_return("Pages.pages")
36
+ expect_click!(at.button("Merge").sheet(1))
37
+ should_wait_until!(:exists, at.menu_button("PDF").window("Print"))
36
38
  subject.mail_merge.merge
37
39
  end
38
-
39
-
40
40
  end
41
41
 
42
42
  describe "Osaka::Pages Mail Merge dialog" do
@@ -47,20 +47,20 @@ describe "Osaka::Pages Mail Merge dialog" do
47
47
 
48
48
  before (:each) do
49
49
  @wrapper = subject.wrapper = double("Osaka::ApplicationWrapper").as_null_object
50
- @location = subject.location = "window 1"
50
+ @location = subject.location = "window \"Pages.pages\""
51
51
  end
52
52
 
53
53
  it "Should be able to set the mail merge dialog to merge to new document" do
54
- expect_click("pop up button 2 of #{@location}")
55
- should_wait_until!(:exists, "menu item 1 of menu 1 of pop up button 2 of #{@location}")
56
- expect_click!("menu item 1 of menu 1 of pop up button 2 of #{@location}")
54
+ expect_click(at.pop_up_button(2).sheet(1))
55
+ should_wait_until!(:exists, at.menu_item(1).menu(1).pop_up_button(2).sheet(1))
56
+ expect_click!(at.menu_item(1).menu(1).pop_up_button(2).sheet(1))
57
57
  subject.set_merge_to_new_document
58
58
  end
59
59
 
60
60
  it "Should be able to set the mail merge dialog to merge to printer" do
61
- expect_click("pop up button 2 of #{@location}")
62
- should_wait_until!(:exists, "menu item 2 of menu 1 of pop up button 2 of #{@location}")
63
- expect_click!("menu item 2 of menu 1 of pop up button 2 of #{@location}")
61
+ expect_click(at.pop_up_button(2).sheet(1))
62
+ should_wait_until!(:exists, at.menu_item(2).menu(1).pop_up_button(2).sheet(1))
63
+ expect_click!(at.menu_item(2).menu(1).pop_up_button(2).sheet(1))
64
64
  subject.set_merge_to_printer
65
65
  end
66
66
  end
@@ -22,6 +22,15 @@ describe "Osaka::ScriptRunner" do
22
22
  subject.execute("random number")
23
23
  Osaka::ScriptRunner::disable_debug_prints
24
24
  end
25
+
26
+ it "Should be able to run on debug printing with HTML tags" do
27
+ subject.should_receive(:do_system).and_return("Blah blah blah")
28
+ subject.should_receive(:puts).with('random number<br>')
29
+ subject.should_receive(:puts).with('Output: <b>Blah blah blah</b><br>')
30
+ Osaka::ScriptRunner::enable_debug_prints(:short_html)
31
+ subject.execute("random number")
32
+ Osaka::ScriptRunner::disable_debug_prints
33
+ end
25
34
 
26
35
  it "Should not print any debugging information by default " do
27
36
  subject.should_receive(:do_system).and_return("")