evm 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +278 -0
  3. data/bin/evm +12 -0
  4. data/lib/evm.rb +7 -28
  5. data/lib/evm/builder.rb +18 -17
  6. data/lib/evm/cli.rb +43 -18
  7. data/lib/evm/command.rb +2 -1
  8. data/lib/evm/command/bin.rb +2 -2
  9. data/lib/evm/command/config.rb +19 -0
  10. data/lib/evm/command/disuse.rb +15 -0
  11. data/lib/evm/command/install.rb +3 -1
  12. data/lib/evm/command/list.rb +1 -1
  13. data/lib/evm/command/uninstall.rb +3 -1
  14. data/lib/evm/command/use.rb +3 -1
  15. data/lib/evm/config.rb +43 -0
  16. data/lib/evm/git.rb +1 -1
  17. data/lib/evm/package.rb +26 -11
  18. data/lib/evm/remote_file.rb +9 -55
  19. data/lib/evm/tar_file.rb +1 -1
  20. data/spec/evm/builder_spec.rb +209 -0
  21. data/spec/evm/cli_spec.rb +53 -0
  22. data/spec/evm/command/bin_spec.rb +32 -0
  23. data/spec/evm/command/config_spec.rb +34 -0
  24. data/spec/evm/command/disuse_spec.rb +19 -0
  25. data/spec/evm/command/install_spec.rb +103 -0
  26. data/spec/evm/command/list_spec.rb +36 -0
  27. data/spec/evm/command/uninstall_spec.rb +35 -0
  28. data/spec/evm/command/use_spec.rb +32 -0
  29. data/spec/evm/config_spec.rb +36 -0
  30. data/spec/evm/evm_spec.rb +11 -0
  31. data/spec/evm/git_spec.rb +39 -0
  32. data/spec/evm/os_spec.rb +47 -0
  33. data/spec/evm/package_spec.rb +274 -0
  34. data/spec/evm/recipe_spec.rb +47 -0
  35. data/spec/evm/remote_file_spec.rb +47 -0
  36. data/spec/evm/system_spec.rb +36 -0
  37. data/spec/evm/tar_file_spec.rb +21 -0
  38. data/spec/spec_helper.rb +13 -0
  39. metadata +29 -17
  40. data/lib/evm/exception.rb +0 -4
  41. data/lib/evm/progress_bar.rb +0 -37
  42. data/recipes/emacs-23.4-bin.rb +0 -7
  43. data/recipes/emacs-23.4.rb +0 -27
  44. data/recipes/emacs-24.1-bin.rb +0 -7
  45. data/recipes/emacs-24.1.rb +0 -24
  46. data/recipes/emacs-24.2-bin.rb +0 -7
  47. data/recipes/emacs-24.2.rb +0 -24
  48. data/recipes/emacs-24.3-bin.rb +0 -7
  49. data/recipes/emacs-24.3.rb +0 -24
  50. data/recipes/emacs-24.4-bin.rb +0 -7
  51. data/recipes/emacs-24.4.rb +0 -24
  52. data/recipes/emacs-git-snapshot.rb +0 -25
