osaka 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,11 @@
1
1
 
2
2
  module Osaka
3
3
 
4
- class ConditionAndActionProxy
4
+ class ConditionProxy
5
5
 
6
- def initialize(wrapper)
6
+ def initialize(wrapper, action)
7
7
  @wrapper = wrapper
8
+ @action = action
8
9
  end
9
10
 
10
11
  def create_condition_class_based_on_name(sym)
@@ -14,13 +15,24 @@ module Osaka
14
15
 
15
16
  def method_missing(sym, *args, &block)
16
17
  condition = create_condition_class_based_on_name(sym)
17
- @wrapper.enter_nested_action
18
- yield unless block.nil?
19
- @wrapper.exit_nested_action
20
- @wrapper.system_event!("repeat until #{condition.as_script(*args)}; #{@wrapper.nested_action} end repeat")
18
+ @action.execute(@wrapper, condition, *args, &block)
21
19
  end
22
20
  end
23
21
 
22
+ class RepeatAction
23
+ def execute(wrapper, condition, *args, &block)
24
+ while (!CheckAction.new.execute(wrapper, condition, *args, &block))
25
+ yield unless block.nil?
26
+ end
27
+ end
28
+ end
29
+
30
+ class CheckAction
31
+ def execute(wrapper, condition, *args, &block)
32
+ wrapper.system_event!("#{condition.as_script(*args)};").strip == "true"
33
+ end
34
+ end
35
+
24
36
  class ExistsCondition
25
37
  def as_script(element_to_wait_for)
26
38
  "exists #{element_to_wait_for}"
@@ -37,44 +49,33 @@ module Osaka
37
49
 
38
50
  def initialize(name)
39
51
  @name = name
40
- @nested = false
41
52
  end
42
53
 
43
- def enter_nested_action
44
- @nested = true
45
- @nested_action = ""
54
+ def print_warning(action, message)
55
+ puts "Osaka WARNING while doing #{action}: #{message}"
46
56
  end
47
57
 
48
- def nested_action
49
- @nested_action
50
- end
51
-
52
- def exit_nested_action
53
- @nested = false
54
- end
55
-
56
- def execute_script(script)
57
- if @nested
58
- @nested_action += "#{script};"
59
- else
60
- ScriptRunner::execute(script) unless @nested
58
+ def check_output(output, action)
59
+ if (!output.empty?)
60
+ print_warning(action, output)
61
61
  end
62
+ output
62
63
  end
63
64
 
64
65
  def activate
65
- tell("activate")
66
+ check_output( tell("activate"), "activate" )
66
67
  end
67
68
 
68
69
  def quit
69
- tell("quit")
70
+ check_output( tell("quit"), "quit" )
70
71
  end
71
72
 
72
73
  def tell(command)
73
- execute_script("tell application \"#{@name}\"; #{command}; end tell")
74
+ ScriptRunner::execute("tell application \"#{@name}\"; #{command}; end tell")
74
75
  end
75
76
 
76
77
  def system_event!(event)
77
- execute_script("tell application \"System Events\"; tell process \"#{@name}\"; #{event}; end tell; end tell")
78
+ ScriptRunner::execute("tell application \"System Events\"; tell process \"#{@name}\"; #{event}; end tell; end tell")
78
79
  end
79
80
 
80
81
  def system_event(event)
@@ -87,12 +88,16 @@ module Osaka
87
88
  wait_until!
88
89
  end
89
90
 
91
+ def check
92
+ ConditionProxy.new(self, CheckAction.new)
93
+ end
94
+
90
95
  def wait_until!
91
- ConditionAndActionProxy.new(self)
96
+ ConditionProxy.new(self, RepeatAction.new)
92
97
  end
93
98
 
94
99
  def until!
95
- ConditionAndActionProxy.new(self)
100
+ ConditionProxy.new(self, RepeatAction.new)
96
101
  end
97
102
 
98
103
  def construct_modifier_statement(modifier_keys)
@@ -102,7 +107,7 @@ module Osaka
102
107
  end
103
108
 
104
109
  def keystroke!(key, modifier_keys = [])
105
- system_event!("keystroke \"#{key}\"#{construct_modifier_statement(modifier_keys)}")
110
+ check_output( system_event!("keystroke \"#{key}\"#{construct_modifier_statement(modifier_keys)}"), "keystroke")
106
111
  self
