-
Notifications
You must be signed in to change notification settings - Fork 1
/
rails_test.iterm.applescript
executable file
·127 lines (112 loc) · 3.33 KB
/
rails_test.iterm.applescript
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
115
116
117
118
119
120
121
122
123
124
125
global ruby_initialization, project_folder, test_file, test_name, subtest_group
on run argv
if (count of argv) is 0 then
--DEBUGGING USE IN APPLESCRIPT EDITOR
set ruby_initialization to "19"
set project_folder to "/Users/btsai/git/workcloud/workcloud"
set test_file to "test/unit/company_test.rb"
set test_name to "test_display_name"
set subtest_group to null
else
--SHOULD HAVE 3 + 2 OPTIONAL ARGUMENTS PASSED OVER BY SUBLIME SCRIPT
set ruby_initialization to item 1 of argv
set project_folder to item 2 of argv
set test_file to item 3 of argv
set test_name to null
set subtest_group to null
if (count of argv) is 4 then
set test_name to item 4 of argv
else if (count of argv) is 5 then
set test_name to item 4 of argv
set subtest_group to item 5 of argv
end if
end if
tell application "iTerm"
set session_name to the last word in test_file
if test_name is not null then
set session_name to session_name & "-" & test_name
end if
set test_session to my existing_session_named(session_name)
if test_session is null then
set test_session to my new_session_named(session_name, ruby_initialization, project_folder)
end if
select test_session
tell test_session
activate
if my is_in_repeat_mode(test_session) then
set test_command to "y"
else
if subtest_group is not null then
set test_command to "ONLY=" & subtest_group & " "
else
set test_command to ""
end if
set test_command to test_command & "ruby " & test_file & ""
if test_name is not null and test_name is not "none" then
set test_command to test_command & " -n " & test_name
end if
set test_command to test_command & " -o"
end if
write text test_command
end tell
end tell
end run
on is_in_repeat_mode(_session)
set last_line to my last_line_in_session(text of _session)
if last_line is "Do you want to run this suite again [y/n]?" then
return true
else
return false
end if
end is_in_repeat_mode
on last_line_in_session(buffer_text)
set last_line to null
set session_lines to reverse of every paragraph of buffer_text
repeat
set first_word to first item of session_lines
if first_word is "" then
set session_lines to rest of session_lines
else
set last_line to first_word
exit repeat
end if
end repeat
return last_line
end last_line_in_session
on existing_session_named(name_to_find)
tell application "iTerm"
set test_session to null
repeat with _session in every session of the current terminal
if my session_is_named(_session, name_to_find) then
set test_session to _session
exit repeat
end if
end repeat
return test_session
end tell
end existing_session_named
on new_session_named(new_name)
tell application "iTerm"
tell the current terminal
launch session "Default Session"
set name of current session to new_name
tell current session
activate
write text ruby_initialization
write text "cd " & project_folder & ""
end tell
return current session
end tell
end tell
end new_session_named
on session_is_named(_session, name_to_find)
set _session_name to name of _session
set match_length to length of name_to_find
if length of _session_name ³ match_length then
set base_name to text 1 thru match_length of _session_name
if base_name is name_to_find then
return true
end if
end if
return false
end session_is_named