scide 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'simplecov'
4
-
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
-
13
- require 'rspec'
14
- require 'fakefs/spec_helpers'
15
-
16
- RSpec.configure do |config|
17
-
18
- config.expect_with :rspec do |c|
19
- c.syntax = :expect
20
- end
21
-
22
- config.before :suite do
23
- ENV.delete_if{ |k,v| k.match /\ASCIDE_/ }
24
- end
25
-
26
- config.after :each do
27
- ENV.delete_if{ |k,v| k.match /\ASCIDE_/ }
28
- end
29
- end
30
-
31
- # test coverage
32
- SimpleCov.start
33
-
34
- require 'scide'
35
-
@@ -1,113 +0,0 @@
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
@@ -1,228 +0,0 @@
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
@@ -1,106 +0,0 @@
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