scide 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.rspec +0 -1
  2. data/.ruby-version +1 -0
  3. data/.screenrc +8 -0
  4. data/.travis.yml +1 -1
  5. data/Gemfile +10 -11
  6. data/Gemfile.lock +46 -39
  7. data/LICENSE.txt +1 -1
  8. data/README.md +36 -144
  9. data/Rakefile +19 -26
  10. data/VERSION +1 -1
  11. data/bin/scide +1 -2
  12. data/lib/scide/auto.rb +33 -0
  13. data/lib/scide/list.rb +33 -0
  14. data/lib/scide/open.rb +57 -0
  15. data/lib/scide/program.rb +109 -0
  16. data/lib/scide/setup.rb +16 -0
  17. data/lib/scide.rb +25 -57
  18. data/scide.gemspec +51 -59
  19. data/spec/auto_spec.rb +72 -0
  20. data/spec/cli/list_spec.rb +81 -0
  21. data/spec/cli/open_spec.rb +131 -0
  22. data/spec/cli/setup_spec.rb +82 -0
  23. data/spec/helper.rb +12 -24
  24. data/spec/list_spec.rb +113 -0
  25. data/spec/open_spec.rb +228 -0
  26. data/spec/setup_spec.rb +106 -0
  27. data/spec/version_spec.rb +3 -5
  28. metadata +150 -72
  29. data/.document +0 -5
  30. data/.rvmrc +0 -41
  31. data/TODO.md +0 -21
  32. data/lib/scide/command.rb +0 -124
  33. data/lib/scide/commands/edit.rb +0 -37
  34. data/lib/scide/commands/run.rb +0 -25
  35. data/lib/scide/commands/show.rb +0 -29
  36. data/lib/scide/commands/tail.rb +0 -37
  37. data/lib/scide/config.rb +0 -105
  38. data/lib/scide/global.rb +0 -30
  39. data/lib/scide/opts.rb +0 -35
  40. data/lib/scide/overmind.rb +0 -70
  41. data/lib/scide/project.rb +0 -93
  42. data/lib/scide/screen.rb +0 -77
  43. data/lib/scide/window.rb +0 -88
  44. data/spec/command_spec.rb +0 -86
  45. data/spec/commands/edit_spec.rb +0 -19
  46. data/spec/commands/run_spec.rb +0 -9
  47. data/spec/commands/show_spec.rb +0 -15
  48. data/spec/commands/tail_spec.rb +0 -14
  49. data/spec/config_spec.rb +0 -113
  50. data/spec/global_spec.rb +0 -38
  51. data/spec/opts_spec.rb +0 -42
  52. data/spec/project_spec.rb +0 -171
  53. data/spec/results/config1.yml +0 -14
  54. data/spec/results/malformed_config.yml +0 -2
  55. data/spec/results/project1.screen +0 -10
  56. data/spec/results/screen1.screen +0 -14
  57. data/spec/scide_spec.rb +0 -38
  58. data/spec/screen_spec.rb +0 -90
  59. data/spec/window_spec.rb +0 -122