107
112
  end
108
113
 
@@ -112,6 +117,7 @@ module Osaka
112
117
  end
113
118
 
114
119
  def click!(element)
120
+ # Click seems to often output stuff, but it doesn't have much meaning so we ignore it.
115
121
  system_event!("click #{element}")
116
122
  self
117
123
  end
@@ -121,13 +127,17 @@ module Osaka
121
127
  click!(element)
122
128
  end
123
129
 
124
- def set!(element, value)
125
- system_event!("set #{element} to \"#{value}\"")
130
+ def set!(element, location, value)
131
+ check_output( system_event!("set #{element} of #{location} to \"#{value}\""), "set")
132
+ end
133
+
134
+ def get!(element, location)
135
+ system_event!("get #{element} of #{location}")
126
136
  end
127
137
 
128
- def set(element, value)
138
+ def set(element, location, value)
129
139
  activate
130
- set!(element, value)
140
+ set!(element, location, value)
131
141
  end
132
142
  end
133
143
  end
data/lib/osaka/pages.rb CHANGED
@@ -1,9 +1,10 @@
1
1
 
2
2
  module Osaka
3
3
  class PagesMailMergeDialog
4
- attr_accessor :wrapper
4
+ attr_accessor :wrapper, :location
5
5
 
6
- def initialize(wrapper)
6
+ def initialize(location, wrapper)
7
+ @location = location
7
8
  @wrapper = wrapper
8
9
  end
9
10
 
@@ -13,7 +14,21 @@ module Osaka
13
14
  @wrapper.wait_until!.exists("menu button \"PDF\" of #{print_dialog_location}")
14
15
  TypicalPrintDialog.new(print_dialog_location, @wrapper)
15
16
  end
16
-
17
+
18
+ def set_merge_to_new_document
19
+ set_merge_to_document_printer(1)
20
+ end
21
+
22
+ def set_merge_to_printer
23
+ set_merge_to_document_printer(2)
24
+ end
25
+
26
+ private
27
+ def set_merge_to_document_printer(value)
28
+ @wrapper.click("pop up button 2 of #{@location}")
29
+ @wrapper.wait_until!.exists("menu item #{value} of menu 1 of pop up button 2 of #{@location}")
30
+ @wrapper.click!("menu item #{value} of menu 1 of pop up button 2 of #{@location}")
31
+ end
17
32
  end
18
33
 
19
34
  class Pages < TypicalApplication
@@ -25,7 +40,7 @@ module Osaka
25
40
  def mail_merge
26
41
  @wrapper.system_event("tell menu bar 1; tell menu \"Edit\"; click menu item 20; end tell; end tell")
27
42
  @wrapper.wait_until.exists('button "Merge" of sheet 1 of window 1')
28
- PagesMailMergeDialog.new(@wrapper)
43
+ PagesMailMergeDialog.new("sheet 1 of window 1", @wrapper)
29
44
  end
30
45
 
31
46
  def mail_merge_to_pdf(filename)
@@ -3,12 +3,15 @@ module Osaka
3
3
 
4
4
  class ScriptRunnerError < RuntimeError
5
5
  end
6
+
7
+ class SystemCommandFailed < RuntimeError
8
+ end
6
9
 
7
10
  module ScriptRunner
8
11
 
9
12
  @@debug_info_enabled = false
10
13
 
11
- def self.enabled_debug_prints
14
+ def self.enable_debug_prints
12
15
  @@debug_info_enabled = true
13
16
  end
14
17
 
@@ -21,18 +24,34 @@ module Osaka
21
24
  end
22
25
 
23
26
  def self.execute(applescript)
24
- script_commands = applescript.gsub('"', '\\"').split(';')
27
+ script_commands = applescript.gsub("\"", "\\\"").split(';')
25
28
  escaped_commands = ""
26
29
  script_commands.each { |l|
27
30
  escaped_commands += " -e \"#{l.strip}\""
28
31
  }
29
32
  puts "Executing: osascript#{escaped_commands}" if debug_prints?
30
-
31
- raise(Osaka::ScriptRunnerError, "Error received while executing: #{applescript}") unless system("osascript#{escaped_commands}")
33
+
34
+ output = ""
35
+ begin
36
+ output = do_system("osascript#{escaped_commands}")
37
+ rescue Osaka:: SystemCommandFailed
38
+ raise(Osaka::ScriptRunnerError, "Error received while executing: #{applescript}")
39
+ end
40
+ if (!output.empty? && debug_prints?)
41
+ puts "Output was: #{output}"
42
+ end
43
+ output
32
44
  end
