Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
osaka.tmproj
osaka*.gem
Gemfile.lock
.DS_Store
4 changes: 3 additions & 1 deletion lib/osaka/commandrunner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class SystemCommandFailed < RuntimeError
end

module CommandRunner
def self.run(command)
def self.run(command, debug = false)
puts "Execute: #{command} " if debug
output = `#{command} 2>&1`
raise Osaka::SystemCommandFailed, "message" + output unless $?.success?
puts "Output was: #{output}" if debug
output
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/osaka/keynote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,18 @@ def light_table_view
control.click(at.menu_item("Light Table").menu(1).menu_bar_item("View").menu_bar(1))
end
end

def open (filename)
abolutePathFileName = File.absolute_path(filename)
new_window = do_and_wait_for_new_window {
# jwg - weird that keynote open via osascript is flakey for Mavericks
# was: control.tell("open \"#{abolutePathFileName}\"")
# But now uses the command line
CommandRunner::run("open #{abolutePathFileName}", ScriptRunner::debug_prints?)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually in higher-level classes, we wouldn't want to use the CommandRunner ? Is it possible to wrap that into a higher level to keep the abstraction good?

}
control.wait_until_exists(at.window(File.basename(filename)))
control.set_current_window(new_window)
end

end
end
43 changes: 39 additions & 4 deletions lib/osaka/keynoteflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ module CommonFlows
def self.keynote_combine_files(result_file, files_to_merge)
keynote = Osaka::Keynote.new
keynote.activate
keynote.close_template_chooser_if_any
keynote.raise_error_on_open_standard_windows("All Keynote windows must be closed before running this flow")

files_to_merge = [files_to_merge].flatten
keynote.open(files_to_merge.shift)
keynote.light_table_view
keynote.select_all_slides
keynote.save_as(result_file)



files_to_merge.each { |file|
combine_keynote = Osaka::Keynote.new
combine_keynote.open(file)
combine_keynote.select_all_slides
combine_keynote.copy
combine_keynote.close
keynote.select_all_slides
keynote.paste
}

Expand All @@ -27,11 +26,47 @@ def self.keynote_combine_files(result_file, files_to_merge)
keynote.quit
end

def self.keynote_open_yield_close(files)
keynote = Osaka::Keynote.new
keynote.activate
keynote.close_template_chooser_if_any
keynote.raise_error_on_open_standard_windows("All Keynote windows must be closed before running this flow")
files = [files].flatten
files.each { |file|
keynote = Osaka::Keynote.new
keynote.open(file)
yield keynote
keynote.close
}
keynote.quit
end

def self.keynote_combine_files_from_directory_sorted(result_file, directory = ".", pattern = /^.*\.key$/)
files_in_directory = Dir.new(directory).entries
files_in_directory.select! { |f| f =~ pattern }
files_to_open = files_in_directory.collect { |f| File.join(directory, f)}
keynote_combine_files(result_file, files_to_open.sort)
end

def self.output message
puts message
end

def self.keynote_combine_files_from_list(result_file, directory = ".", keynote_files)
files_to_open = keynote_files.collect { |f| File.join(directory, f)}
missing_files = ""
files_to_open.each { |f|
if !File.exist?(f)
missing_files += "\n" + f
end
}

if missing_files.empty?
keynote_combine_files(result_file, files_to_open)
else
output "These files do not exist: " + missing_files
end

end

end
70 changes: 36 additions & 34 deletions lib/osaka/osakaexpectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,134 +3,136 @@ module Osaka
module OsakaExpectations

def simulate_mac_version(version)
control.should_receive(:mac_version).and_return(version)
expect(control).to receive(:mac_version).and_return(version)
end

def expect_execute_osascript(command = nil)
return Osaka::ScriptRunner.should_receive(:execute).with(command) unless command.nil?
Osaka::ScriptRunner.should_receive(:execute)
end

def expect_clone
control.should_receive(:clone)
expect(control).to receive(:clone)
end

def expect_activate
control.should_receive(:activate)
expect(control).to receive(:activate)
# expect(control).to receive(:activate)
end

def expect_launch
control.should_receive(:launch)
expect(control).to receive(:launch)
end

def expect_focus
control.should_receive(:focus)
expect(control).to receive(:focus)
end

def expect_focus!
control.should_receive(:focus!)
expect(control).to receive(:focus!)
end

def expect_set_current_window(name)
control.should_receive(:set_current_window).with(name)
expect(control).to receive(:set_current_window).with(name)
end

def expect_running?
control.should_receive(:running?)
expect(control).to receive(:running?)
end

