terminitor 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ require File.expand_path('../teststrap', __FILE__)
2
+
3
+ context "AbstractCore" do
4
+
5
+ context "setup!" do
6
+ setup do
7
+ any_instance_of(Terminitor::AbstractCore) do |core|
8
+ stub(core).load_termfile('/path/to') { { :setup => ['ls','ok'] } }
9
+ mock(core).active_window { true }.times 3
10
+ end
11
+ end
12
+ setup { @core = Terminitor::AbstractCore.new('/path/to') }
13
+ setup { mock(@core).execute_command("cd #{Dir.pwd}", :in => true)}
14
+ setup { mock(@core).execute_command('ls', :in => true) }
15
+ setup { mock(@core).execute_command('ok', :in => true) }
16
+ asserts("ok") { @core.setup! }
17
+ end
18
+
19
+ context "process!" do
20
+ context "without default" do
21
+ setup do
22
+ any_instance_of(Terminitor::AbstractCore) do |core|
23
+ stub(core).load_termfile('/path/to') { {:windows => {'tab1' => ['ls', 'ok'], 'default' => [] } } }
24
+ end
25
+ end
26
+ setup { @core = Terminitor::AbstractCore.new('/path/to') }
27
+ setup { mock(@core).run_in_window(['ls', 'ok']) }
28
+ asserts("ok") { @core.process! }
29
+ end
30
+
31
+ context "with default" do
32
+ setup do
33
+ any_instance_of(Terminitor::AbstractCore) do |core|
34
+ stub(core).load_termfile('/path/to') { {:windows => {'tab1' => ['ls', 'ok'], 'default' => ['echo'] } } }
35
+ end
36
+ end
37
+ setup { @core = Terminitor::AbstractCore.new('/path/to') }
38
+ setup { mock(@core).run_in_window(['echo'], :default => true) }
39
+ setup { mock(@core).run_in_window(['ls', 'ok']) }
40
+ asserts("ok") { @core.process! }
41
+ end
42
+
43
+ end
44
+
45
+ context "run_in_window" do
46
+ setup do
47
+ any_instance_of(Terminitor::AbstractCore) do |core|
48
+ stub(core).load_termfile('/path/to') { true }
49
+ end
50
+ @core = Terminitor::AbstractCore.new('/path/to')
51
+ end
52
+
53
+ context "with default" do
54
+ setup { mock(@core).open_window { true } }
55
+ setup { mock(@core).open_tab { true } }
56
+ setup { mock(@core).execute_command('ls', :in => true) }
57
+ setup { mock(@core).execute_command('ok', :in => true) }
58
+ asserts("ok") { @core.run_in_window('tab' => ['ls','ok']) }
59
+ end
60
+
61
+ context "without default" do
62
+ setup { mock(@core).open_tab { true } }
63
+ setup { mock(@core).execute_command('ls', :in => true) }
64
+ setup { mock(@core).execute_command('ok', :in => true) }
65
+ asserts("ok") { @core.run_in_window({'tab' => ['ls','ok']}, :default => true) }
66
+ end
67
+
68
+
69
+ context "with working_dir" do
70
+ setup { stub(Dir).pwd { '/tmp/path' } }
71
+ setup { mock(@core).execute_command("cd \"/tmp/path\"", :in => '/tmp/path') }
72
+ setup { mock(@core).execute_command('ls', :in => '/tmp/path') }
73
+ asserts("ok") { @core.run_in_window({'tab' => ['ls']}) }
74
+ end
75
+ end
76
+
77
+
78
+
79
+ end
data/test/cli_test.rb ADDED
@@ -0,0 +1,121 @@
1
+ require File.expand_path('../teststrap', __FILE__)
2
+
3
+ context "Terminitor" do
4
+ setup { @yaml = File.read(File.expand_path('../fixtures/foo.yml', __FILE__)) }
5
+ setup { @template = File.read(File.expand_path('../../lib/templates/example.yml.tt', __FILE__)) }
6
+ setup { FakeFS.activate! }
7
+ setup { FileUtils.mkdir_p(File.join(ENV["HOME"],'.terminitor')) }
8
+ teardown { FakeFS.deactivate! }
9
+
10
+ context "help" do
11
+ setup { capture(:stdout) { Terminitor::Cli.start(['-h']) } }
12
+ asserts_topic.matches %r{start PROJECT_NAME}
13
+ asserts_topic.matches %r{init}
14
+ asserts_topic.matches %r{edit PROJECT_NAME}
15
+ end
16
+
17
+ context "list" do
18
+ setup { @path = "#{ENV['HOME']}/.terminitor/" }
19
+ setup { File.open(File.join(@path,'foo.yml'),"w") { |f| f.puts @template } }
20
+ setup { File.open(File.join(@path,'bar.yml'),"w") { |f| f.puts @template } }
21
+ setup { capture(:stdout) { Terminitor::Cli.start(['list']) } }
22
+ asserts_topic.matches %r{foo - COMMENT OF SCRIPT HERE}
23
+ asserts_topic.matches %r{bar - COMMENT OF SCRIPT HERE}
24
+ end
25
+
26
+ context "init" do
27
+ setup { capture(:stdout) { Terminitor::Cli.start(['init']) } }
28
+ asserts("creates .terminitor") { File.exists?("#{ENV['HOME']}/.terminitor") }
29
+ end
30
+
31
+ context "edit" do
32
+ setup { FakeFS.deactivate! }
33
+ setup { `rm -rf #{ENV['HOME']}/.terminitor/test_foo_bar2.yml`}
34
+ setup { `rm -rf #{ENV['HOME']}/.terminitor/test_foo_bar2.term`}
35
+ teardown { `rm -rf /tmp/sample_project` }
36
+ teardown { `rm -rf #{ENV['HOME']}/.terminitor/test_foo_bar2.yml`}
37
+ teardown { `rm -rf #{ENV['HOME']}/.terminitor/test_foo_bar2.term`}
38
+ context "for project" do
39
+ context "for yaml" do
40
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("#{ENV['HOME']}/.terminitor/test_foo_bar2.yml",nil) { true }.once }
41
+ setup { capture(:stdout) { Terminitor::Cli.start(['edit','test_foo_bar2', '-s=yml']) } }
42
+ asserts_topic.matches %r{create}
43
+ asserts_topic.matches %r{test_foo_bar2.yml}
44
+ asserts("has term template") { File.read(File.join(ENV['HOME'],'.terminitor','test_foo_bar2.yml')) }.matches %r{- tab1}
45
+ end
46
+
47
+ context "for term" do
48
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("#{ENV['HOME']}/.terminitor/test_foo_bar2.term",nil) { true }.once }
49
+ setup { capture(:stdout) { Terminitor::Cli.start(['edit','test_foo_bar2', '-s=term']) } }
50
+ asserts_topic.matches %r{create}
51
+ asserts_topic.matches %r{test_foo_bar2.term}
52
+ asserts("has term template") { File.read(File.join(ENV['HOME'],'.terminitor','test_foo_bar2.term')) }.matches %r{setup}
53
+ end
54
+
55
+ end
56
+
57
+ context "for Termfile" do
58
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("/tmp/sample_project/Termfile",nil) { true }.once }
59
+ setup { capture(:stdout) { Terminitor::Cli.start(['edit','-s=yml','-r=/tmp/sample_project']) } }
60
+ asserts_topic.matches %r{create}
61
+ asserts_topic.matches %r{Termfile}
62
+ asserts("has term template") { File.read('/tmp/sample_project/Termfile') }.matches %r{setup}
63
+ end
64
+
65
+ context "for editor flag" do
66
+ setup { FileUtils.mkdir_p('/tmp/sample_project') }
67
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor('/tmp/sample_project/Termfile','nano') { true }.once }
68
+ asserts("runs nano") { capture(:stdout) { Terminitor::Cli.start(['edit','-r=/tmp/sample_project','-c=nano']) } }
69
+ end
70
+
71
+ end
72
+
73
+ context "create" do
74
+ setup { mock.instance_of(Terminitor::Cli).invoke(:edit, [], 'root' => '/tmp/sample_project') { true }.once }
75
+ asserts('calls open') { capture(:stdout) { Terminitor::Cli.start(['create','-r=/tmp/sample_project']) } }
76
+ end
77
+
78
+
79
+ context "open" do
80
+ setup { mock.instance_of(Terminitor::Cli).invoke(:edit, [""], {'syntax' => 'term', 'root' => '/tmp/sample_project'}) { true }.once }
81
+ setup { capture(:stdout) { Terminitor::Cli.start(['open','-r=/tmp/sample_project']) } }
82
+ asserts_topic.matches %r{'open' is now deprecated. Please use 'edit' instead}
83
+ end
84
+
85
+ context "delete" do
86
+ context "directory Termfile" do
87
+ setup { FileUtils.mkdir_p('/tmp/sample_project') }
88
+ setup { FileUtils.touch("/tmp/sample_project/Termfile") }
89
+ setup { capture(:stdout) { Terminitor::Cli.start(['delete',"-r=/tmp/sample_project"]) } }
90
+ asserts("Termfile") { File.exists?("/tmp/sample_project/Termfile") }.not!
91
+ end
92
+
93
+ context "for yaml" do
94
+ setup { FileUtils.touch("#{ENV['HOME']}/.terminitor/delete_this.yml") }
95
+ setup { capture(:stdout) { Terminitor::Cli.start(['delete','delete_this', '-s=yml']) } }
96
+ asserts(" script") { File.exists?("#{ENV['HOME']}/.terminitor/delete_this.yml") }.not!
97
+ end
98
+
99
+ context "for term" do
100
+ setup { FileUtils.touch("#{ENV['HOME']}/.terminitor/delete_this.term") }
101
+ setup { capture(:stdout) { Terminitor::Cli.start(['delete','delete_this']) } }
102
+ asserts("script") { File.exists?("#{ENV['HOME']}/.terminitor/delete_this.term") }.not!
103
+ end
104
+ end
105
+
106
+ context "setup" do
107
+ setup { mock.instance_of(Terminitor::Cli).execute_core(:setup!,'project') {true } }
108
+ asserts("calls execute_core") { Terminitor::Cli.start(['setup','project']) }
109
+ end
110
+
111
+
112
+ context "start" do
113
+ setup { mock.instance_of(Terminitor::Cli).execute_core(:process!,'project') {true } }
114
+ asserts("calls execute_core") { Terminitor::Cli.start(['start','project']) }
115
+ end
116
+
117
+ context "fetch" do
118
+ setup { mock.instance_of(Terminitor::Cli).fetch_repo('achiu','terminitor', 'root' => '.', 'setup' => true) { true } }
119
+ asserts("run setup in project dir") { capture(:stdout) { Terminitor::Cli.start(['fetch','achiu','terminitor'])} }
120
+ end
121
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../../teststrap',__FILE__)
2
+ if platform?('linux')
3
+ require 'dbus'
4
+ context "KonsoleCore" do
5
+ # Stub out the initialization
6
+ setup do
7
+ bus = Object.new
8
+ @konsole_service = Object.new
9
+ @konsole = Object.new
10
+ mock(DBus::SessionBus).instance { bus }
11
+ mock(bus).service("org.kde.konsole") { @konsole_service }
12
+ any_instance_of(Terminitor::KonsoleCore) do |core|
13
+ stub(core).get_konsole { @konsole }
14
+ stub(core).load_termfile('/path/to') { true }
15
+ end
16
+ end
17
+ setup { @konsole_core = Terminitor::KonsoleCore.new('/path/to') }
18
+
19
+ context "open_tab" do
20
+ setup do
21
+ mock(@konsole).newSession { 1 }
22
+ session_object = { "org.kde.konsole.Session" => Object.new }
23
+ mock(@konsole_service).object("/Sessions/1") { session_object }
24
+ mock(session_object).introspect { true }
25
+ end
26
+ asserts("returns last tab") { @konsole_core.open_tab }
27
+ end
28
+
29
+ context "open_window" do
30
+ setup do
31
+ mock(@konsole).currentSession { 2 }
32
+ session_object = { "org.kde.konsole.Session" => Object.new }
33
+ mock(@konsole_service).object("/Sessions/2") { session_object }
34
+ mock(session_object).introspect { true }
35
+ end
36
+ asserts("returns last tab") { @konsole_core.open_window }
37
+ end
38
+
39
+ context "execute_command" do
40
+ @tab = Object.new
41
+ context "carriage return missing" do
42
+ setup do
43
+ mock(@tab).sendText("hasta\n") { true }
44
+ end
45
+ asserts("executes command") { @konsole_core.execute_command('hasta', :in => @tab) }
46
+ end
47
+
48
+ context "carriage return present" do
49
+ setup do
50
+ mock(@tab).sendText("hasta\n") { true }
51
+ end
52
+ asserts("executes command") { @konsole_core.execute_command("hasta\n", :in => @tab) }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path('../../teststrap',__FILE__)
2
+
3
+ if platform?("darwin") # Only run test if it's darwin
4
+ context "MacCore" do
5
+ # Stub out the initialization
6
+ setup do
7
+ terminal = Object.new
8
+ stub(terminal).windows { true }
9
+ any_instance_of(Terminitor::MacCore) do |core|
10
+ stub(core).app('Terminal') { terminal }
11
+ stub(core).load_termfile('/path/to') { true }
12
+ end
13
+ end
14
+ setup { @mac_core = Terminitor::MacCore.new('/path/to') }
15
+
16
+ context "terminal_process" do
17
+ setup do
18
+ process = Object.new
19
+ mock(process).application_processes { { "Terminal.app" => true } }
20
+ mock(@mac_core).app('System Events') { process }
21
+ end
22
+ asserts("calls System Events") { @mac_core.terminal_process }
23
+ end
24
+
25
+ context "open_tab" do
26
+ setup do
27
+ process = Object.new
28
+ mock(process).keystroke('t', :using => :command_down)
29
+ mock(@mac_core).return_last_tab { true }
30
+ mock(@mac_core).terminal_process { process }
31
+ end
32
+ asserts("returns last tab") { @mac_core.open_tab }
33
+ end
34
+
35
+ context "open_window" do
36
+ setup do
37
+ process = Object.new
38
+ mock(process).keystroke('n', :using => :command_down)
39
+ mock(@mac_core).return_last_tab { true }
40
+ mock(@mac_core).terminal_process { process }
41
+ end
42
+ asserts("returns last tab") { @mac_core.open_window }
43
+ end
44
+
45
+ context "return_last_tab" do
46
+ setup do
47
+ window = Object.new
48
+ tab = Object.new
49
+ mock(tab).get { true }
50
+ mock(window).tabs { [tab] }
51
+ mock(@mac_core).active_window { window }
52
+ end
53
+ asserts("returns tab") { @mac_core.return_last_tab }
54
+ end
55
+
56
+ context "execute_command" do
57
+ setup do
58
+ window = Object.new
59
+ mock(window).do_script("hasta", :in => :la_vista) { true }
60
+ mock(@mac_core).active_window { window }
61
+ end
62
+ asserts("baby") { @mac_core.execute_command('hasta', :in => :la_vista) }
63
+ end
64
+
65
+ context "active_window" do
66
+ setup do
67
+ terminal, windows, window, app_object = 4.times.collect { Object.new } # holy mother of somebody.
68
+ stub(app_object).get { {:frontmost => true} }
69
+ stub(window).properties_ { app_object }
70
+ stub(windows).get { [window] }
71
+ stub(terminal).windows { windows }
72
+ any_instance_of(Terminitor::MacCore) do |core|
73
+ stub(core).app('Terminal') { terminal }
74
+ stub(core).load_termfile('/path/to') { true }
75
+ end
76
+ end
77
+ asserts("gives me window") { Terminitor::MacCore.new('/path/to').active_window }
78
+ end
79
+ end
80
+ else
81
+ context "MacCore" do
82
+ puts "Nothing to do, you are not on OSX"
83
+ end
84
+ end
data/test/dsl_test.rb ADDED
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../teststrap', __FILE__)
2
+
3
+ context "Dsl" do
4
+ setup { @path = File.expand_path('../fixtures/bar.term', __FILE__)}
5
+ setup { @yaml = Terminitor::Dsl.new(@path) }
6
+ asserts_topic.assigns :setup
7
+ asserts_topic.assigns :windows
8
+ asserts_topic.assigns :_context
9
+
10
+ context "to_hash" do
11
+ setup { @yaml.to_hash }
12
+ asserts_topic.equivalent_to(:setup=>["echo \"setup\""], :windows=>{"window1"=>{"named tab"=>["echo 'named tab'", "ls"], "tab0"=>["echo 'first tab'", "echo 'of window'"]}, "default"=>{"tab0"=>["echo 'default'", "echo 'default tab'"]}})
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ # you can make as many tabs as you wish...
2
+ # tab names are actually arbitrary at this point too.
3
+
4
+ setup 'echo "setup"'
5
+
6
+ tab "echo 'default'", "echo 'default tab'"
7
+
8
+ window do
9
+ tab "echo 'first tab'", "echo 'of window'"
10
+
11
+ tab "named tab" do
12
+ run "echo 'named tab'"
13
+ run "ls"
14
+ end
15
+ end
16
+
@@ -0,0 +1,21 @@
1
+ setup do
2
+ run "echo 'setup'"
3
+ end
4
+
5
+ window "first window" do
6
+ run "echo 'first window"
7
+ end
8
+
9
+ window "second window" do
10
+ tab 'first tab' do
11
+ run "echo 'second window'"
12
+ end
13
+
14
+ tab(:second_tab) { run "echo 'second_tab'" }
15
+
16
+ end
17
+
18
+ # runs on last instantiated window
19
+ tab do
20
+ run "echo 'tab'"
21
+ end
@@ -1,3 +1,4 @@
1
+ # Foo.yml
1
2
  # you can make as many tabs as you wish...