@@ -0,0 +1,274 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evm::Package do
4
+ let :file_class do
5
+ double('file_class')
6
+ end
7
+
8
+ let :file_instance do
9
+ double('file_instance')
10
+ end
11
+
12
+ let :config do
13
+ double('config')
14
+ end
15
+
16
+ before do
17
+ @foo = Evm::Package.new('foo', file: file_class)
18
+ allow(@foo).to receive(:name).and_return('foo')
19
+ @foo
20
+ end
21
+
22
+ describe '#current?' do
23
+ it 'should be current if current name is same as name' do
24
+ allow(Evm::Package).to receive(:current).and_return(@foo)
25
+ expect(Evm::Package.new('foo')).to be_current
26
+ end
27
+
28
+ it 'should not be current if current name is different from name' do
29
+ allow(Evm::Package).to receive(:current).and_return(@foo)
30
+ expect(Evm::Package.new('bar')).not_to be_current
31
+ end
32
+
33
+ it 'should not be current if no current' do
34
+ allow(Evm::Package).to receive(:current)
35
+ expect(Evm::Package.new('foo')).not_to be_current
36
+ end
37
+ end
38
+
39
+ describe '#installed?' do
40
+ before do
41
+ @binary = '/tmp/evm/foo/bin/emacs'
42
+ end
43
+
44
+ it 'should be installed if binary exists' do
45
+ allow(@foo).to receive(:bin).and_return(@binary)
46
+
47
+ expect(File).to receive(:file?).with(@binary).and_return(true)
48
+ expect(File).to receive(:executable?).with(@binary).and_return(true)
49
+
50
+ expect(@foo).to be_installed
51
+ end
52
+
53
+ it 'should not be installed if binary does not exist' do
54
+ allow(@foo).to receive(:bin).and_return(@binary)
55
+
56
+ expect(File).to receive(:file?).with(@binary).and_return(false)
57
+
58
+ expect(@foo).not_to be_installed
59
+ end
60
+
61
+ it 'should not be installed if binary exists, but is not binary' do
62
+ allow(@foo).to receive(:bin).and_return(@binary)
63
+
64
+ expect(File).to receive(:file?).with(@binary).and_return(true)
65
+ expect(File).to receive(:executable?).with(@binary).and_return(false)
66
+
67
+ expect(@foo).not_to be_installed
68
+ end
69
+ end
70
+
71
+ describe '#path' do
72
+ it 'should be path to package path' do
73
+ expect(@foo.path).to eq('/tmp/evm/foo')
74
+ end
75
+ end
76
+
77
+ describe '#bin' do
78
+ it 'should be bin/emacs if linux' do
79
+ allow(Evm::Os).to receive(:osx?).and_return(false)
80
+ allow(Evm::Os).to receive(:linux?).and_return(true)
81
+
82
+ expect(@foo.bin.to_s).to eq('/tmp/evm/foo/bin/emacs')
83
+ end
84
+
85
+ it 'should be bin/emacs if osx and no nextstep' do
86
+ allow(Evm::Os).to receive(:osx?).and_return(true)
87
+ allow(Evm::Os).to receive(:linux?).and_return(false)
88
+
89
+ allow(File).to receive(:exist?).with('/tmp/evm/foo/Emacs.app').and_return(false)
90
+
91
+ expect(@foo.bin.to_s).to eq('/tmp/evm/foo/bin/emacs')
92
+ end
93
+
94
+ it 'should be nextstep bin if osx and nextstep' do
95
+ allow(Evm::Os).to receive(:osx?).and_return(true)
96
+ allow(Evm::Os).to receive(:linux?).and_return(false)
97
+
98
+ allow(File).to receive(:exist?).with('/tmp/evm/foo/Emacs.app').and_return(true)
99
+
100
+ expect(@foo.bin).to eq('/tmp/evm/foo/Emacs.app/Contents/MacOS/Emacs')
101
+ end
102
+ end
103
+
104
+ describe '#use!' do
105
+ it 'creates emacs and evm-emacs shims' do
106
+ expect(file_class).to receive(:exists?).with(Evm::EMACS_PATH).and_return(false)
107
+ expect(file_class).to receive(:exists?).with(Evm::EVM_EMACS_PATH).and_return(true)
108
+ expect(file_class).to receive(:delete).with(Evm::EVM_EMACS_PATH)
109
+ expect(file_class).to receive(:open).twice.with(anything, 'w').and_yield(file_instance)
110
+ expect(file_class).to receive(:chmod).twice
111
+ expect(file_instance).to receive(:puts).twice.with("#!/bin/bash\nexec \"/tmp/evm/foo/bin/emacs\" \"$@\"")
112
+
113
+ @foo.use!
114
+ end
115
+
116
+ it 'sets current package' do
117
+ allow(file_class).to receive(:exists?)
118
+ allow(file_class).to receive(:open)
119
+ allow(file_class).to receive(:chmod)
120
+ allow(file_instance).to receive(:puts)
121
+ allow(Evm).to receive(:config).and_return(config)
122
+ expect(config).to receive(:[]=).with(:current, 'foo')
123
+
124
+ @foo.use!
125
+ end
126
+ end
127
+
128
+ describe '#disuse!' do
129
+ it 'removes emacs and evm-emacs shims' do
130
+ expect(file_class).to receive(:exists?).with(Evm::EMACS_PATH).and_return(true)
131
+ expect(file_class).to receive(:exists?).with(Evm::EVM_EMACS_PATH).and_return(true)
132
+ expect(file_class).to receive(:delete).with(Evm::EMACS_PATH)
133
+ expect(file_class).to receive(:delete).with(Evm::EVM_EMACS_PATH)
134
+
135
+ @foo.disuse!
136
+ end
137
+
138
+ it 'unsets current package' do
139
+ allow(file_class).to receive(:exists?)
140
+ allow(Evm).to receive(:config).and_return(config)
141
+ expect(config).to receive(:[]=).with(:current, nil)
142
+
143
+ @foo.disuse!
144
+ end
145
+ end
146
+
147
+ describe '#install!' do
148
+ before do
149
+ @builder = double('builder')
150
+ expect(@builder).to receive(:build!)
151
+
152
+ allow(File).to receive(:exist?).with('/tmp/evm/foo').and_return(true)
153
+ allow(File).to receive(:exist?).with('/tmp/evm/tmp').and_return(true)
154
+
155
+ allow(Evm::Builder).to receive(:new).and_return(@builder)
156
+ end
157
+
158
+ it 'should create installation path if not exist' do
159
+ allow(File).to receive(:exist?).with('/tmp/evm/foo').and_return(false)
160
+
161
+ expect(Dir).to receive(:mkdir).with('/tmp/evm/foo')
162
+
163
+ @foo.install!
164
+ end
165
+
166
+ it 'should not create installation path if exists' do
167
+ allow(File).to receive(:exist?).with('/tmp/evm/foo').and_return(true)
168
+
169
+ expect(Dir).not_to receive(:mkdir)
170
+
171
+ @foo.install!
172
+ end
173
+
174
+ it 'should create tmp path if not exist' do
175
+ allow(File).to receive(:exist?).with('/tmp/evm/tmp').and_return(false)
176
+
177
+ expect(Dir).to receive(:mkdir).with('/tmp/evm/tmp')
178
+
179
+ @foo.install!
180
+ end
181
+
182
+ it 'should not create installation path if exists' do
183
+ allow(File).to receive(:exist?).with('/tmp/evm/tmp').and_return(true)
184
+
185
+ expect(Dir).not_to receive(:mkdir).with('/tmp/evm/tmp')
186
+
187
+ @foo.install!
188
+ end
189
+ end
190
+
191
+ describe '#uninstall!' do
192
+ before do
193
+ allow(@foo).to receive(:current?).and_return(false)
194
+ end
195
+
196
+ it 'should remove installation path if exists' do
197
+ allow(File).to receive(:exist?).and_return(true)
198
+ expect(FileUtils).to receive(:rm_r).with('/tmp/evm/foo')
199
+
200
+ @foo.uninstall!
201
+ end
202
+
203
+ it 'should not remove installation path if not exists' do
204
+ allow(File).to receive(:exist?).and_return(false)
205
+ expect(FileUtils).not_to receive(:rm_r)
206
+
207
+ @foo.uninstall!
208
+ end
209
+
210
+ it 'should remove binary symlink if current' do
211
+ expect(FileUtils).to receive(:rm).with(Evm::EVM_EMACS_PATH)
212
+
213
+ allow(@foo).to receive(:current?).and_return(true)
214
+
215
+ @foo.uninstall!
216
+ end
217
+
218
+ it 'should not remove binary symlink file if not current' do
219
+ expect(FileUtils).not_to receive(:rm).with(Evm::EVM_EMACS_PATH)
220
+
221
+ allow(@foo).to receive(:current?).and_return(false)
222
+
223
+ @foo.uninstall!
224
+ end
225
+ end
226
+
227
+ describe '#to_s' do
228
+ it 'should return name' do
229
+ expect(@foo.to_s).to eq('foo')
230
+ end
231
+ end
232
+
233
+ describe '.current' do
234
+ it 'return package when set in config' do
235
+ Evm.config[:current] = 'emacs-24.5'
236
+ expect(Evm::Package.current.name).to eq('emacs-24.5')
237
+ end
238
+
239
+ it 'is nil unless set in config' do
240
+ Evm.config[:current] = nil
241
+ expect(Evm::Package.current).to be_nil
242
+ end
243
+ end
244
+
245
+ describe '.find' do
246
+ it 'should return recipe with same name' do
247
+ allow(Evm::Recipe).to receive(:find).and_return({})
248
+
249
+ expect(Evm::Package.find('foo').name).to eq('foo')
250
+ end
251
+
252
+ it 'should raise exception if no recipe with same name' do
253
+ allow(Evm::Recipe).to receive(:find).and_return(nil)
254
+ expect {
255
+ Evm::Package.find('baz')
256
+ }.to raise_error('No such package: baz')
257
+ end
258
+ end
259
+
260
+ describe '.all' do
261
+ it 'should return array with one package for each recipe' do
262
+ recipes = []
263
+ recipes << double('recipe-1', :name => 'foo')
264
+ recipes << double('recipe-2', :name => 'bar')
265
+
266
+ allow(Evm::Recipe).to receive(:all).and_return(recipes)
267
+
268
+ package_1, package_2 = Evm::Package.all
269
+
270
+ expect(package_1.name).to eq('foo')
271
+ expect(package_2.name).to eq('bar')
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evm::Recipe do
4
+ describe '#name' do
5
+ it 'should return recipe name' do
6
+ allow(File).to receive(:read).with('foo.rb').and_return('recipe "foo" do end')
7
+ allow(File).to receive(:read).with('bar.rb').and_return('recipe "bar" do end')
8
+
9
+ expect(Evm::Recipe.new('foo.rb').name).to eq('foo')
10
+ expect(Evm::Recipe.new('bar.rb').name).to eq('bar')
11
+ end
12
+ end
13
+
14
+ describe '#read' do
15
+ it 'should read recipe file' do
16
+ expect(File).to receive(:read).twice.with('foo.rb').and_return('recipe "foo" do end')
17
+
18
+ expect(Evm::Recipe.new('foo.rb').read).to eq('recipe "foo" do end')
19
+ end
20
+ end
21
+
22
+ describe '.find' do
23
+ it 'should return recipe with same name' do
24
+ foo = double('foo', :name => 'foo')
25
+ bar = double('bar', :name => 'bar')
26
+
27
+ allow(Evm::Recipe).to receive(:all).and_return([foo, bar])
28
+ expect(Evm::Recipe.find('foo')).to eq(foo)
29
+ expect(Evm::Recipe.find('bar')).to eq(bar)
30
+ end
31
+
32
+ it 'should return nil if no recipe with same name' do
33
+ expect(Evm::Recipe.find('foo')).to be_nil
34
+ end
35
+ end
36
+
37
+ describe '.all' do
38
+ it 'should return an array of all recipes' do
39
+ allow(File).to receive(:read).with('foo.rb').and_return('recipe "foo" do end')
40
+ allow(File).to receive(:read).with('bar.rb').and_return('recipe "bar" do end')
41
+
42
+ allow(Dir).to receive(:glob).and_return(['foo.rb', 'bar.rb'])
43
+
44
+ expect(Evm::Recipe.all.size).to eq(2)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evm::RemoteFile do
4
+ let :url do
5
+ 'http://mirror.com/emacs-24.3.tar.gz'
6
+ end
7
+
8
+ let :path do
9
+ '/path/to/emacs-24.3.tar.gz'
10
+ end
11
+
12
+ let :file_class do
13
+ double('file_class')
14
+ end
15
+
16
+ let :file_instance do
17
+ double('file_instance')
18
+ end
19
+
20
+ let :uri do
21
+ double('uri')
22
+ end
23
+
24
+ let :data do
25
+ 'DATA'
26
+ end
27
+
28
+ subject do
29
+ Evm::RemoteFile.new(url, file: file_class, uri: uri)
30
+ end
31
+
32
+ describe '#download' do
33
+ it 'downloads file to path' do
34
+ expect(file_class).to receive(:exist?).with(path).and_return(false)
35
+ expect(file_class).to receive(:open).with(path, 'w').and_yield(file_instance)
36
+ expect(file_instance).to receive(:write).with(data)
37
+ expect(uri).to receive_message_chain(:parse, :read).and_return(data)
38
+ subject.download(path)
39
+ end
40
+
41
+ it 'does not download file if file already exist' do
42
+ expect(file_class).to receive(:exist?).with(path).and_return(true)
43
+ expect(file_class).to_not receive(:open)
44
+ subject.download(path)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evm::System do
4
+ before do
5
+ @system = Evm::System.new('command')
6
+ end
7
+
8
+ describe '#run' do
9
+ it 'should run when no arguments' do
10
+ expect(Kernel).to receive(:system).with('command').and_return(true)
11
+
12
+ @system.run
13
+ end
14
+
15
+ it 'should run with single argument' do
16
+ expect(Kernel).to receive(:system).with('command', 'foo').and_return(true)
17
+
18
+ @system.run('foo')
19
+ end
20
+
21
+ it 'should run with multiple arguments' do
22
+ expect(Kernel).to receive(:system).with('command', 'foo', 'bar').and_return(true)
23
+
24
+ @system.run('foo', 'bar')
25
+ end
26
+
27
+ it 'should exit if the command fails' do
28
+ expect(Kernel).to receive(:exit)
29
+
30
+ # Based on http://stackoverflow.com/a/4589517
31
+ system = Evm::System.new('(exit 21)')
32
+
33
+ system.run
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evm::TarFile do
4
+ let('tar_file') { '/path/to/foo.tar.gz' }
5
+
6
+ subject do
7
+ Evm::TarFile.new(@tar_file)
8
+ end
9
+
10
+ describe '#extract' do
11
+ it 'extracts tar file to path when no name' do
12
+ expect(subject).to receive(:tar).with('-xf', @tar_file, '-C', '/path/to')
13
+ subject.extract('/path/to')
14
+ end
15
+
16
+ it 'extracts tar file to path/name when name' do
17
+ expect(subject).to receive(:tar).with('-xf', @tar_file, '-C', '/path/to/directory', '--strip-components', '1')
18
+ subject.extract('/path/to', 'directory')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'evm'
5
+
6
+ RSpec.configure do |config|
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+ config.before do
11
+ allow(Evm).to receive(:config).and_return({path: '/tmp/evm'})
12
+ end
13
+ end
metadata CHANGED
@@ -1,51 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Andersson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2016-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: EVM is a command-line tool that allows you to install multiple Emacs
14
14
  versions.
