osaka 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/osaka.rb +7 -0
- data/lib/osaka/mailmergeflow.rb +7 -11
- data/lib/osaka/numbers.rb +24 -5
- data/lib/osaka/pages.rb +5 -0
- data/lib/osaka/preview.rb +28 -0
- data/lib/osaka/typicalapplication.rb +7 -0
- data/lib/osaka/typicalfinderdialog.rb +1 -1
- data/lib/osaka/typicalopendialog.rb +3 -2
- data/lib/osaka/version.rb +1 -1
- data/spec/integration_numbers_spec.rb +17 -0
- data/spec/integration_pages_numbers_mail_merge_spec.rb +13 -10
- data/spec/mailmergeflow_spec.rb +5 -9
- data/spec/numbers_spec.rb +26 -15
- data/spec/pages_spec.rb +9 -2
- data/spec/preview_spec.rb +30 -0
- data/spec/typicalapplication_spec.rb +12 -0
- data/spec/typicalopendialog_spec.rb +1 -1
- metadata +5 -2
data/lib/osaka.rb
CHANGED
@@ -7,12 +7,19 @@ require 'osaka/typicalfinderdialog'
|
|
7
7
|
require 'osaka/typicalopendialog'
|
8
8
|
require 'osaka/typicalsavedialog'
|
9
9
|
require 'osaka/typicalprintdialog'
|
10
|
+
|
11
|
+
#Specific application
|
10
12
|
require 'osaka/pages'
|
11
13
|
require 'osaka/numbers'
|
12
14
|
require 'osaka/keynote'
|
13
15
|
require 'osaka/calculator'
|
14
16
|
require 'osaka/textedit'
|
17
|
+
require 'osaka/preview'
|
18
|
+
|
19
|
+
# Automation flots
|
15
20
|
require 'osaka/mailmergeflow'
|
16
21
|
require 'osaka/keynoteflow'
|
22
|
+
|
23
|
+
# RSpec helpers
|
17
24
|
require 'osaka/osakaexpectations'
|
18
25
|
|
data/lib/osaka/mailmergeflow.rb
CHANGED
@@ -2,21 +2,17 @@
|
|
2
2
|
module CommonFlows
|
3
3
|
|
4
4
|
def self.number_and_pages_mail_merge(numbers_file, pages_file, output_file)
|
5
|
-
numbers = Osaka::Numbers.new
|
6
|
-
pages = Osaka::Pages.new
|
7
|
-
|
8
|
-
numbers.open(numbers_file)
|
9
|
-
yield numbers if block_given?
|
10
|
-
numbers.save
|
11
5
|
|
6
|
+
if block_given?
|
7
|
+
Osaka::Numbers.create_document(numbers_file) { |numbers|
|
8
|
+
yield numbers
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
pages = Osaka::Pages.new
|
12
13
|
pages.open(pages_file)
|
13
14
|
pages.mail_merge_to_pdf(output_file)
|
14
|
-
|
15
|
-
numbers.close(:dont_save)
|
16
15
|
pages.close(:dont_save)
|
17
|
-
|
18
|
-
numbers.quit(:dont_save)
|
19
16
|
pages.quit(:dont_save)
|
20
|
-
|
21
17
|
end
|
22
18
|
end
|
data/lib/osaka/numbers.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
|
2
2
|
module Osaka
|
3
|
+
|
4
|
+
class Location
|
5
|
+
def cell(name)
|
6
|
+
create_location_with_added_name("cell", name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def table(name)
|
10
|
+
create_location_with_added_name("table", name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
class Numbers < TypicalApplication
|
4
15
|
|
5
16
|
def initialize
|
@@ -13,17 +24,25 @@ module Osaka
|
|
13
24
|
})
|
14
25
|
end
|
15
26
|
|
16
|
-
def self.create_document(filename)
|
27
|
+
def self.create_document(filename, &block)
|
17
28
|
numbers = Osaka::Numbers.new
|
18
|
-
numbers.
|
19
|
-
yield numbers
|
20
|
-
numbers.save_as(filename)
|
21
|
-
numbers.close
|
29
|
+
numbers.create_document(filename, &block)
|
22
30
|
end
|
23
31
|
|
24
32
|
def fill_cell(column, row, value)
|
33
|
+
if (column > column_count)
|
34
|
+
set_column_count(column)
|
35
|
+
end
|
25
36
|
control.tell("tell document 1; tell sheet 1; tell table 1; set value of cell #{column} of row #{row} to \"#{value}\"; end tell; end tell; end tell")
|
26
37
|
end
|
27
38
|
|
39
|
+
def column_count
|
40
|
+
control.tell("tell document 1; tell sheet 1; tell table 1; get column count; end tell; end tell; end tell").to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_column_count(amount)
|
44
|
+
control.tell("tell document 1; tell sheet 1; tell table 1; set column count to #{amount}; end tell; end tell; end tell")
|
45
|
+
end
|
46
|
+
|
28
47
|
end
|
29
48
|
end
|
data/lib/osaka/pages.rb
CHANGED
@@ -77,6 +77,11 @@ module Osaka
|
|
77
77
|
control.keystroke(text)
|
78
78
|
end
|
79
79
|
|
80
|
+
def self.create_document(filename, &block)
|
81
|
+
numbers = Osaka::Pages.new
|
82
|
+
numbers.create_document(filename, &block)
|
83
|
+
end
|
84
|
+
|
80
85
|
def set_mail_merge_document(filename)
|
81
86
|
inspector.change_mail_merge_source
|
82
87
|
control.wait_until_exists(at.sheet(1))
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Osaka
|
4
|
+
|
5
|
+
class Preview < TypicalApplication
|
6
|
+
|
7
|
+
attr_accessor :control
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super "Preview"
|
11
|
+
end
|
12
|
+
|
13
|
+
def pdf_content
|
14
|
+
control.get!("value", at.static_text(1).scroll_area(1).splitter_group(1))
|
15
|
+
end
|
16
|
+
|
17
|
+
def open(filename)
|
18
|
+
control.click_menu_bar(at.menu_item("Open…"), "File").wait_until_exists(at.window("Open"))
|
19
|
+
dialog = create_dialog(TypicalOpenDialog, at.window("Open"))
|
20
|
+
dialog.set_folder(File.dirname(filename))
|
21
|
+
new_window = do_and_wait_for_new_window {
|
22
|
+
dialog.select_file(File.basename(filename))
|
23
|
+
}
|
24
|
+
control.set_current_window(new_window)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -83,6 +83,13 @@ module Osaka
|
|
83
83
|
control.focus
|
84
84
|
end
|
85
85
|
|
86
|
+
def create_document(filename)
|
87
|
+
new_document
|
88
|
+
yield self
|
89
|
+
save_as(filename)
|
90
|
+
close
|
91
|
+
end
|
92
|
+
|
86
93
|
def duplicate_available?
|
87
94
|
control.exists?(at.menu_item("Duplicate").menu(1).menu_bar_item("File").menu_bar(1))
|
88
95
|
end
|
@@ -10,9 +10,9 @@ module Osaka
|
|
10
10
|
|
11
11
|
def set_folder(pathname)
|
12
12
|
return if pathname == "."
|
13
|
-
|
14
13
|
control.keystroke("g", [ :command, :shift ]).wait_until_exists(at.sheet(1))
|
15
14
|
control.set("value", at.text_field(1).sheet(1), pathname)
|
15
|
+
sleep(1) # Seems this must be here due to the sucking Apple UI. Not found something else to wait for!
|
16
16
|
control.click(at.button("Go").sheet(1)).wait_until_not_exists(at.sheet(1))
|
17
17
|
end
|
18
18
|
end
|
@@ -36,7 +36,7 @@ module Osaka
|
|
36
36
|
|
37
37
|
def select_file_by_row(row)
|
38
38
|
raise(OpenDialogCantSelectFile, "Tried to select a file, but it either doesn't exist or is greyed out") if (greyed_out?(row))
|
39
|
-
control.set!("selected", at.row(
|
39
|
+
control.set!("selected", at.row(row) + file_list_location, true)
|
40
40
|
end
|
41
41
|
|
42
42
|
def amount_of_files_in_list
|
@@ -49,11 +49,12 @@ module Osaka
|
|
49
49
|
control.get!("value", field_location_from_row(row))
|
50
50
|
end
|
51
51
|
|
52
|
-
def select_file(filename)
|
52
|
+
def select_file(filename)
|
53
53
|
amount_of_files_in_list.times() { |row|
|
54
54
|
if filename_at(row+1) == filename
|
55
55
|
select_file_by_row(row+1)
|
56
56
|
click_open
|
57
|
+
return
|
57
58
|
end
|
58
59
|
}
|
59
60
|
end
|
data/lib/osaka/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'osaka'
|
3
|
+
|
4
|
+
describe "Integration tests for Numbers" do
|
5
|
+
|
6
|
+
it "Should be able to fill in large index cells" do
|
7
|
+
|
8
|
+
Dir.mktmpdir { |dir|
|
9
|
+
|
10
|
+
Osaka::Numbers.create_document(File.join(dir, "temp.numbers")) { |doc|
|
11
|
+
doc.fill_cell(12, 1, "Data")
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -17,23 +17,26 @@ describe "Integration of mail merge flow with Pages and Numbers" do
|
|
17
17
|
|
18
18
|
it "Should mail merge the assets and generate a PDF" do
|
19
19
|
|
20
|
-
Osaka::Numbers.create_document
|
20
|
+
Osaka::Numbers.create_document(@numbers_filename) { |doc|
|
21
21
|
doc.fill_cell(2, 1, "Data")
|
22
22
|
doc.fill_cell(2, 2, "Hello World")
|
23
23
|
doc.fill_cell(2, 3, "of Data")
|
24
24
|
doc.fill_cell(2, 4, "in Numbers")
|
25
25
|
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
pages.save_as(@pages_template_filename)
|
34
|
-
pages.close
|
35
|
-
|
27
|
+
Osaka::Pages.create_document(@pages_template_filename) { |doc|
|
28
|
+
doc.set_mail_merge_document(@numbers_filename)
|
29
|
+
doc.type("Hello World! This is pages. We're going to mail merge!\r\r")
|
30
|
+
doc.mail_merge_field("Data");
|
31
|
+
}
|
32
|
+
|
36
33
|
CommonFlows::number_and_pages_mail_merge(@numbers_filename, @pages_template_filename, @pdf_output_file)
|
37
34
|
File.exists?(@pdf_output_file).should == true
|
35
|
+
|
36
|
+
preview = Osaka::Preview.new
|
37
|
+
preview.open(@pdf_output_file)
|
38
|
+
preview.pdf_content.should include("Hello World")
|
39
|
+
preview.close
|
40
|
+
preview.quit
|
38
41
|
end
|
39
42
|
end
|
data/spec/mailmergeflow_spec.rb
CHANGED
@@ -7,19 +7,15 @@ describe "Mail Merge to PDF common flow" do
|
|
7
7
|
let(:mock_pages) { mock("Pages") }
|
8
8
|
|
9
9
|
it "Should do a good mail merge with Pages and Keynote flow" do
|
10
|
-
|
10
|
+
|
11
|
+
Osaka::Numbers.should_receive(:create_document).with("/template/numbers").and_yield(mock_numbers)
|
12
|
+
|
11
13
|
Osaka::Pages.should_receive(:new).and_return(mock_pages)
|
12
14
|
|
13
|
-
mock_numbers.should_receive(:open).with("/template/numbers")
|
14
|
-
mock_numbers.should_receive(:save)
|
15
|
-
|
16
15
|
mock_pages.should_receive(:open).with("/template/pages")
|
17
16
|
mock_pages.should_receive(:mail_merge_to_pdf).with("/output/file.pdf")
|
18
|
-
|
19
|
-
mock_numbers.should_receive(:close).with(:dont_save)
|
20
|
-
mock_pages.should_receive(:close).with(:dont_save)
|
21
17
|
|
22
|
-
|
18
|
+
mock_pages.should_receive(:close).with(:dont_save)
|
23
19
|
mock_pages.should_receive(:quit).with(:dont_save)
|
24
20
|
|
25
21
|
CommonFlows.number_and_pages_mail_merge("/template/numbers", "/template/pages", "/output/file.pdf") {}
|
@@ -28,7 +24,7 @@ describe "Mail Merge to PDF common flow" do
|
|
28
24
|
it "Should yield for filling in the numbers fields" do
|
29
25
|
mock_numbers.as_null_object
|
30
26
|
mock_pages.as_null_object
|
31
|
-
Osaka::Numbers.should_receive(:
|
27
|
+
Osaka::Numbers.should_receive(:create_document).and_yield(mock_numbers)
|
32
28
|
Osaka::Pages.should_receive(:new).and_return(mock_pages)
|
33
29
|
|
34
30
|
retrieved_numbers = nil
|
data/spec/numbers_spec.rb
CHANGED
@@ -8,11 +8,30 @@ describe "Osaka::Numbers" do
|
|
8
8
|
subject { Osaka::Numbers.new }
|
9
9
|
let(:control) { subject.control = mock("RemoteControl").as_null_object}
|
10
10
|
|
11
|
-
it "Should be able to
|
11
|
+
it "Should be able to get the column count" do
|
12
|
+
expect_tell('tell document 1; tell sheet 1; tell table 1; get column count; end tell; end tell; end tell').and_return("10")
|
13
|
+
subject.column_count.should == 10
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Should be able to set the column count to a certain value" do
|
17
|
+
expect_tell('tell document 1; tell sheet 1; tell table 1; set column count to 10; end tell; end tell; end tell')
|
18
|
+
subject.set_column_count(10)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "Should be able to fill in data in cells" do
|
22
|
+
subject.should_receive(:column_count).and_return(10)
|
12
23
|
expect_tell('tell document 1; tell sheet 1; tell table 1; set value of cell 1 of row 2 to "30"; end tell; end tell; end tell')
|
13
24
|
subject.fill_cell(1, 2, "30")
|
14
25
|
end
|
15
26
|
|
27
|
+
it "Will change the column count when the cell is outside of the range of the current column count" do
|
28
|
+
subject.should_receive(:column_count).and_return(5)
|
29
|
+
subject.should_receive(:set_column_count).with(6)
|
30
|
+
expect_tell('tell document 1; tell sheet 1; tell table 1; set value of cell 6 of row 2 to "30"; end tell; end tell; end tell')
|
31
|
+
subject.fill_cell(6, 2, "30")
|
32
|
+
|
33
|
+
end
|
34
|
+
|
16
35
|
it "Should be able to select blank from the template choser" do
|
17
36
|
expect_set_current_window("Template Choser")
|
18
37
|
subject.should_receive(:do_and_wait_for_new_window).and_return("Template Choser")
|
@@ -22,20 +41,12 @@ describe "Osaka::Numbers" do
|
|
22
41
|
subject.new_document
|
23
42
|
end
|
24
43
|
|
25
|
-
it "Should be able to
|
26
|
-
|
27
|
-
|
28
|
-
subject.should_receive(:new_document)
|
29
|
-
subject.should_receive(:method_call_from_code_block)
|
30
|
-
subject.should_receive(:save_as).with("filename")
|
31
|
-
subject.should_receive(:close)
|
44
|
+
it "Should be able to use a class method for creating documents quickly" do
|
45
|
+
Osaka::Numbers.should_receive(:new).any_number_of_times.and_return(mock("App"))
|
46
|
+
subject.should_receive(:create_document)
|
32
47
|
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
|
48
|
+
Osaka::Numbers.create_document("filename") { |doc|
|
49
|
+
}
|
37
50
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
51
|
+
|
41
52
|
end
|
data/spec/pages_spec.rb
CHANGED
@@ -14,10 +14,17 @@ describe "Osaka::Pages" do
|
|
14
14
|
it "Should be able to type in the file" do
|
15
15
|
expect_keystroke("Hello")
|
16
16
|
subject.type("Hello")
|
17
|
-
end
|
18
|
-
|
17
|
+
end
|
19
18
|
end
|
20
19
|
|
20
|
+
it "Should be able to use a class method for creating documents quickly" do
|
21
|
+
Osaka::Pages.should_receive(:new).any_number_of_times.and_return(mock("App"))
|
22
|
+
subject.should_receive(:create_document)
|
23
|
+
|
24
|
+
Osaka::Pages.create_document("filename") { |doc|
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
21
28
|
it "Should be able to do mail merge to a PDF flow" do
|
22
29
|
|
23
30
|
mail_merge_dialog = mock("Pages Mail Merge Dialog")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'osaka'
|
3
|
+
|
4
|
+
describe "Preview application for reading PDFs" do
|
5
|
+
|
6
|
+
include(*Osaka::OsakaExpectations)
|
7
|
+
|
8
|
+
subject { Osaka::Preview.new }
|
9
|
+
let(:control) { subject.control = mock("RemoteControl", :mac_version => :mountain_lion)}
|
10
|
+
|
11
|
+
it "Can get the text context of a PDF document" do
|
12
|
+
expect_get!("value", at.static_text(1).scroll_area(1).splitter_group(1)).and_return("Blah")
|
13
|
+
subject.pdf_content.should == "Blah"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Can open a PDF file via the menu instead of the AppleScript 'open' as that one is buggy" do
|
17
|
+
open_dialog = mock("Open Dialog")
|
18
|
+
|
19
|
+
expect_click_menu_bar(at.menu_item("Open…"), "File")
|
20
|
+
expect_wait_until_exists(at.window("Open"))
|
21
|
+
subject.stub(:do_and_wait_for_new_window).and_yield.and_return("window name")
|
22
|
+
subject.should_receive(:create_dialog).with(Osaka::TypicalOpenDialog, at.window("Open")).and_return(open_dialog)
|
23
|
+
open_dialog.should_receive(:set_folder).with("dir")
|
24
|
+
open_dialog.should_receive(:select_file).with("filename")
|
25
|
+
expect_set_current_window("window name")
|
26
|
+
|
27
|
+
subject.open("dir/filename")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -68,6 +68,18 @@ describe "Osaka::TypicalApplication" do
|
|
68
68
|
subject.new_document
|
69
69
|
end
|
70
70
|
|
71
|
+
it "Should be able to easily create a document, put something, save it, and close it again" do
|
72
|
+
|
73
|
+
subject.should_receive(:new_document)
|
74
|
+
subject.should_receive(:method_call_from_code_block)
|
75
|
+
subject.should_receive(:save_as).with("filename")
|
76
|
+
subject.should_receive(:close)
|
77
|
+
|
78
|
+
subject.create_document("filename") { |doc|
|
79
|
+
doc.method_call_from_code_block
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
71
83
|
end
|
72
84
|
|
73
85
|
context "Quiting and closing and checking whether the app is still running" do
|
@@ -23,7 +23,7 @@ describe "Osaka::TypicalOpenDialog" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "Should be able to select a file from Row 3" do
|
26
|
-
subject.should_receive(:amount_of_files_in_list).and_return(
|
26
|
+
subject.should_receive(:amount_of_files_in_list).and_return(10)
|
27
27
|
subject.should_receive(:filename_at).and_return("filename", "filename2", "filename3")
|
28
28
|
subject.should_receive(:select_file_by_row).with(3)
|
29
29
|
subject.should_receive(:click_open)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: osaka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.4
|
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-
|
13
|
+
date: 2012-12-05 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/osaka/numbers.rb
|
56
56
|
- lib/osaka/osakaexpectations.rb
|
57
57
|
- lib/osaka/pages.rb
|
58
|
+
- lib/osaka/preview.rb
|
58
59
|
- lib/osaka/remotecontrol.rb
|
59
60
|
- lib/osaka/scriptrunner.rb
|
60
61
|
- lib/osaka/textedit.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- spec/calculator_spec.rb
|
72
73
|
- spec/integration_calculator_spec.rb
|
73
74
|
- spec/integration_keynote_spec.rb
|
75
|
+
- spec/integration_numbers_spec.rb
|
74
76
|
- spec/integration_pages_numbers_mail_merge_spec.rb
|
75
77
|
- spec/integration_textedit_spec.rb
|
76
78
|
- spec/keynote_flows_spec.rb
|
@@ -80,6 +82,7 @@ files:
|
|
80
82
|
- spec/numbers_spec.rb
|
81
83
|
- spec/osakaexpectations_spec.rb
|
82
84
|
- spec/pages_spec.rb
|
85
|
+
- spec/preview_spec.rb
|
83
86
|
- spec/remotecontrol_spec.rb
|
84
87
|
- spec/scriptrunner_spec.rb
|
85
88
|
- spec/textedit_spec.rb
|