def expect_quit
control.should_receive(:quit)
expect(control).to receive(:quit)
end

def expect_window_list
control.should_receive(:window_list)
expect(control).to receive(:window_list)
end

def expect_standard_window_list
control.should_receive(:standard_window_list)
expect(control).to receive(:standard_window_list)
end

def expect_current_window_name
control.should_receive(:current_window_name)
expect(control).to receive(:current_window_name)
# expect(control).to receive(:current_window_name)
end

def expect_set(element, location, value)
control.should_receive(:set).with(element, location, value)
expect(control).to receive(:set).with(element, location, value)
end

def expect_set!(element, location, value)
control.should_receive(:set!).with(element, location, value)
expect(control).to receive(:set!).with(element, location, value)
end

def expect_get_app!(element)
control.should_receive(:get_app!).with(element)
expect(control).to receive(:get_app!).with(element)
end

def expect_keystroke(key, modifier = [])
control.should_receive(:keystroke).with(key, modifier).and_return(control) unless modifier.empty?
control.should_receive(:keystroke).with(key).and_return(control) if modifier.empty?
expect(control).to receive(:keystroke).with(key, modifier).and_return(control) unless modifier.empty?
expect(control).to receive(:keystroke).with(key).and_return(control) if modifier.empty?
end

def expect_keystroke!(key, modifier = [])
control.should_receive(:keystroke!).with(key, modifier).and_return(control) unless modifier.empty?
control.should_receive(:keystroke!).with(key).and_return(control) if modifier.empty?
expect(control).to receive(:keystroke!).with(key, modifier).and_return(control) unless modifier.empty?
expect(control).to receive(:keystroke!).with(key).and_return(control) if modifier.empty?
end

def expect_click!(location)
control.should_receive(:click!).with(location).and_return(control)
expect(control).to receive(:click!).with(location).and_return(control)
end

def expect_click(location)
control.should_receive(:click).with(location).and_return(control)
expect(control).to receive(:click).with(location).and_return(control)
end

def expect_click_menu_bar(menu_item, menu_name)
control.should_receive(:click_menu_bar).with(menu_item, menu_name).and_return(control)
expect(control).to receive(:click_menu_bar).with(menu_item, menu_name).and_return(control)
end

def expect_get!(element, location)
control.should_receive(:get!).with(element, location)
expect(control).to receive(:get!).with(element, location)
end

def expect_tell(do_this)
control.should_receive(:tell).with(do_this)
expect(control).to receive(:tell).with(do_this)
end

def expect_system_event(event)
control.should_receive(:system_event).with(event)
expect(control).to receive(:system_event).with(event)
end

def expect_system_event!(event)
control.should_receive(:system_event!).with(event)
expect(control).to receive(:system_event!).with(event)
end

def expect_exists?(location)
control.should_receive(:exists?).with(location)
expect(control).to receive(:exists?).with(location)
end

def expect_not_exists?(location)
control.should_receive(:not_exists?).with(location)
expect(control).to receive(:not_exists?).with(location)
end

def expect_wait_until_exists(*location)
control.should_receive(:wait_until_exists).with(*location)
expect(control).to receive(:wait_until_exists).with(*location)
end

def expect_wait_until_exists!(*location)
control.should_receive(:wait_until_exists!).with(*location)
expect(control).to receive(:wait_until_exists!).with(*location)
end

def expect_wait_until_not_exists(location)
control.should_receive(:wait_until_not_exists).with(location)
expect(control).to receive(:wait_until_not_exists).with(location)
end

def expect_wait_until_not_exists!(location, action)
control.should_receive(:wait_until_not_exists!).with(location)
expect(control).to receive(:wait_until_not_exists!).with(location)
end

def expect_until_not_exists!(element)
control.should_receive(:until_not_exists!).with(element).and_yield
expect(control).to receive(:until_not_exists!).with(element).and_yield
end
end
end
2 changes: 1 addition & 1 deletion lib/osaka/pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def self.create_document(filename, &block)

def new_document
super
if control.current_window_name == "Template Chooser"
if template_chooser?
control.set_current_window(do_and_wait_for_new_window {
control.click(at.button("Choose").window("Template Chooser"))
})
Expand Down
6 changes: 6 additions & 0 deletions lib/osaka/remotecontrol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def click_menu_bar(menu_item, menu_name)
click!(menu_item + at.menu(1) + menu_bar_location)
end

def click_menu_bar_by_name(menu_item_name, menu_name)
click_menu_bar(at.menu_item(menu_item_name), menu_name)
end