15
15
  email: johan.rejeep@gmail.com
16
- executables: []
16
+ executables:
17
+ - evm
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
21
+ - README.md
22
+ - bin/evm
20
23
  - lib/evm.rb
21
24
  - lib/evm/builder.rb
22
25
  - lib/evm/cli.rb
23
26
  - lib/evm/command.rb
24
27
  - lib/evm/command/bin.rb
28
+ - lib/evm/command/config.rb
29
+ - lib/evm/command/disuse.rb
25
30
  - lib/evm/command/install.rb
26
31
  - lib/evm/command/list.rb
27
32
  - lib/evm/command/uninstall.rb
28
33
  - lib/evm/command/use.rb
29
- - lib/evm/exception.rb
34
+ - lib/evm/config.rb
30
35
  - lib/evm/git.rb
31
36
  - lib/evm/os.rb
32
37
  - lib/evm/package.rb
33
- - lib/evm/progress_bar.rb
34
38
  - lib/evm/recipe.rb
35
39
  - lib/evm/remote_file.rb
36
40
  - lib/evm/system.rb
37
41
  - lib/evm/tar_file.rb
38
- - recipes/emacs-23.4-bin.rb
39
- - recipes/emacs-23.4.rb
40
- - recipes/emacs-24.1-bin.rb
41
- - recipes/emacs-24.1.rb
42
- - recipes/emacs-24.2-bin.rb
43
- - recipes/emacs-24.2.rb
44
- - recipes/emacs-24.3-bin.rb
45
- - recipes/emacs-24.3.rb
46
- - recipes/emacs-24.4-bin.rb
47
- - recipes/emacs-24.4.rb
48
- - recipes/emacs-git-snapshot.rb
42
+ - spec/evm/builder_spec.rb
43
+ - spec/evm/cli_spec.rb
44
+ - spec/evm/command/bin_spec.rb
45
+ - spec/evm/command/config_spec.rb
46
+ - spec/evm/command/disuse_spec.rb
47
+ - spec/evm/command/install_spec.rb
48
+ - spec/evm/command/list_spec.rb
49
+ - spec/evm/command/uninstall_spec.rb
50
+ - spec/evm/command/use_spec.rb
51
+ - spec/evm/config_spec.rb
52
+ - spec/evm/evm_spec.rb
53
+ - spec/evm/git_spec.rb
54
+ - spec/evm/os_spec.rb
55
+ - spec/evm/package_spec.rb
56
+ - spec/evm/recipe_spec.rb
57
+ - spec/evm/remote_file_spec.rb
58
+ - spec/evm/system_spec.rb
59
+ - spec/evm/tar_file_spec.rb
60
+ - spec/spec_helper.rb
49
61
  homepage: http://github.com/rejeep/evm
50
62
  licenses:
51
63
  - MIT
@@ -66,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
78
  version: '0'
67
79
  requirements: []
68
80
  rubyforge_project:
69
- rubygems_version: 2.4.6
81
+ rubygems_version: 2.5.1
70
82
  signing_key:
71
83
  specification_version: 4
72
84
  summary: Emacs Version Manager