33
45
 
34
46
  def self.execute_file(scriptName, parameters = "")
35
- system("osascript #{scriptName} #{parameters}".strip)
47
+ do_system("osascript #{scriptName} #{parameters}".strip)
48
+ end
49
+
50
+ private
51
+ def self.do_system(command)
52
+ output = `#{command}`
53
+ raise Osaka::SystemCommandFailed unless $?.success?
54
+ output
36
55
  end
37
56
  end
38
57
  end
@@ -10,12 +10,12 @@ module Osaka
10
10
  end
11
11
 
12
12
  def set_filename(filename)
13
- @wrapper.set("value of text field 1 of #{@location}", filename)
13
+ @wrapper.set("value", "text field 1 of #{@location}", filename)
14
14
  end
15
15
 
16
16
  def set_folder(pathname)
17
- @wrapper.keystroke("g", [ :command, :shift ]).wait_until.exists ("sheet 1 of #{@location}")
18
- @wrapper.set("value of text field 1 of sheet 1 of #{@location}", pathname)
17
+ @wrapper.keystroke("g", [ :command, :shift ]).wait_until.exists("sheet 1 of #{@location}")
18
+ @wrapper.set("value", "text field 1 of sheet 1 of #{@location}", pathname)
19
19
  @wrapper.click("button \"Go\" of sheet 1 of #{@location}").wait_until.not_exists("sheet 1 of #{@location}")
20
20
  end
21
21
 
@@ -44,7 +44,7 @@ module Osaka
44
44
  end
45
45
 
46
46
  def save_as_pdf(filename)
47
- @wrapper.click!("menu button \"PDF\" of #{@location}").wait_until!.exists ("menu 1 of menu button \"PDF\" of #{@location}")
47
+ @wrapper.click!("menu button \"PDF\" of #{@location}").wait_until!.exists("menu 1 of menu button \"PDF\" of #{@location}")
48
48
  @wrapper.click!("menu item 2 of menu 1 of menu button \"PDF\" of #{@location}").wait_until!.exists('window "Save"')
49
49
  save_dialog = create_save_dialog("window \"Save\"", @wrapper)
50
50
  save_dialog.save(filename)
data/lib/osaka/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Osaka
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
@@ -6,6 +6,11 @@ describe "Osaka::ApplicationWrapper" do
6
6
  name = "ApplicationName"
7
7
  quoted_name = "\"#{name}\""
8
8
  subject { Osaka::ApplicationWrapper.new(name) }
9
+
10
+ def check_for_warning(action)
11
+ Osaka::ScriptRunner.should_receive(:execute).and_return("Blah")
12
+ subject.should_receive(:print_warning).with(action, "Blah")
13
+ end
9
14
 
10
15
  it "Should be able to tell applications to do something" do
11
16
  Osaka::ScriptRunner.should_receive(:execute).with("tell application #{quoted_name}; command; end tell")
@@ -16,16 +21,31 @@ describe "Osaka::ApplicationWrapper" do
16
21
  Osaka::ScriptRunner.should_receive(:execute).with("tell application #{quoted_name}; activate; quit; end tell")
17
22
  subject.tell("activate; quit")
18
23
  end
24
+
25
+ it "Should be able to print warning messages" do
26
+ subject.should_receive(:puts).with("Osaka WARNING while doing action: Message")
27
+ subject.print_warning("action", "Message")
28
+ end
19
29
 
20
30
  it "Has a short-cut method for activation" do
21
- Osaka::ScriptRunner.should_receive(:execute).with(/activate/)
31
+ Osaka::ScriptRunner.should_receive(:execute).with(/activate/).and_return("")
32
+ subject.activate
33
+ end
34
+
35
+ it "Should print an Warning message with the ScriptRunner returns text when doing activate" do
36
+ check_for_warning("activate")
22
37
  subject.activate
23
38
  end
24
39
 
25
40
  it "Has a short-cut method for quitting" do
26
- Osaka::ScriptRunner.should_receive(:execute).with(/quit/)
41
+ Osaka::ScriptRunner.should_receive(:execute).with(/quit/).and_return("")
27
42
  subject.quit