@@ -0,0 +1,82 @@
1
+ require 'helper'
2
+
3
+ describe 'scide setup' do
4
+
5
+ let(:argv){ [ 'setup' ] }
6
+ let(:expected_args){ [] }
7
+ let(:expected_options){ {} }
8
+ let(:expected_output){ '' }
9
+
10
+ before :each do
11
+ Scide.stub :setup
12
+ Scide.stub(:list).and_raise(StandardError.new('list should not be called'))
13
+ Scide.stub(:open).and_raise(StandardError.new('open should not be called'))
14
+ end
15
+
16
+ shared_examples_for "setup" do
17
+
18
+ let(:config_file){ '~/some/.screenrc' }
19
+ let(:expected_output){ config_file }
20
+
21
+ it "should output the path to the created file" do
22
+ Scide.stub setup: '~/some/.screenrc'
23
+ expect_success
24
+ end
25
+
26
+ context "if it fails" do
27
+
28
+ before :each do
29
+ Scide.stub(:setup).and_raise(Scide::Error.new('fubar'))
30
+ end
31
+
32
+ it "should output the error to stderr" do
33
+ expect_failure "fubar#{Scide::Program::BACKTRACE_NOTICE}"
34
+ end
35
+
36
+ context "with the trace option" do
37
+
38
+ let(:argv){ super().unshift '--trace' }
39
+
40
+ it "should raise the error" do
41
+ expect_failure "fubar", true
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ it_behaves_like "setup"
48
+
49
+ [ '-p', '--projects' ].each do |opt|
50
+ context "with the #{opt} option" do
51
+ let(:projects_dir){ '~/Projects' }
52
+ let(:expected_options){ { projects: projects_dir } }
53
+ let(:argv){ super() + [ opt, projects_dir ] }
54
+ it_behaves_like "setup"
55
+ end
56
+ end
57
+
58
+ def expect_success output = nil
59
+ args = expected_args + (expected_options.empty? ? [] : [ expected_options ])
60
+ Scide.should_receive(:setup).with *args
61
+ program = Scide::Program.new argv
62
+ stdout, stderr = StringIO.new, StringIO.new
63
+ $stdout, $stderr = stdout, stderr
64
+ expect{ program.run! }.to_not raise_error
65
+ $stdout, $stderr = STDOUT, STDERR
66
+ expect(Paint.unpaint(stdout.string.chomp "\n")).to eq(output || expected_output)
67
+ expect(stderr.string).to be_empty
68
+ end
69
+
70
+ def expect_failure message, expect_raise = false, code = 1, &block
71
+ program = Scide::Program.new argv
72
+ if expect_raise
73
+ expect{ program.run! }.to raise_error(Scide::Error){ |e| expect(e.message).to eq(message) }
74
+ else
75
+ stderr = StringIO.new
76
+ $stderr = stderr
77
+ expect{ program.run! }.to raise_error(SystemExit){ |e| expect(e.status).to eq(code) }
78
+ $stderr = STDERR
79
+ expect(Paint.unpaint(stderr.string.strip)).to eq(message)
80
+ end
81
+ end
82
+ end
data/spec/helper.rb CHANGED
@@ -2,12 +2,6 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  require 'simplecov'
4
4
 
5
- # to silence streams
6
- require 'active_support/core_ext/kernel/reporting'
7
-
8
- # test coverage
9
- SimpleCov.start
10
-
11
5
  begin
12
6
  Bundler.setup(:default, :development)
13
7
  rescue Bundler::BundlerError => e
@@ -17,31 +11,25 @@ rescue Bundler::BundlerError => e
17
11
  end
18
12
 
19
13
  require 'rspec'
20
- require 'shoulda'
14
+ require 'fakefs/spec_helpers'
21
15
 
22
- class SpecHelper
23
- def self.result name
24
- File.open(File.join(File.dirname(__FILE__), 'results', "#{name}.screen"), 'r').read
16
+ RSpec.configure do |config|
17
+
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = :expect
25
20
  end
26
21
 
27
- def self.silence
28
- silence_stream(STDOUT) do
29
- silence_stream(STDERR) do
30
- yield
31
- end
32
- end
22
+ config.before :suite do
23
+ ENV.delete_if{ |k,v| k.match /\ASCIDE_/ }
33
24
  end
34
25
 
35
- def self.should_fail exit_on_fail, condition, msg
36
- if exit_on_fail
37
- "should exit with status #{Scide::EXIT[condition]} #{msg}"
38
- else
39
- "should raise an error with condition #{condition} #{msg}"
40
- end
26
+ config.after :each do
27
+ ENV.delete_if{ |k,v| k.match /\ASCIDE_/ }
41
28
  end
42
29
  end
43
30
 
44
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
45
- $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ # test coverage
32
+ SimpleCov.start
33
+
46
34
  require 'scide'
47
35
 
