consular 1.0.0.rc1

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/spec/cli_spec.rb ADDED
@@ -0,0 +1,194 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ class FakeCore < Consular::Core
4
+
5
+ def self.valid_system?
6
+ true
7
+ end
8
+
9
+ def process!; puts('process'); end
10
+ def setup!; puts('setup'); end
11
+ end
12
+
13
+ describe Consular::CLI do
14
+
15
+ before do
16
+ @template = File.read File.expand_path('../../lib/templates/example.yml.tt', __FILE__)
17
+ FakeFS.activate!
18
+ FileUtils.mkdir_p Consular.global_path
19
+ end
20
+
21
+ after do
22
+ FakeFS.deactivate!
23
+ Consular.instance_variable_set(:@global_path, nil)
24
+ end
25
+
26
+ it "displays help" do
27
+ output = capture_io { Consular::CLI.start ['-h'] }.join('')
28
+
29
+ assert_match /start \[PROJECT\]/, output
30
+ assert_match /init/, output
31
+ assert_match /edit \[PROJECT\]/, output
32
+ end
33
+
34
+ it "lists out all global scripts" do
35
+ File.open(Consular.global_path('foo.yml'), "w") { |f| f.puts @template }
36
+ File.open(Consular.global_path('bar.term'), "w") { |f| f.puts @template }
37
+ File.open(Consular.global_path('bar.term~'), "w") { |f| f.puts @template }
38
+ output = capture_io { Consular::CLI.start ['list'] }.join('')
39
+
40
+ assert_match /foo\.yml - COMMENT OF SCRIPT HERE/, output
41
+ assert_match /bar - COMMENT OF SCRIPT HERE/, output
42
+ refute_match /bar\.term - COMMENT OF SCRIPT HERE/, output
43
+ refute_match /bar\.term~/, output
44
+ end
45
+
46
+ describe "start command" do
47
+ before do
48
+ FileUtils.mkdir_p '/tmp'
49
+ FileUtils.touch '/tmp/Termfile'
50
+ FileUtils.touch Consular.global_path('foo.term')
51
+ FileUtils.touch Consular.global_path('foo.yml')
52
+ Consular.add_core FakeCore
53
+ end
54
+
55
+ it "should start a Termfile" do
56
+ output = capture_io { Consular::CLI.start ['start', '-r=/tmp'] }.join('')
57
+ assert_match /process/, output
58
+ end
59
+
60
+ it "should start a global term script" do
61
+ output = capture_io { Consular::CLI.start ['start', 'foo'] }.join('')
62
+ assert_match /process/, output
63
+ end
64
+
65
+ it "should start a global yaml script" do
66
+ output = capture_io { Consular::CLI.start ['start', 'foo.yml'] }.join('')
67
+ assert_match /process/, output
68
+ end
69
+
70
+ it "should return an error message if it doesn't exist" do
71
+ output = capture_io { Consular::CLI.start ['start', 'barr'] }.join('')
72
+ assert_match /does not exist/, output
73
+ end
74
+ end
75
+
76
+ describe "setup command" do
77
+ before do
78
+ FileUtils.mkdir_p '/tmp'
79
+ FileUtils.touch '/tmp/Termfile'
80
+ FileUtils.touch Consular.global_path('foo.term')
81
+ FileUtils.touch Consular.global_path('foo.yml')
82
+ Consular.add_core FakeCore
83
+ end
84
+
85
+ it "should setup a Termfile" do
86
+ output = capture_io { Consular::CLI.start ['setup', '-r=/tmp'] }.join('')
87
+ assert_match /setup/, output
88
+ end
89
+
90
+ it "should setup a global term script" do
91
+ output = capture_io { Consular::CLI.start ['setup', 'foo'] }.join('')
92
+ assert_match /setup/, output
93
+ end
94
+
95
+ it "should setup a global yaml script" do
96
+ output = capture_io { Consular::CLI.start ['setup', 'foo.yml'] }.join('')
97
+ assert_match /setup/, output
98
+ end
99
+
100
+ it "should return an error message if it doesn't exist" do
101
+ output = capture_io { Consular::CLI.start ['setup', 'barr'] }.join('')
102
+ assert_match /does not exist/, output
103
+ end
104
+ end
105
+
106
+ it "init creates a new global script directory and consularc" do
107
+ FileUtils.rm_rf Consular.global_path
108
+ capture_io { Consular::CLI.start ['init'] }.join('')
109
+
110
+ assert File.exists?(Consular.global_path), "global script directory exists"
111
+ end
112
+
113
+ describe "delete command" do
114
+
115
+ it "removes Termfile" do
116
+ FileUtils.mkdir_p '/tmp/sample_project'
117
+ FileUtils.touch "/tmp/sample_project/Termfile"
118
+ capture_io { Consular::CLI.start ['delete',"-r=/tmp/sample_project"] }
119
+
120
+ refute File.exists?("/tmp/sample_project/Termfile"), 'deletes Termfile'
121
+ end
122
+
123
+ it "removes .yml files" do
124
+ FileUtils.touch Consular.global_path('foo.yml')
125
+ capture_io { Consular::CLI.start ['delete','foo.yml'] }
126
+
127
+ refute File.exists?(Consular.global_path('foo.yml')), 'deletes .yml files'
128
+ end
129
+
130
+ it "removes .term file" do
131
+ FileUtils.touch Consular.global_path('delete_this.term')
132
+ capture_io { Consular::CLI.start ['delete','delete_this'] }
133
+
134
+ refute File.exists?(Consular.global_path('delete_this.term')), 'deletes .term file'
135
+ end
136
+
137
+ it "removes .term file" do
138
+ output = capture_io { Consular::CLI.start ['delete','barr'] }.join('')
139
+
140
+ assert_match /does not exist/, output
141
+ end
142
+
143
+ end
144
+
145
+ describe "edit command" do
146
+ before do
147
+ FakeFS.deactivate!
148
+ @path = File.join ENV['HOME'], '.config', 'consular'
149
+ @yaml = File.join @path, 'foobar.yml'
150
+ @term = File.join @path, 'foobar.term'
151
+ `rm -f #{@yaml}`
152
+ `rm -f #{@term}`
153
+ `rm -f /tmp/Termfile`
154
+ end
155
+
156
+ after do
157
+ `rm -f #{@yaml}`
158
+ `rm -f #{@term}`
159
+ `rm -f /tmp/Termfile`
160
+ end
161
+
162
+ it "edits yaml files" do
163
+ FakeFS.deactivate!
164
+ Consular::CLI.any_instance.expects(:open_in_editor).with(@yaml, nil).returns(true)
165
+ output = capture_io { Consular::CLI.start ['edit', 'foobar.yml'] }.join('')
166
+
167
+ assert_match /create/, output
168
+ assert_match /foobar\.yml/, output
169
+ assert_match /- tab1/, File.read(@yaml)
170
+ end
171
+
172
+ it "edits .term file" do
173
+ FakeFS.deactivate!
174
+ Consular::CLI.any_instance.expects(:open_in_editor).with(@term, nil).returns(true)
175
+ output = capture_io { Consular::CLI.start ['edit', 'foobar'] }.join('')
176
+
177
+ assert_match /create/, output
178
+ assert_match /foobar\.term/, output
179
+ assert_match /setup/, File.read(@term)
180
+ end
181
+
182
+ it "edits a Termfile" do
183
+ FakeFS.deactivate!
184
+ Consular::CLI.any_instance.expects(:open_in_editor).with('/tmp/Termfile', nil).returns(true)
185
+ output = capture_io { Consular::CLI.start ['edit', '-r=/tmp'] }.join('')
186
+
187
+ assert_match /create/, output
188
+ assert_match /Termfile/, output
189
+ assert_match /setup/, File.read('/tmp/Termfile')
190
+ end
191
+
192
+ end
193
+
194
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Consular do
4
+
5
+ after do
6
+ Consular.instance_variable_set(:@cores,[])
7
+ Consular.instance_variable_set(:@global_path,nil)
8
+ end
9
+
10
+ it "can add cores" do
11
+ Consular.add_core Consular::Core
12
+ assert_equal 1, Consular.cores.size
13
+ end
14
+
15
+ it "has default configurations" do
16
+ assert_equal File.join(ENV['HOME'],'.config','consular',''), Consular.global_path
17
+ end
18
+
19
+ it "can be configured" do
20
+ Consular.configure do |c|
21
+ c.global_path = '/tmp/'
22
+ c.default_editor = 'vim'
23
+ end
24
+
25
+ assert_equal '/tmp/', Consular.global_path
26
+ assert_equal 'vim', Consular.default_editor
27
+ assert_equal '/tmp/Termfile', Consular.global_path('Termfile')
28
+ end
29
+
30
+ end
data/spec/core_spec.rb ADDED
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Consular::Core do
4
+ before do
5
+ @core = Consular::Core.new File.expand_path('../fixtures/bar.term', __FILE__)
6
+ end
7
+
8
+ it "on .initialize assigns the right values" do
9
+ refute_nil @core.termfile
10
+ end
11
+
12
+ it "stubs out the methods that need to be defined" do
13
+ assert_raises(NotImplementedError) { @core.class.valid_system? }
14
+ assert_raises(NotImplementedError) { @core.class.capture! }
15
+ assert_raises(NotImplementedError) { @core.setup! }
16
+ assert_raises(NotImplementedError) { @core.process! }
17
+ end
18
+
19
+ end
data/spec/dsl_spec.rb ADDED
@@ -0,0 +1,76 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Consular::DSL do
4
+ before do
5
+ @dsl = Consular::DSL.new File.expand_path('../fixtures/bar.term', __FILE__)
6
+ @yaml = Consular::DSL.new File.expand_path('../fixtures/foo.yml', __FILE__)
7
+ end
8
+
9
+ it "on .initialize setup some variables" do
10
+ refute_nil @dsl._setup
11
+ refute_nil @dsl._windows
12
+ refute_nil @dsl._context
13
+ end
14
+
15
+ describe ".to_hash with DSL" do
16
+ before do
17
+ @result = @dsl.to_hash
18
+ end
19
+
20
+ it "returns the initial setup" do
21
+ assert_equal @result[:setup], ['setup']
22
+ end
23
+
24
+ it "returns the first window" do
25
+ @window1 = @result[:windows]['window1']
26
+ @tab1 = @window1[:tabs]
27
+
28
+ assert_equal @window1[:before], ['before']
29
+ assert_equal @window1[:options], :size => [70, 30]
30
+
31
+ assert_equal @tab1['default'][:commands], ['whoami && who && ls']
32
+ assert_equal @tab1['tab1'][:commands], ['first-tab', 'motion &', 'foo']
33
+
34
+ assert_equal @tab1['tab2'][:options], :settings => 'Grass', :name => 'second'
35
+ assert_equal @tab1['tab2'][:commands], ['second-tab','second-tab:ls']
36
+
37
+ assert_equal @tab1['tab3'][:options], :settings => 'Pro', :name => 'third'
38
+ assert_equal @tab1['tab3'][:commands], ['third-tab', "(mvim &) && (gitx &) && uptime"]
39
+
40
+ assert_equal @tab1['tab4'][:options], :settings => 'Grass', :name => 'fourth'
41
+ assert_equal @tab1['tab4'][:commands], ['fourth-tab']
42
+ end
43
+
44
+ it "returns the second window" do
45
+ @window2 = @result[:windows]['window2']
46
+ @tab2 = @window2[:tabs]
47
+
48
+ assert_equal @window2[:before], ['name:before']
49
+ assert_equal @window2[:options], :name => 'name'
50
+
51
+ assert_equal @tab2['tab1'][:commands], ['name:tab']
52
+ end
53
+
54
+ end
55
+
56
+ describe ".to_hash with YAML" do
57
+ before do
58
+ @result = @yaml.to_hash
59
+ end
60
+
61
+ it "returns no setup" do
62
+ assert_equal @result[:setup], nil
63
+ end
64
+
65
+ it "returns the default window" do
66
+ @tabs = @result[:windows]['default'][:tabs]
67
+
68
+ assert_equal @tabs['tab1'][:commands], ['cd /foo/bar', 'gitx']
69
+ assert_equal @tabs['tab1'][:options], {}
70
+
71
+ assert_equal @tabs['tab2'][:commands], ['ls', 'mate .']
72
+ assert_equal @tabs['tab2'][:options], {}
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,32 @@
1
+ setup 'setup'
2
+
3
+ tab 'default', 'default-tab'
4
+
5
+ window :size => [70,30] do
6
+
7
+ before 'before'
8
+
9
+ run 'whoami', 'who', 'ls'
10
+
11
+ tab 'first-tab', 'motion &', 'foo'
12
+
13
+ tab 'second', :settings => 'Grass' do
14
+ run 'second-tab'
15
+ run 'second-tab:ls'
16
+ end
17
+
18
+ tab 'third', :settings => 'Pro' do
19
+ run 'third-tab'
20
+ run 'mvim &', 'gitx &', 'uptime'
21
+ end
22
+
23
+ tab 'fourth', :settings => 'Grass' do
24
+ run 'fourth-tab'
25
+ end
26
+ end
27
+
28
+ window 'name' do
29
+ before { run 'name:before' }
30
+
31
+ tab 'name:tab'
32
+ end
@@ -0,0 +1,10 @@
1
+ # Foo.yml
2
+ # you can make as many tabs as you wish...
3
+ # tab names are actually arbitrary at this point too.
4
+ ---
5
+ - tab1:
6
+ - cd /foo/bar
7
+ - gitx
8
+ - tab2:
9
+ - ls
10
+ - mate .
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ gem 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'fakefs/safe'
5
+ require 'mocha'
6
+ require File.expand_path('../../lib/consular', __FILE__)
7
+
8
+
9
+ class ColoredIO
10
+ ESC = "\e["
11
+ NND = "#{ESC}0m"
12
+
13
+ def initialize(io)
14
+ @io = io
15
+ end
16
+
17
+ def print(o)
18
+ case o
19
+ when "."
20
+ @io.send(:print, "#{ESC}32m#{o}#{NND}")
21
+ when "E"
22
+ @io.send(:print, "#{ESC}33m#{o}#{NND}")
23
+ when "F"
24
+ @io.send(:print, "#{ESC}31m#{o}#{NND}")
25
+ else
26
+ @io.send(:print, o)
27
+ end
28
+ end
29
+
30
+ def puts(*o)
31
+ super
32
+ end
33
+ end
34
+
35
+ MiniTest::Unit.output = ColoredIO.new(MiniTest::Unit.output)
36
+
37
+ # This is to silence the 'task' warning for the mocks.
38
+ #
39
+ class Thor
40
+ class << self
41
+ def create_task(meth) #:nodoc:
42
+ if @usage && @desc
43
+ base_class = @hide ? Thor::HiddenTask : Thor::Task
44
+ tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
45
+ @usage, @desc, @long_desc, @method_options, @hide = nil
46
+ true
47
+ elsif self.all_tasks[meth] || meth == "method_missing"
48
+ true
49
+ else
50
+ false
51
+ end
52
+ end
53
+ end
54
+ end
data/spec.watchr ADDED
@@ -0,0 +1,67 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ if not growlnotify.empty?
7
+ title = "Watchr Test Results"
8
+ image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
9
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
10
+ system %(#{growlnotify} #{options} &)
11
+ else
12
+ puts message
13
+ end
14
+ end
15
+
16
+ def run(cmd)
17
+ puts(cmd)
18
+ `#{cmd}`
19
+ end
20
+
21
+ def run_test_file(file)
22
+ system('clear')
23
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
24
+ growl result.split("\n").last rescue nil
25
+ puts result
26
+ end
27
+
28
+ def run_all_tests
29
+ system('clear')
30
+ result = run "rake spec"
31
+ growl result.split("\n").last rescue nil
32
+ puts result
33
+ end
34
+
35
+ def related_test_files(path)
36
+ Dir['spec/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_spec.rb/ }
37
+ end
38
+
39
+ def run_suite
40
+ run_all_tests
41
+ end
42
+
43
+ watch('spec/spec_helper\.rb') { run_all_tests }
44
+ watch('spec/(.*).*_spec\.rb') { |m| run_test_file(m[0]) }
45
+ watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
46
+
47
+ # Ctrl-\
48
+ Signal.trap 'QUIT' do
49
+ puts " --- Running all tests ---\n\n"
50
+ run_all_tests
51
+ end
52
+
53
+ @interrupted = false
54
+
55
+ # Ctrl-C
56
+ Signal.trap 'INT' do
57
+ if @interrupted then
58
+ @wants_to_quit = true
59
+ abort("\n")
60
+ else
61
+ puts "Interrupt a second time to quit"
62
+ @interrupted = true
63
+ Kernel.sleep 1.5
64
+ # raise Interrupt, nil # let the run loop catch it
65
+ run_suite
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: consular
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15424055
5
+ prerelease: 6
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 1.0.0.rc1
13
+ platform: ruby
14
+ authors:
15
+ - Arthur Chiu
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-10-09 00:00:00 -07:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: thor
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 3
32
+ segments:
33
+ - 0
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: minitest
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: mocha
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: fakefs
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ description: Terminal Automation to get you on your projects quickly
94
+ email:
95
+ - mr.arthur.chiu@gmail.com
96
+ executables:
97
+ - consular
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - Termfile
110
+ - bin/consular
111
+ - consular.gemspec
112
+ - lib/consular.rb
113
+ - lib/consular/cli.rb
114
+ - lib/consular/core.rb
115
+ - lib/consular/dsl.rb
116
+ - lib/consular/version.rb
117
+ - lib/templates/consularc.tt
118
+ - lib/templates/example.term.tt
119
+ - lib/templates/example.yml.tt
120
+ - spec.watchr
121
+ - spec/cli_spec.rb
122
+ - spec/consular_spec.rb
123
+ - spec/core_spec.rb
124
+ - spec/dsl_spec.rb
125
+ - spec/fixtures/bar.term
126
+ - spec/fixtures/foo.yml
127
+ - spec/spec_helper.rb
128
+ has_rdoc: true
129
+ homepage: http://www.github.com/achiu/consular
130
+ licenses: []
131
+
132
+ post_install_message: "********************************************************************************\n\n Consular has been installed! Please run:\n\n consular init\n\n This will create a directory at ~/.config/consular which will hold all your global scripts.\n Also a .consularc file will be generated in your HOME directory which you can further configure\n Consular.\n\n\
133
+ ********************************************************************************\n "
134
+ rdoc_options: []
135
+
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">"
151
+ - !ruby/object:Gem::Version
152
+ hash: 25
153
+ segments:
154
+ - 1
155
+ - 3
156
+ - 1
157
+ version: 1.3.1
158
+ requirements: []
159
+
160
+ rubyforge_project: consular
161
+ rubygems_version: 1.6.2
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Quickly setup your terminal windows for your projects
165
+ test_files:
166
+ - spec/cli_spec.rb
167
+ - spec/consular_spec.rb
168
+ - spec/core_spec.rb
169
+ - spec/dsl_spec.rb
170
+ - spec/fixtures/bar.term
171
+ - spec/fixtures/foo.yml
172
+ - spec/spec_helper.rb