28
43
  end
44
+
45
+ it "Prints a warning message when quit results in some output" do
46
+ check_for_warning("quit")
47
+ subject.quit
48
+ end
29
49
 
30
50
  it "Should be able to generate events via the Systems Events" do
31
51
  Osaka::ScriptRunner.should_receive(:execute).with(/tell application "System Events"; tell process #{quoted_name}; quit; end tell; end tell/)
@@ -38,24 +58,38 @@ describe "Osaka::ApplicationWrapper" do
38
58
  subject.system_event("quit")
39
59
  end
40
60
 
61
+ it "Should be able to check whether a specific element exists" do
62
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true\n")
63
+ subject.check.exists("window 1").should == true
64
+ end
65
+
41
66
  it "Should be able to wait for for a specific element existing" do
42
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window 1; end repeat/)
67
+ counter = 0
68
+ Osaka::ScriptRunner.should_receive(:execute).exactly(5).times.with(/exists window 1/).and_return {
69
+ counter = counter + 1
70
+ (counter == 5).to_s
71
+ }
43
72
  subject.wait_until!.exists("window 1")
44
73
  end
45
74
 
46
75
  it "Should be able to wait until exists and activate the application first" do
47
76
  subject.should_receive(:activate)
48
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window 1; end repeat/)
77
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
49
78
  subject.wait_until.exists("window 1")
50
79
  end
51
80
 
52
81
  it "Should be able to wait for a specific element to not exist anymore" do
53
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until not exists window 1; end repeat/)
82
+ Osaka::ScriptRunner.should_receive(:execute).with(/not exists window 1/).and_return("true")
54
83
  subject.wait_until!.not_exists("window 1")
55
84
  end
56
85
 
57
86
  it "Should be able to generate keystroke events" do
58
- Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/)
87
+ Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
88
+ subject.keystroke!("p")
89
+ end
90
+
91
+ it "Prints a warning when keystroke results in some outputShould be able to generate keystroke events" do
92
+ check_for_warning("keystroke")
59
93
  subject.keystroke!("p")
60
94
  end
61
95
 
@@ -66,33 +100,33 @@ describe "Osaka::ApplicationWrapper" do
66
100
  end
67
101
 
68
102
  it "Should be able to do keystrokes with command down" do
69
- Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {command down}/)
103
+ Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {command down}/).and_return("")
70
104
  subject.keystroke!("p", :command)
71
105
  end
72
106
 
73
107
  it "Should be able to do keystrokes with option and command down" do
74
- Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {option down, command down}/)
108
+ Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p" using {option down, command down}/).and_return("")
75
109
  subject.keystroke!("p", [ :option, :command ])
76
110
  end
77
111
 
78
112
  it "Should be able to do a keystroke and wait until something happen in one easy line" do
79
- Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/)
80
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window 1; end repeat/)
113
+ Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
114
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
81
115
  subject.keystroke!("p", []).wait_until!.exists("window 1")
82
116
  end
83
117
 
84
118
  it "Should be able to keystroke_and_wait_until_exists and activate" do
85
119
  subject.should_receive(:activate)
86
- Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/)
87
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window 1; end repeat/)
120
+ Osaka::ScriptRunner.should_receive(:execute).with(/keystroke "p"/).and_return("")
121
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window 1/).and_return("true")
88
122
  subject.keystroke("p", []).wait_until!.exists("window 1")
89
123
  end
90
124
 
91
125
  it "Should be able to do clicks" do
92
- Osaka::ScriptRunner.should_receive(:execute).with(/click menu button "PDF"/)
126
+ Osaka::ScriptRunner.should_receive(:execute).with(/click menu button "PDF"/).and_return("")
93
127
  subject.click!('menu button "PDF"')
94
128
  end
95
-
129
+
96
130
  it "Should be able to do click and activate" do
97
131
  subject.should_receive(:activate)
98
132
  subject.should_receive(:click!).with("button")
@@ -100,31 +134,50 @@ describe "Osaka::ApplicationWrapper" do
100
134
  end
101
135
 
102
136
  it "Should be able to do clicks and wait until something happened in one easy line" do
103
- Osaka::ScriptRunner.should_receive(:execute).with(/click/)
104
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window; end repeat/)
137
+ Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
138
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window/).and_return("true")
105
139
  subject.click!("button").wait_until!.exists("window")