data/spec/list_spec.rb ADDED
@@ -0,0 +1,113 @@
1
+ require 'helper'
2
+
3
+ describe 'Scide.list' do
4
+ include FakeFS::SpecHelpers
5
+
6
+ let(:default_projects_dir){ File.expand_path('~/src') }
7
+ let(:custom_projects_dir){ File.expand_path('~/Projects') }
8
+ let(:env_projects_dir){ nil }
9
+ let(:options){ {} }
10
+
11
+ before :each do
12
+ FileUtils.mkdir_p File.expand_path('~')
13
+ ENV['SCIDE_PROJECTS'] = env_projects_dir if env_projects_dir
14
+ end
15
+
16
+ shared_examples_for "listings" do
17
+
18
+ it "should fail if the projects directory is a file" do
19
+ FileUtils.mkdir_p File.dirname(projects_dir)
20
+ FileUtils.touch projects_dir
21
+ expect_failure /no such directory/i
22
+ end
23
+
24
+ context "if the projects directory doesn't exist" do
25
+
26
+ it "should fail if current directory is the home directory" do
27
+ Dir.chdir setup('~', false)
28
+ expect_failure /no such directory/i
29
+ end
30
+
31
+ it "should fail if the current directory isn't a project" do
32
+ Dir.chdir setup('~/some', false)
33
+ expect_failure /no such directory/i
34
+ end
35
+
36
+ it "should return the current directory if it's a project" do
37
+ Dir.chdir setup('~/some')
38
+ expect(list).to eq([ '.' ])
39
+ end
40
+ end
41
+
42
+ context "if the projects directory exists" do
43
+
44
+ before :each do
45
+ FileUtils.mkdir_p projects_dir
46
+ end
47
+
48
+ it "should return an empty list if there are no projects" do
49
+ expect(list).to be_empty
50
+ end
51
+
52
+ it "should return the current directory if it's a project" do
53
+ Dir.chdir setup('~/some')
54
+ expect(list).to eq([ '.' ])
55
+ end
56
+
57
+ it "should return the projects with a .screenrc file in the projects directory" do
58
+ setup File.join(projects_dir, 'a')
59
+ setup File.join(projects_dir, 'b'), false
60
+ setup File.join(projects_dir, 'c')
61
+ setup File.join(projects_dir, 'd')
62
+ setup File.join(projects_dir, 'e'), false
63
+ expect(list).to eq([ 'a', 'c', 'd' ])
64
+ end
65
+
66
+ it "should return the projects in the projects directory and the current directory" do
67
+ Dir.chdir setup('~/some')
68
+ setup File.join(projects_dir, 'a')
69
+ setup File.join(projects_dir, 'b')
70
+ setup File.join(projects_dir, 'c'), false
71
+ expect(list).to eq([ '.', 'a', 'b' ])
72
+ end
73
+
74
+ it "should not return the projects directory" do
75
+ setup projects_dir
76
+ expect(list).to be_empty
77
+ end
78
+ end
79
+ end
80
+
81
+ context "with the default projects directory" do
82
+ let(:projects_dir){ default_projects_dir }
83
+ it_behaves_like "listings"
84
+ end
85
+
86
+ context "with a custom projects directory set by option" do
87
+ let(:projects_dir){ custom_projects_dir }
88
+ let(:options){ { projects: custom_projects_dir } }
89
+ it_behaves_like "listings"
90
+ end
91
+
92
+ context "with a custom projects directory set by environment variable" do
93
+ let(:projects_dir){ custom_projects_dir }
94
+ let(:env_projects_dir){ custom_projects_dir }
95
+ it_behaves_like "listings"
96
+ end
97
+
98
+ def setup dir, config = true
99
+ dir = File.expand_path dir
100
+ FileUtils.mkdir_p dir
101
+ FileUtils.touch File.join(dir, '.screenrc') if config
102
+ dir
103
+ end
104
+
105
+ def expect_failure *args, &block
106
+ block = lambda{ list } unless block
107
+ expect(&block).to raise_error(Scide::Error){ |e| args.each{ |msg| expect(e.message).to match(msg) } }
108
+ end
109
+
110
+ def list
111
+ Scide.list options
112
+ end
113
+ end
data/spec/open_spec.rb ADDED
@@ -0,0 +1,228 @@
1
+ require 'helper'
2
+ require 'fileutils'
3
+
4
+ describe 'Scide.open' do
5
+ include FakeFS::SpecHelpers
6
+
7
+ let(:default_projects_dir){ File.expand_path('~/src') }
8
+ let(:custom_projects_dir){ File.expand_path('~/Projects') }
9
+ let(:env_projects_dir){ nil }
10
+ let(:system_result){ true }
11
+ let(:name){ nil }
12
+ let(:options){ {} }
13
+ let(:open_args){ (name ? [ name ] : []) + (options.empty? ? [] : [ options ]) }
14
+ let(:expected_screenrc){ Regexp.escape '.screenrc' }
15
+
16
+ before :each do
17
+
18
+ # for temporary files
19
+ FileUtils.mkdir_p '/tmp'
20
+
21
+ # for which
22
+ FileUtils.mkdir_p '/usr/bin'
23
+ FileUtils.touch '/usr/bin/screen'
24
+ FileUtils.chmod 0755, '/usr/bin/screen'
25
+
26
+ # home folder
27
+ FileUtils.mkdir_p File.expand_path('~')
28
+
29
+ ENV['SCIDE_PROJECTS'] = env_projects_dir if env_projects_dir
30
+
31
+ Kernel.stub system: system_result
32
+ end
33
+
34
+ it "should fail if screen is not in the path" do
35
+ Which.stub which: nil
36
+ expect_failure(/screen must be in the path/i){ Scide.open }
37
+ end
38
+
39
+ it "should fail if more than one project name is given" do
40
+ expect_failure(/only one project name/i){ Scide.open 'a', 'b' }
41
+ end
42
+
43
+ it "should not open the home directory" do
44
+ Dir.chdir File.expand_path('~')
45
+ expect_failure(/home directory/i){ Scide.open }
46
+ end
47
+
48
+ shared_examples_for "a screen wrapper" do
49
+
50
+ it "should execute the command" do
51
+ expect_success /\A#{expected_chdir}screen -U -c #{expected_screenrc}\Z/
52
+ end
53
+
54
+ context "with a custom binary set by option" do
55
+
56
+ let(:custom_bin){ '/bin/custom-screen' }
57
+ let(:options){ super().merge bin: custom_bin }
58
+
59
+ it "should execute the command with that binary" do
60
+ expect_success /\A#{expected_chdir}#{Regexp.escape custom_bin} -U -c #{expected_screenrc}\Z/
61
+ end
62
+ end
63
+
64
+ context "with a custom binary set by environment variable" do
65
+
66
+ let(:custom_bin){ '/bin/custom-screen' }
67
+ before(:each){ ENV['SCIDE_BIN'] = custom_bin }
68
+
69
+ it "should execute the command with that binary" do
70
+ expect_success /\A#{expected_chdir}#{Regexp.escape custom_bin} -U -c #{expected_screenrc}\Z/
71
+ end
72
+ end
73
+
74
+ context "with custom screen options set by option" do
75
+
76
+ let(:custom_screen){ '-r -x' }
77
+ let(:options){ super().merge screen: custom_screen }
78
+
79
+ it "should execute the command with those options" do
80
+ expect_success /\A#{expected_chdir}screen -r -x -c #{expected_screenrc}\Z/
81
+ end
82
+ end
83
+
84
+ context "with custom screen options set by environment variable" do
85
+
86
+ let(:custom_screen){ '-r -x' }
87
+ before(:each){ ENV['SCIDE_SCREEN'] = custom_screen }
88
+
89
+ it "should execute the command with those options" do
90
+ expect_success /\A#{expected_chdir}screen -r -x -c #{expected_screenrc}\Z/
91
+ end
92
+ end
93
+
94
+ context "with the noop option" do
95
+
96
+ let(:options){ super().merge noop: true }
97
+
98
+ it "should print the command" do
99
+ expect_success false, /\A#{expected_chdir}screen -U -c #{expected_screenrc}\Z/
100
+ end
101
+ end
102
+ end
103
+
104
+ context "for a project in the current directory" do
105
+
106
+ let(:file){ '/projects/a/.screenrc' }
107
+ let(:dir){ File.dirname file }
108
+ before(:each){ Dir.chdir setup(dir, false) }
109
+
110
+ it "should fail if there is no configuration file" do
111
+ expect_failure /no such configuration/i
112
+ end
113
+
114
+ it "should fail if the configuration is not a file" do
115
+ FileUtils.mkdir_p file
116
+ expect_failure /not a file/i
117
+ end
118
+
119
+ context "with the auto option" do
120
+ let(:expected_chdir){ nil }
121
+ let(:expected_screenrc){ '.+' }
122
+ let(:options){ super().merge auto: true }
123
+ it_behaves_like "a screen wrapper"
124
+ end
125
+
126
+ context "if the project is valid" do
127
+ let(:expected_chdir){ nil }
128
+ before(:each){ FileUtils.touch file }
129
+ it_behaves_like "a screen wrapper"
130
+ end
131
+ end
132
+
133
+ shared_examples_for "a project in a configured directory" do
134
+
135
+ it "should fail if the project directory doesn't exist" do
136
+ expect_failure /no such directory/i
137
+ end
138
+
139
+ it "should fail if the project directory is not a directory" do
140
+ FileUtils.mkdir_p File.dirname(dir)
141
+ FileUtils.touch dir
142
+ expect_failure /no such directory/i
143
+ end
144
+
145
+ it "should fail if there is no configuration file" do
146
+ setup dir, false
147
+ expect_failure /no such configuration/i
148
+ end
149
+
150
+ it "should fail if the configuration is not a file" do
151
+ FileUtils.mkdir_p file
152
+ expect_failure /not a file/i
153
+ end
154
+
155
+ context "with the auto option" do
156
+ let(:expected_chdir){ Regexp.escape "cd #{Shellwords.escape dir} && " }
157
+ let(:expected_screenrc){ '.+' }
158
+ let(:options){ super().merge auto: true }
159
+ before(:each){ setup dir, false }
160
+ it_behaves_like "a screen wrapper"
161
+ end
162
+
163
+ context "if the project is valid" do
164
+ let(:expected_chdir){ Regexp.escape "cd #{Shellwords.escape dir} && " }
165
+ before(:each){ setup dir }
166
+ it_behaves_like "a screen wrapper"
167
+ end
168
+ end
169
+
170
+ context "for a project in the default project directory" do
171
+ let(:name){ 'a' }
172
+ let(:file){ File.join default_projects_dir, name, '.screenrc' }
173
+ let(:dir){ File.dirname file }
174
+ it_behaves_like "a project in a configured directory"
175
+ end
176
+
177
+ context "for a project in a custom project directory set by option" do
178
+ let(:name){ 'a' }
179
+ let(:file){ File.join custom_projects_dir, name, '.screenrc' }
180
+ let(:dir){ File.dirname file }
181
+ let(:options){ { projects: custom_projects_dir } }
182
+ it_behaves_like "a project in a configured directory"
183
+ end
184
+
185
+ context "for a project in a custom project directory set by environment variable" do
186
+ let(:name){ 'a' }
187
+ let(:file){ File.join custom_projects_dir, name, '.screenrc' }
188
+ let(:dir){ File.dirname file }
189
+ let(:env_projects_dir){ custom_projects_dir }
190
+ it_behaves_like "a project in a configured directory"
191
+ end
192
+
193
+ def open
194
+ Scide.open *open_args
195
+ end
196
+
197
+ def setup dir, config = true
198
+ dir = File.expand_path dir
199
+ FileUtils.mkdir_p dir
200
+ FileUtils.touch File.join(dir, '.screenrc') if config
201
+ dir
202
+ end
203
+
204
+ def expect_success command, expected_result = nil, &block
205
+
206
+ if command
207
+ Kernel.should_receive(:system).with command
208
+ else
209
+ Kernel.should_not_receive(:system)
210
+ end
211
+
212
+ block = lambda{ open } unless block
213
+
214
+ result = nil
215
+ expect{ result = block.call }.to_not raise_error
216
+
217
+ if !expected_result
218
+ expect(result).to be_true if open_args.empty?
219
+ elsif !command
220
+ expect(result).to match(expected_result)
221
+ end
222
+ end
223
+
224
+ def expect_failure *args, &block
225
+ block = lambda{ open } unless block
226
+ expect(&block).to raise_error(Scide::Error){ |e| args.each{ |msg| expect(e.message).to match(msg) } }
227
+ end
228
+ end
@@ -0,0 +1,106 @@
1
+ require 'helper'
2
+
3
+ describe 'Scide.setup' do
4
+ include FakeFS::SpecHelpers
5
+
6
+ let(:default_projects_dir){ File.expand_path('~/src') }
7
+ let(:custom_projects_dir){ File.expand_path('~/Projects') }
8
+ let(:env_projects_dir){ nil }
9
+ let(:expected_contents){ 'foo' }
10
+ let(:name){ nil }
11
+ let(:options){ {} }
12
+ let(:setup_args){ (name ? [ name ] : []) + (options.empty? ? [] : [ options ]) }
13
+
14
+ before :each do
15
+ FileUtils.mkdir_p File.expand_path('~')
16
+ ENV['SCIDE_PROJECTS'] = env_projects_dir if env_projects_dir
17
+ Scide.stub auto_config: expected_contents
18
+ end
19
+
20
+ shared_examples_for "setting up" do
21
+
22
+ it "should fail if more than one project name is given" do
23
+ expect_failure(/only one project name/i){ Scide.setup 'a', 'b' }
24
+ end
25
+
26
+ it "should not set up the home directory" do
27
+ Dir.chdir File.expand_path('~')
28
+ expect_failure /home directory/i
29
+ end
30
+
31
+ context "the current directory" do
32
+
33
+ let(:dir){ '~/some' }
34
+
35
+ it "should fail if a .screenrc file already exists" do
36
+ Dir.chdir setup(dir)
37
+ expect_failure /already exists/i
38
+ end
39
+
40
+ it "should setup the default configuration" do
41
+ Dir.chdir setup(dir, false)
42
+ expect_success File.join(dir, '.screenrc')
43
+ end
44
+ end
45
+
46
+ context "a project directory" do
47
+
48
+ let(:name){ 'a' }
49
+ let(:project_dir){ File.join projects_dir, name }
50
+
51
+ before :each do
52
+ FileUtils.mkdir_p projects_dir
53
+ end
54
+
55
+ it "should fail if a .screenrc file already exists" do
56
+ Dir.chdir setup(project_dir)
57
+ expect_failure /already exists/i
58
+ end
59
+
60
+ it "should setup the default configuration" do
61
+ Dir.chdir setup(project_dir, false)
62
+ expect_success File.join(project_dir, '.screenrc')
63
+ end
64
+ end
65
+ end
66
+
67
+ context "with the default projects directory" do
68
+ let(:projects_dir){ default_projects_dir }
69
+ it_behaves_like "setting up"
70
+ end
71
+
72
+ context "with a custom projects directory set by option" do
73
+ let(:projects_dir){ custom_projects_dir }
74
+ let(:options){ { projects: custom_projects_dir } }
75
+ it_behaves_like "setting up"
76
+ end
77
+
78
+ context "with a custom projects directory set by environment variable" do
79
+ let(:projects_dir){ custom_projects_dir }
80
+ let(:env_projects_dir){ custom_projects_dir }
81
+ it_behaves_like "setting up"
82
+ end
83
+
84
+ def setup dir, config = true
85
+ dir = File.expand_path dir
86
+ FileUtils.mkdir_p dir
87
+ FileUtils.touch File.join(dir, '.screenrc') if config
88
+ dir
89
+ end
90
+
91
+ def expect_success path, noop = false
92
+ result = nil
93
+ expect{ result = do_setup *setup_args }.to_not raise_error
94
+ expect(result).to eq(File.expand_path(path))
95
+ expect(File.read(result)).to eq(expected_contents) unless noop
96
+ end
97
+
98
+ def expect_failure *args, &block
99
+ block = lambda{ do_setup *setup_args } unless block
100
+ expect(&block).to raise_error(Scide::Error){ |e| args.each{ |msg| expect(e.message).to match(msg) } }
101
+ end
102
+
103
+ def do_setup *args
104
+ Scide.setup *args
105
+ end
106
+ end
data/spec/version_spec.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- describe 'Scide::VERSION' do
4
-
5
- it "should be the correct version" do
6
- Scide::VERSION.should == File.open(File.join(File.dirname(__FILE__), '..', 'VERSION'), 'r').read
7
- end
3
+ describe 'Version' do
4
+ subject{ Scide::VERSION }
5
+ it{ should eq(File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))) }
8
6
  end