2
3
  # tab names are actually arbitrary at this point too.
3
4
  ---
@@ -0,0 +1,234 @@
1
+ require File.expand_path('../teststrap', __FILE__)
2
+
3
+ class TestRunner
4
+ include Terminitor::Runner
5
+ def say(caption); puts caption; end
6
+ end
7
+
8
+ class TestObject
9
+ attr_accessor :test_item
10
+ def initialize(test_item); @test_item = test_item; end
11
+ def windows; [@test_item]; end
12
+ end
13
+
14
+ class TestItem
15
+ def do_script(prompt,hash); true; end
16
+ def get; true; end
17
+ def keystroke(prompt,hash); true; end
18
+ end
19
+
20
+ context "Runner" do
21
+ setup { @yaml = File.read(File.expand_path('../fixtures/foo.yml', __FILE__)) }
22
+ setup { @template = File.read(File.expand_path('../../lib/templates/example.yml.tt', __FILE__)) }
23
+ setup { @test_runner = TestRunner.new }
24
+ setup { FakeFS.activate! }
25
+ teardown { FakeFS.deactivate! }
26
+
27
+
28
+ context "find_core" do
29
+ context "for Darwin" do
30
+ setup { @test_runner.find_core('darwin') }
31
+ asserts_topic.equals Terminitor::MacCore
32
+ end
33
+
34
+ if platform?('linux') # TODO Gotta be a better way.
35
+ context "for KDE" do
36
+ setup { @test_runner.find_core('linux') }
37
+ asserts_topic.equals Terminitor::KonsoleCore
38
+ end
39
+ end
40
+ end
41
+
42
+ context "open_in_editor" do
43
+ context "using $EDITOR" do
44
+ setup { ENV['EDITOR'] = 'mate' }
45
+ setup { mock(@test_runner).system("mate /tmp/sample_project/foo.yml").returns {true}.once }
46
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml") } }
47
+ end
48
+
49
+ context "using $TERM_EDITOR" do
50
+ setup { ENV['TERM_EDITOR'] = 'vim' }
51
+ setup { ENV['EDITOR'] = 'jack' }
52
+ setup { mock(@test_runner).system("vim /tmp/sample_project/foo.yml").returns {true}.once }
53
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml")} }
54
+ end
55
+
56
+ context "without any editor" do
57
+ setup { ENV['TERM_EDITOR'] = nil }
58
+ setup { ENV['EDITOR'] = nil }
59
+ setup { mock(@test_runner).system("open /tmp/sample_project/foo.yml").returns {true}.once }
60
+ setup { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml")} }
61
+ asserts_topic.matches %r{please set}
62
+ end
63
+
64
+ context "accepts an editor" do
65
+ setup { ENV['TERM_EDITOR'] = 'vim' }
66
+ setup { ENV['EDITOR'] = 'jack' }
67
+ setup { mock(@test_runner).system("nano /tmp/sample_project/foo.yml").returns {true}.once }
68
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml","nano")} }
69
+ end
70
+
71
+ end
72
+
73
+ context "resolve_path" do
74
+ setup { FileUtils.mkdir_p(File.join(ENV['HOME'],'.terminitor')) }
75
+
76
+ context "with yaml" do
77
+ setup { FileUtils.touch(File.join(ENV['HOME'],'.terminitor','test.yml')) }
78
+ setup { @test_runner.resolve_path('test') }
79
+ asserts_topic.equals File.join(ENV['HOME'],'.terminitor','test.yml')
80
+ end
81
+
82
+ context "with term" do
83
+ setup { FileUtils.touch(File.join(ENV['HOME'],'.terminitor','test.term')) }
84
+ setup { FileUtils.rm(File.join(ENV['HOME'],'.terminitor','test.yml')) }
85
+ setup { @test_runner.resolve_path('test') }
86
+ asserts_topic.equals File.join(ENV['HOME'],'.terminitor','test.term')
87
+ end
88
+
89
+ context "with Termfile" do
90
+ setup { FileUtils.rm(File.join(ENV['HOME'],'.terminitor','test.yml')) }
91
+ setup { FileUtils.rm(File.join(ENV['HOME'],'.terminitor','test.term')) }
92
+ setup { FileUtils.touch("Termfile") }
93
+ setup { mock(@test_runner).options { {:root => '.'} } }
94
+ setup { @test_runner.resolve_path("") }
95
+ asserts_topic.equals "./Termfile"
96
+ end
97
+
98
+ context "with nothing" do
99
+ setup { FileUtils.rm(File.join(ENV['HOME'],'.terminitor','test.yml')) }
100
+ setup { FileUtils.rm(File.join(ENV['HOME'],'.terminitor','test.term')) }
101
+ setup { FileUtils.rm("Termfile") }
102
+
103
+ context "with a project" do
104
+ setup { @test_runner.resolve_path('hey') }
105
+ asserts_topic.nil
106
+ end
107
+
108
+ context "without a project" do
109
+ setup { mock(@test_runner).options { {:root => '.'} } }
110
+ setup { @test_runner.resolve_path("") }
111
+ asserts_topic.nil
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ context "config_path" do
118
+ context "for yaml" do
119
+ setup { @test_runner.config_path('test',:yml) }
120
+ asserts_topic.equals File.join(ENV['HOME'],'.terminitor','test.yml')
121
+ end
122
+
123
+ context "for term" do
124
+ setup { @test_runner.config_path('test', :term) }
125
+ asserts_topic.equals File.join(ENV['HOME'],'.terminitor', 'test.term')
126
+ end
127
+
128
+ context "for Termfile" do
129
+ setup { mock(@test_runner).options { {:root => '/tmp'} } }
130
+ setup { @test_runner.config_path("") }
131
+ asserts_topic.equals "/tmp/Termfile"
132
+ end
133
+
134
+ end
135
+
136
+ context "grab_comment_for_file" do
137
+ setup { File.open('foo.yml','w') { |f| f.puts @yaml } }
138
+ setup { @test_runner.grab_comment_for_file('foo.yml') }
139
+ asserts_topic.matches %r{- Foo.yml}
140
+ end
141
+
142
+ context "return_error_message" do
143
+ context "with project" do
144
+ setup { mock(@test_runner).say(%r{'hi' doesn't exist}) { true } }
145
+ asserts("that it says") { @test_runner.return_error_message('hi') }
146
+ end
147
+ context "without project" do
148
+ setup { mock(@test_runner).say(%r{Termfile}) { true } }
149
+ asserts("that is says") { @test_runner.return_error_message('') }
150
+ end
151
+ end
152
+
153
+ context "execute_core" do
154
+
155
+ context "with no found path" do
156
+ setup { mock(@test_runner).resolve_path('project') { nil } }
157
+ setup { mock(@test_runner).return_error_message('project') { true } }
158
+ asserts("shows error message") { @test_runner.execute_core(:process!,'project') }
159
+ end
160
+
161
+ context "with no found core" do
162
+ setup { mock(@test_runner).resolve_path('project') { true } }
163
+ setup { mock(@test_runner).find_core(anything) { nil } }
164
+ setup { mock(@test_runner).say(/No suitable/) { true } }
165
+ asserts("shows message") { @test_runner.execute_core(:process!,'project') }
166
+ end
167
+
168
+ context "with found core" do
169
+ context "#process!" do
170
+ setup { mock(@test_runner).resolve_path('project') { '/path/to' } }
171
+ setup do
172
+ any_instance_of(Terminitor::AbstractCore) do |core|
173
+ stub(core).load_termfile('/path/to') { true }
174
+ stub(core).process! { true }
175
+ end
176
+ mock(@test_runner).find_core(anything) { Terminitor::AbstractCore }
177
+ end
178
+ asserts("calls process!") { @test_runner.execute_core(:process!, 'project') }
179
+ end
180
+
181
+ context "#setup!" do
182
+ setup { mock(@test_runner).resolve_path('project') { '/path/to' } }
183
+ setup do
184
+ any_instance_of(Terminitor::AbstractCore) do |core|
185
+ stub(core).load_termfile('/path/to') { true }
186
+ stub(core).setup! { true }
187
+ end
188
+ mock(@test_runner).find_core(anything) { Terminitor::AbstractCore }
189
+ end
190
+ asserts("calls process!") { @test_runner.execute_core(:setup!, 'project') }
191
+ end
192
+ end
193
+ end
194
+
195
+ context "clone_repo" do
196
+ context "with github" do
197
+ setup { stub(@test_runner).__double_definition_create__.call(:`,'which github') { "github" } }
198
+ context "with read/write priv" do
199
+ setup { mock(@test_runner).system("github clone achiu terminitor --ssh") { true } }
200
+ asserts("invokes ssh") { @test_runner.clone_repo('achiu','terminitor') }
201
+ end
202
+
203
+ context "with read only" do
204
+ setup { mock(@test_runner).system("github clone achiu terminitor --ssh") { false } }
205
+ setup { mock(@test_runner).system("github clone achiu terminitor") { true } }
206
+ asserts("invokes git://") { @test_runner.clone_repo('achiu', 'terminitor') }
207
+ end
208
+ end
209
+ end
210
+
211
+ context "fetch_repo" do
212
+ context "with setup" do
213
+ setup { mock(@test_runner).clone_repo('achiu','terminitor') { true } }
214
+ setup { mock(FileUtils).cd(File.join(Dir.pwd,'terminitor')) { true } }
215
+ setup { mock(@test_runner).invoke(:setup, []) { true } }
216
+ asserts("invokes setup") { @test_runner.fetch_repo('achiu','terminitor', :setup => true) }
217
+ end
218
+
219
+ context "without setup" do
220
+ setup { mock(@test_runner).clone_repo('achiu','terminitor') { true } }
221
+ setup { mock(FileUtils).cd(File.join(Dir.pwd,'terminitor')) { true } }
222
+ asserts("invokes setup") { @test_runner.fetch_repo('achiu','terminitor') }.nil
223
+ end
224
+
225
+ context "failed on repo" do
226
+ setup { mock(@test_runner).clone_repo('achiu','terminitor') { false } }
227
+ setup { mock(@test_runner).say("could not fetch repo!") { true } }
228
+ asserts("invokes say") { @test_runner.fetch_repo('achiu', 'terminitor') }
229
+ end
230
+
231
+ end
232
+
233
+
234
+ end