106
140
  end
107
141
 
108
142
  it "Should be able to click_and_wait_until_exists and activate" do
109
143
  subject.should_receive(:activate)
110
- Osaka::ScriptRunner.should_receive(:execute).with(/click/)
111
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window; end repeat/)
144
+ Osaka::ScriptRunner.should_receive(:execute).with(/click/).and_return("")
145
+ Osaka::ScriptRunner.should_receive(:execute).with(/exists window/).and_return("true")
112
146
  subject.click("button").wait_until!.exists("window")
113
147
  end
114
148
 
115
149
  it "Should be able to set a value to an element" do
116
- subject.should_receive(:system_event!).with(/set value of window to "newvalue"/)
117
- subject.set!("value of window", "newvalue")
150
+ check_for_warning("set")
151
+ subject.set!("value", "window", "newvalue")
152
+ end
153
+
154
+ it "Prints a warning when setting and element and output is received" do
155
+ subject.should_receive(:system_event!).with(/set value of window to "newvalue"/).and_return("")
156
+ subject.set!("value", "window", "newvalue")
157
+ end
158
+
159
+ it "Should be able to get a value from an element" do
160
+ subject.should_receive(:system_event!).with(/get value of window/).and_return("1")
161
+ subject.get!("value", "window").should == "1"
118
162
  end
119
163
 
120
164
  it "Should be able to set a value and activate" do
121
165
  subject.should_receive(:activate)
122
- subject.should_receive(:set!).with("value of window", "newvalue")
123
- subject.set("value of window", "newvalue")
166
+ subject.should_receive(:set!).with("value", "window", "newvalue")
167
+ subject.set("value", "window", "newvalue")
124
168
  end
125
169
 
126
170
  it "Should be able to loop over some script until something happens" do
127
- Osaka::ScriptRunner.should_receive(:execute).with(/repeat until exists window; tell application \"ApplicationName\"; activate; end tell; end repeat/)
171
+ counter = 0
172
+ Osaka::ScriptRunner.should_receive(:execute).exactly(3).times.with(/exists window/).and_return {
173
+ counter = counter + 1
174
+ if counter > 2
175
+ "true"
176
+ else
177
+ "false"
178
+ end
179
+ }
180
+ subject.should_receive(:activate).twice
128
181
  subject.until!.exists("window") {
129
182
  subject.activate
130
183
  }
data/spec/pages_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe "Osaka::Pages" do
22
22
 
23
23
  subject.mail_merge_to_pdf("filename")
24
24
  end
25
-
25
+
26
26
  it "Should be able to select the Mail Merge" do
27
27
  expect_system_event('tell menu bar 1; tell menu "Edit"; click menu item 20; end tell; end tell')
28
28
  should_wait_until(:exists, 'button "Merge" of sheet 1 of window 1')
@@ -35,4 +35,32 @@ describe "Osaka::Pages" do
35
35
  subject.mail_merge.merge
36
36
  end
37
37
 
38
+
38
39
  end
40
+
41
+ describe "Osaka::Pages Mail Merge dialog" do
42
+
43
+ include(*Osaka::ApplicationWrapperExpectations)
44
+
45
+ subject { Osaka::PagesMailMergeDialog.new("", nil) }
46
+
47
+ before (:each) do
48
+ @wrapper = subject.wrapper = double("Osaka::ApplicationWrapper").as_null_object
49
+ @location = subject.location = "window 1"
50
+ end
51
+
52
+ it "Should be able to set the mail merge dialog to merge to new document" do
53
+ expect_click("pop up button 2 of #{@location}")
54
+ should_wait_until!(:exists, "menu item 1 of menu 1 of pop up button 2 of #{@location}")
55
+ expect_click!("menu item 1 of menu 1 of pop up button 2 of #{@location}")
56
+ subject.set_merge_to_new_document
57
+ end
58
+
59
+ it "Should be able to set the mail merge dialog to merge to printer" do
60
+ expect_click("pop up button 2 of #{@location}")
61
+ should_wait_until!(:exists, "menu item 2 of menu 1 of pop up button 2 of #{@location}")
62
+ expect_click!("menu item 2 of menu 1 of pop up button 2 of #{@location}")
63
+ subject.set_merge_to_printer
64
+ end
65
+ end
66
+
@@ -5,46 +5,47 @@ describe "Osaka::ScriptRunner" do
5
5
  subject { Osaka::ScriptRunner }
6
6
 
7
7
  it "Should be able to run single-line text as osascript" do
8
- subject.should_receive(:system).with('osascript -e "random number"').and_return(true)
9
- subject.execute("random number")
8
+ subject.should_receive(:do_system).with('osascript -e "random number"').and_return("")
9
+ subject.execute("random number").should == ""
10
10
  end
11
11
 
12
12
  it "Should escape quotes when passing text" do
13
- subject.should_receive(:system).with('osascript -e "say \\"hello\\""').and_return(true)
13
+ subject.should_receive(:do_system).with('osascript -e "say \\"hello\\""').and_return("")
14
14
  subject.execute('say "hello"')
15
15
  end
16
16
 
17
17
  it "Should be able to run on debug printing" do
18
- subject.should_receive(:system).and_return(true)
18
+ subject.should_receive(:do_system).and_return("Blah blah blah")
19
19
  subject.should_receive(:puts).with('Executing: osascript -e "random number"')
20
- Osaka::ScriptRunner::enabled_debug_prints
20
+ subject.should_receive(:puts).with('Output was: Blah blah blah')
21
+ Osaka::ScriptRunner::enable_debug_prints
21
22
  subject.execute("random number")
22
23
  Osaka::ScriptRunner::disable_debug_prints
23
24
  end
24
25
 
25
26
  it "Should not print any debugging information by default " do
26
- subject.should_receive(:system).and_return(true)
27
+ subject.should_receive(:do_system).and_return("")
27
28
  subject.should_not_receive(:puts)
28
29
  subject.execute("random number")
29
30
  end
30
31
 
31
32
  it "Should be able to define multi-line statements using ; as a separator" do
32
- subject.should_receive(:system).with('osascript -e "tell application \\"Calculator\\"" -e "activate" -e "end tell"').and_return(true)
33
+ subject.should_receive(:do_system).with('osascript -e "tell application \\"Calculator\\"" -e "activate" -e "end tell"').and_return("")
33
34
  subject.execute('tell application "Calculator"; activate; end tell')
34
35
  end
35
36
 
36
37
  it "Should raise an exception witha proper error message when the applescript fails" do
37
- subject.should_receive(:system).and_return(false)
38
+ subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed)
38
39
  lambda {subject.execute("Fuck off!")}.should raise_error(Osaka::ScriptRunnerError, "Error received while executing: Fuck off!")