def set!(element, location, value)
encoded_value = (value.class == String) ? "\"#{value}\"" : value.to_s
check_output( system_event!("set #{element}#{construct_prefixed_location(location)} to #{encoded_value}"), "set")
Expand Down Expand Up @@ -241,6 +245,8 @@ def mac_version
:lion
when /^10.8.*/
:mountain_lion
when /^10.9.*/
:mavericks
else
:other
end
Expand Down
24 changes: 22 additions & 2 deletions lib/osaka/typicalapplication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ def duplicate
end

def duplicate_and_close_original
new_instance = duplicate
close
original_window_name = control.current_window_name
new_instance = duplicate
control.click_menu_bar_by_name(original_window_name, "Window")
close
@control = new_instance.control
end

Expand Down Expand Up @@ -199,6 +201,24 @@ def select_file_from_open_dialog(filename, dialog_location)
dialog.set_folder(File.dirname(filename))
dialog.select_file(File.basename(filename))
end

# jwg add tests
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this comment doesn't belong here, right?

def template_chooser?
focus
current_window_name = control.current_window_name
current_window_name == "Choose a Theme" ||
current_window_name == "Choose a Template" ||
current_window_name == "Template Chooser" ? true : false
end

def close_template_chooser_if_any
focus
if template_chooser?
window = at.window(control.current_window_name)
close
control.wait_until_not_exists!(window)
end
end

def raise_error_on_open_standard_windows(error_message)
raise Osaka::ApplicationWindowsMustBeClosed, error_message if ! control.standard_window_list.empty?
Expand Down
3 changes: 3 additions & 0 deletions make-gem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#/bin/bash
gem build osaka.gemspec
gem install osaka-0.4.8.gem
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shell script should probably be removed...

40 changes: 40 additions & 0 deletions run_each_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
UNIT_TESTS+=" ./spec/calculator_spec.rb"
UNIT_TESTS+=" ./spec/defaultssystem_spec.rb"
UNIT_TESTS+=" ./spec/keynote_flows_spec.rb"
UNIT_TESTS+=" ./spec/keynote_spec.rb"
UNIT_TESTS+=" ./spec/launchservices_spec.rb"
UNIT_TESTS+=" ./spec/location_spec.rb"
UNIT_TESTS+=" ./spec/mailmergeflow_spec.rb"
UNIT_TESTS+=" ./spec/numbers_spec.rb"
UNIT_TESTS+=" ./spec/osakaexpectations_spec.rb"
# UNIT_TESTS+=" ./spec/pages_spec.rb"
UNIT_TESTS+=" ./spec/preview_spec.rb"
UNIT_TESTS+=" ./spec/remotecontrol_spec.rb"
UNIT_TESTS+=" ./spec/scriptrunner_spec.rb"
UNIT_TESTS+=" ./spec/textedit_spec.rb"
UNIT_TESTS+=" ./spec/typicalapplication_spec.rb"
UNIT_TESTS+=" ./spec/typicalfinderdialog_spec.rb"
UNIT_TESTS+=" ./spec/typicalopendialog_spec.rb"
UNIT_TESTS+=" ./spec/typicalprintdialog_spec.rb"
UNIT_TESTS+=" ./spec/typicalsavedialog_spec.rb"

INTEGRATION_TESTS+=" ./spec/integration_calculator_spec.rb"
INTEGRATION_TESTS+=" ./spec/integration_keynote_spec.rb"
INTEGRATION_TESTS+=" ./spec/integration_numbers_spec.rb"
INTEGRATION_TESTS+=" ./spec/integration_preview_spec.rb"
INTEGRATION_TESTS+=" ./spec/integration_textedit_spec.rb"
## INTEGRATION_TESTS+=" ./spec/integration_pages_numbers_mail_merge_spec.rb"

export LANG=en_US.UTF-8

if [ "$1" == "u" ] ; then
ruby -S rspec $UNIT_TESTS

elif [ "$1" == "i" ] ; then
ruby -S rspec $INTEGRATION_TESTS
else
ruby -S rspec $UNIT_TESTS
ruby -S rspec $INTEGRATION_TESTS
fi


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise. You can do these with rake ?

Binary file removed spec/assets/01_first_slides.key
Binary file not shown.
Binary file removed spec/assets/02_second_slides.key
Binary file not shown.
Binary file removed spec/assets/03_third_slides.key
Binary file not shown.
Binary file added spec/assets/key-09/01_first_slides.key
Binary file not shown.
Binary file added spec/assets/key-09/02_second_slides.key
Binary file not shown.
Binary file added spec/assets/key-09/03_third_slides.key
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading