forked from Marketcircle/AXElements
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_application.rb
114 lines (92 loc) · 2.74 KB
/
test_application.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding: utf-8 -*-
require 'test/helper'
require 'ax/application'
class TestAXApplication < Minitest::Test
def app
@app ||= AX::Application.new REF
end
def running_app
@running_app ||=
NSRunningApplication.runningApplicationWithProcessIdentifier app.pid
end
def test_subclass_of_element
assert_equal AX::Element, AX::Application.superclass
end
def test_inspect
assert_match /children/, app.inspect
assert_match /\spid=\d+/, app.inspect
assert_match /\sfocused\[(?:✔|✘)\]/, app.inspect
end
def tset_action_methods_forward_to_perform
def app.perform name
[:cracker_jacks, name]
end
assert_equal [:cracker_jacks, :terminate], app.terminate
assert_equal [:cracker_jacks, :force_terminate], app.terminate!
assert_equal [:cracker_jacks, :hide], app.hide
assert_equal [:cracker_jacks, :unhide], app.unhide
end
def test_terminate
got_called = false
mock = Object.new
mock.define_singleton_method(:terminate) { got_called = true }
mock.define_singleton_method(:terminated?) { false }
app.instance_variable_set :@app, mock
app.perform :terminate
assert got_called
end
def test_force_terminate
got_called = false
mock = Object.new
mock.define_singleton_method(:forceTerminate) { got_called = true }
mock.define_singleton_method(:terminated? ) { false }
app.instance_variable_set :@app, mock
app.perform :force_terminate
assert got_called
end
def test_writable_handles_focused_and_hidden
assert app.writable? :focused?
assert app.writable? :focused
assert app.writable? :hidden
assert app.writable? :hidden?
end
def test_attribute_calls_super
assert_equal 'AXElementsTester', app.title
end
def test_set_calls_super
called_super = false
app.define_singleton_method :set do |attr, value|
called_super = true if attr == :thingy && value == 'pie'
end
app.set :thingy, 'pie'
assert called_super
end
def test_writable_calls_super
called_super = false
app.define_singleton_method :writable? do |attr|
called_super = true if attr == :brain
end
app.writable? :brain
assert called_super
end
def test_perform_calls_super
called_super = false
app.define_singleton_method :perform do |name|
called_super = true if name == :some_action
end
app.perform :some_action
assert called_super
end
def test_bundle_identifier
assert_equal running_app.bundleIdentifier, app.bundle_identifier
end
def test_info_plist
assert_equal 'hmmmmm', app.info_plist['CFBundleIconFile']
end
def test_version
assert_equal '1.0', app.version
end
def test_ancestor
assert_nil app.ancestor(:menu)
end
end