39
40
  end
40
41
 
41
42
  it "Should be able to execute an file containing applescript" do
42
- subject.should_receive(:system).with('osascript script.scpt').and_return(true)
43
+ subject.should_receive(:do_system).with('osascript script.scpt').and_return(true)
43
44
  subject.execute_file("script.scpt")
44
45
  end
45
46
 
46
47
  it "Should be able to pass parameters to an applescript" do
47
- subject.should_receive(:system).with('osascript script.scpt a b c').and_return(true)
48
+ subject.should_receive(:do_system).with('osascript script.scpt a b c').and_return(true)
48
49
  subject.execute_file("script.scpt", "a b c")
49
50
  end
50
51
  end
@@ -95,14 +95,14 @@ describe "Osaka::TypicalApplication" do
95
95
  end
96
96
 
97
97
  it "Should be able to set the filename" do
98
- subject.wrapper.should_receive(:set).with('value of text field 1 of window 1', "filename")
98
+ subject.wrapper.should_receive(:set).with('value', 'text field 1 of window 1', "filename")
99
99
  subject.set_filename("filename")
100
100
  end
101
101
 
102
102
  it "Should be able to set the path" do
103
103
  expect_keystroke("g", [ :command, :shift ])
104
104
  should_wait_until(:exists, "sheet 1 of window 1")
105
- subject.wrapper.should_receive(:set).with("value of text field 1 of sheet 1 of window 1", "path")
105
+ subject.wrapper.should_receive(:set).with("value", "text field 1 of sheet 1 of window 1", "path")
106
106
  expect_click('button "Go" of sheet 1 of window 1')
107
107
  should_wait_until(:not_exists, "sheet 1 of window 1")
108
108
  subject.set_folder("path")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: osaka
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bas Vodde
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-18 00:00:00 +08:00
13
+ date: 2012-02-26 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency