warp-dir 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Warp::Dir::Command do
4
- include_context :initialized_store
5
- installed_commands = Warp::Dir::Command.installed_commands.dup.freeze
6
-
7
- let(:command) { Warp::Dir::Command }
8
- let(:commander) { Warp::Dir::Commander.instance }
9
-
10
- describe 'when we remove inherited hierarchy' do
11
- before do
12
- commander.commands.clear
13
- end
14
- after do
15
- commander.commands.merge(installed_commands.dup)
16
- end
17
-
18
- it 'should start with a blank list' do
19
- expect(commander.commands).to be_empty
20
- end
21
-
22
- it 'should add a subclass command to the list of installed Command' do
23
- class Warp::Dir::Command::MyCommand < Warp::Dir::Command; def run; end; end
24
- expect(commander.installed_commands).to eql([:mycommand])
25
- expect(commander.find :mycommand).to eql(Warp::Dir::Command::MyCommand)
26
- end
27
-
28
- it 'should be possible to lookup the command by alias' do
29
- class Warp::Dir::Command::CommandWithAlias < Warp::Dir::Command
30
- aliases :with_alias, :without_alias
31
- def run;
32
- end;
33
- end
34
-
35
- expect(commander.installed_commands).to eql([:commandwithalias])
36
- expect(commander.find :commandwithalias).to eql(Warp::Dir::Command::CommandWithAlias)
37
- expect(commander.find :with_alias).to eql(Warp::Dir::Command::CommandWithAlias)
38
- expect(commander.find :without_alias).to eql(Warp::Dir::Command::CommandWithAlias)
39
-
40
- expect { commander.find :boo }.to raise_error Warp::Dir::Errors::InvalidCommand
41
- end
42
-
43
-
44
- describe '#validate!' do
45
- it 'should raise exception when subclass command does not have a #run method ' do
46
- class Warp::Dir::Command::Random < Warp::Dir::Command;
47
- end
48
- expect(commander.commands).to include(Warp::Dir::Command::Random)
49
- expect { commander.send(:validate!) }.to raise_error(Warp::Dir::Errors::InvalidCommand)
50
- end
51
-
52
- it 'should not quietly remove any abstract classes ' do
53
- class Warp::Dir::Command::Random < Warp::Dir::Command
54
- def abstract_class?;
55
- true;
56
- end
57
- end
58
- expect(commander.commands).to eql(Set.new)
59
- end
60
- end
61
- end
62
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
- require 'warp/dir/store'
3
-
4
- RSpec.describe Warp::Dir::Command::Add do
5
- include_context :fake_serializer
6
-
7
- let(:store) { double }
8
- let(:command_class) { Warp::Dir::Command::Add }
9
- let(:commander) { Warp::Dir::Commander.instance }
10
-
11
- let(:wp_path) { ENV['HOME'] + '/workspace/tinker-mania' }
12
- let(:wp_name) { 'harro' }
13
- let(:point) { Warp::Dir::Point.new(wp_name, wp_path) }
14
-
15
- let(:add_command) { command_class.new(store, wp_name, wp_path) }
16
-
17
- before do
18
- expect(store).to receive(:config).and_return(config).at_least(:once)
19
- end
20
-
21
- it 'should have the commander defined' do
22
- expect(add_command.store).to_not be_nil
23
- end
24
-
25
- describe '#help' do
26
- it 'should define a help message' do
27
- expect(add_command.command_name).to eql(:add)
28
- expect(add_command.description).to match(%r(Adds the current directory)i)
29
- expect(add_command.help).to match /add/
30
- expect(add_command.help).to match /Adds the current directory/
31
- end
32
- end
33
-
34
- describe '#run' do
35
- it 'should call #save! on store after adding new wp' do
36
- expect(store).to receive(:insert).with(point_name: wp_name, point_path: wp_path, overwrite: false).and_return(point)
37
- add_command.run
38
- end
39
- end
40
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/cli_expectations'
3
- require 'warp/dir/formatter'
4
-
5
- RSpec.describe Warp::Dir::Command::Install do
6
-
7
- let(:commander) { Warp::Dir.commander }
8
- let(:install) { Warp::Dir::Command::Install.new(store) }
9
-
10
- describe '#run' do
11
- include_context :fixture_file
12
- include_context :initialized_store
13
-
14
- context 'when shell files do not exist' do
15
- it 'should return :error type response' do
16
- expect("install #{warprc_args} --dotfile ~/.do_not_exist").to output(/not found/)
17
- end
18
- end
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'warp/dir/formatter'
3
-
4
- RSpec.describe Warp::Dir::Command::List do
5
-
6
- let(:commander) { Warp::Dir.commander }
7
- let(:list) { Warp::Dir::Command::List }
8
-
9
- describe '#help' do
10
- it 'should define a help message' do
11
- expect(list.help).to match /list/
12
- expect(list.help).to match /Print all stored warp points/
13
- end
14
- end
15
-
16
- describe '#run' do
17
- include_context :fake_serializer
18
- include_context :initialized_store
19
-
20
- let(:formatter) { Warp::Dir::Formatter.new(store) }
21
- let(:output) { formatter.format_store(:ascii) }
22
- before do
23
- store.add(point: point)
24
- end
25
-
26
- it 'should return formatted warp points from the store' do
27
- expect(output).to eql(%Q{harro -> ~/workspace/tinker-mania})
28
- end
29
-
30
- it 'should return response and print the listing' do
31
- response = list.new(store).run
32
- expect(response.messages.first).to eql(output.blue.bold)
33
- expect(STDOUT).to receive(:printf).at_least(1).times
34
- response.print
35
- end
36
- end
37
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Warp::Dir::Config do
4
- let(:c1) { Warp::Dir::Config.new(blah: 'blah blah') }
5
-
6
- it 'should have a default folder' do
7
- expect(c1.warprc).to eql(ENV['HOME'] + '/.warprc')
8
- end
9
-
10
- it 'should automatically create accessors' do
11
- expect(c1.blah).to eql('blah blah')
12
- end
13
-
14
- it 'should add new parameter to the params array' do
15
- expect(c1.variables).to eql([:warprc, :shell, :force, :debug, :blah])
16
- end
17
-
18
- it 'should be able to create a attr_writer also' do
19
- c1.blah = 'another blah'
20
- expect(c1.blah).to eql('another blah')
21
- end
22
-
23
- it 'should be possible to add a new value after instance was created' do
24
- c1.new_field = 'really new here'
25
- expect(c1.new_field?).to be_truthy
26
- expect(c1.new_field).to eql('really new here')
27
- end
28
-
29
- describe 'when another instance of the config is created' do
30
- let(:c2) { Warp::Dir::Config.new(poo: 'boo') }
31
-
32
- it 'should only have one parameter for this class' do
33
- expect(c1.respond_to?(:poo)).to be_falsey
34
- expect(c2.respond_to?(:poo)).to be_truthy
35
-
36
- expect(c1.respond_to?(:blah)).to be_truthy
37
- expect(c2.respond_to?(:blah)).to be_falsey
38
- end
39
-
40
- it 'should add new parameter to the params array' do
41
- expect(c2.variables).to eql([:warprc, :shell, :force, :debug, :poo])
42
- end
43
-
44
- end
45
- end
@@ -1,16 +0,0 @@
1
- require 'warp/dir'
2
- require 'spec_helper'
3
-
4
- RSpec.describe Warp::Dir::Errors do
5
- include_context :fake_serializer
6
- include_context :initialized_store
7
-
8
- it 'should properly throw point already exists error' do
9
- expect(store.class).to eql(Warp::Dir::Store)
10
- expect(point.class).to eql(Warp::Dir::Point)
11
-
12
- store.add(point: point.dup)
13
- point.full_path = '~/booomania'
14
- expect { store.add(point: point) }.to raise_error(Warp::Dir::Errors::PointAlreadyExists)
15
- end
16
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'warp/dir/formatter'
3
-
4
- RSpec.describe Warp::Dir::Formatter do
5
- include_context :initialized_store
6
-
7
- let(:path_absolute) { ENV['HOME'] + '/workspace' }
8
- let(:path_relative) { '~/workspace' }
9
- let(:p1) { Warp::Dir::Point.new('p', ENV['HOME'] + '/workspace') }
10
- let(:p2) { Warp::Dir::Point.new('n', ENV['HOME'] + '/workspace/new-project') }
11
-
12
- describe 'with empty store' do
13
- before do
14
- store.add(p1)
15
- store.add(p2)
16
- end
17
-
18
-
19
- # it '#map,#each' do
20
- # expect(collection.map(&:formatted)).to eql([
21
- # 'p -> ~/workspace',
22
- # 'n -> ~/workspace/new-project'
23
- # ])
24
- # paths = []
25
- # collection.each { |p| paths << p.relative_path }
26
- # expect(paths).to eql(%w(~/workspace ~/workspace/new-project))
27
- # end
28
- # it '#:[]' do
29
- # expect(collection[1]).to eql(p2)
30
- # end
31
- # it '#formatted' do
32
- # expect(collection.formatted).to eql("n -> ~/workspace/new-project\np -> ~/workspace")
33
- # end
34
- # it '#formatted sorted' do
35
- # expect(collection.formatted(:ascii, :path)).to eql("p -> ~/workspace\nn -> ~/workspace/new-project")
36
- # end
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
- require 'warp/dir'
3
-
4
- RSpec.describe Warp::Dir::Point do
5
- include_context :fake_serializer
6
- include_context :initialized_store
7
-
8
- let(:path_absolute) { ENV['HOME'] + '/workspace' }
9
- let(:path_relative) { '~/workspace' }
10
- let(:p1) { Warp::Dir::Point.new('p', ENV['HOME'] + '/workspace') }
11
- let(:p2) { Warp::Dir::Point.new('n', ENV['HOME'] + '/workspace/new-project') }
12
-
13
- describe 'with two distinct but identical objects' do
14
- let(:p2) { Warp::Dir::Point.new('p', ENV['HOME'] + '/workspace') }
15
- it 'correctly defines #eql?' do
16
- expect(p1).to eql(p2)
17
- end
18
- it 'correctly defines #hash' do
19
- expect(p1.hash).to eql(p2.hash)
20
- end
21
- it '#file.path' do
22
- expect(file.path.length > 0).to be_truthy
23
- end
24
- end
25
-
26
- describe 'instance methods' do
27
- it '#to_s' do
28
- expect(p1.to_s).to eql('p -> ~/workspace')
29
- end
30
- it '#inspect' do
31
- expect(p1.inspect).to match(%r{name: '#{p1.name}', path: '#{p1.relative_path}'})
32
- end
33
- end
34
-
35
- end
@@ -1,130 +0,0 @@
1
- require 'spec_helper'
2
- require 'warp/dir'
3
- require 'warp/dir/config'
4
- require 'warp/dir/store'
5
- require 'tempfile'
6
-
7
- RSpec.describe Warp::Dir::Store do
8
-
9
- describe 'with no existin warprc file' do
10
- let(:config_path) { "/tmp/warprc#{srand()}" }
11
- let(:config) { Warp::Dir::Config.new(warprc: config_path) }
12
- let(:store) { Warp::Dir::Store.new(config) }
13
-
14
- after do
15
- File.unlink(config_path) if File.exists?(config_path)
16
- end
17
-
18
- it 'does not fail for find requests' do
19
- expect(File.exist?(config.warprc)).to be_falsey, config.warprc
20
- expect { store['mypoint'] }.to raise_error(Warp::Dir::Errors::PointNotFound)
21
- end
22
-
23
- it 'creates the file when adding points' do
24
- expect(File.exist?(config.warprc)).to be_falsey, config.warprc
25
- expect(store.size).to eql(0)
26
- store.add(point_name: 'mypoint', point_path: '/tmp')
27
- expect(File.exist?(config.warprc)).to be_falsey, config.warprc
28
- end
29
- end
30
-
31
- describe 'with an exiting warprc file' do
32
- include_context :fake_serializer
33
- include_context :initialized_store
34
-
35
- context 'when store responds to common methods on collections' do
36
- let(:point_name) { 'moo' }
37
- let(:point_path) { ENV['HOME'] + '/tmp/12398485' }
38
- let(:store) { Warp::Dir::Store.new(config) }
39
- let(:p1) { Warp::Dir::Point.new('p', ENV['HOME'] + '/workspace') }
40
- let(:p2) { Warp::Dir::Point.new('n', ENV['HOME'] + '/workspace/new-project') }
41
-
42
- it 'should be able to have an empty store' do
43
- expect(store.points).to be_empty
44
- end
45
-
46
- it 'should respond to #size and return 0' do
47
- expect(store.size).to eql(0)
48
- end
49
-
50
- it 'it should respond to #<< and add a new point' do
51
- store.add(point: p1)
52
- store.add(point: p2)
53
- store << Warp::Dir::Point.new('123', '436')
54
- expect(store.size).to eql(3)
55
- end
56
- end
57
-
58
- context 'when the data storeis empty' do
59
- let(:point_name) { 'moo' }
60
- let(:point_path) { ENV['HOME'] + '/tmp/12398485' }
61
- let(:store) { Warp::Dir::Store.new(config) }
62
-
63
- it 'should be able to initialize the Store' do
64
- expect(store.points).to be_empty
65
- end
66
-
67
- it 'should respond to #size and return 0' do
68
- expect(store.size).to eql(0)
69
- end
70
-
71
- it 'it should respond to #<< and add a new point' do
72
- expect(store.size).to eql(0)
73
- store << Warp::Dir::Point.new('123', '436')
74
- expect(store.size).to eql(1)
75
- end
76
-
77
- it 'should be able to add a new point to the Store' do
78
- store.add(point_name: point_name, point_path: point_path)
79
- corrected_path = Warp::Dir.absolute point_path
80
- expect(store[point_name].path).to eql(corrected_path)
81
- end
82
-
83
- it 'should not be able to add a different point with the same name' do
84
- store.add(point_name: point_name, point_path: point_path)
85
- # double adding the same point is ok
86
- expect { store.add(point_name: point_name, point_path: point_path) }.to_not raise_error
87
- # adding another point pointing to the same name is not OK
88
- expect { store.add(point_name: point_name, point_path: point_path + '98984') }.to raise_error(Warp::Dir::Errors::PointAlreadyExists)
89
- end
90
-
91
- it 'should be able to add multiple points to the Store' do
92
- store.add(point_name: 'm1', point_path: '123')
93
- store.add(point_name: 'm2', point_path: '456')
94
- expect(store['m1'].path).to eql('123')
95
- expect(store['m2'].path).to eql('456')
96
- end
97
- end
98
-
99
- context 'data store contains some warp points already' do
100
- let(:store) { Warp::Dir::Store.new(config) }
101
- before do
102
- store.add(point_name: 'm1', point_path: 'A1')
103
- store.add(point_name: 'm2', point_path: 'A2')
104
- store.save!
105
- end
106
-
107
- describe 'reading data' do
108
- let(:new_store) { Warp::Dir::Store.new(config) }
109
-
110
- it 'should restore correctly compared to last saved' do
111
- expect(new_store['m1'].path).to eql('A1')
112
- expect(new_store['m2'].path).to eql('A2')
113
- end
114
-
115
- it 'should not allow overwriting without a force flag' do
116
- # adding another point pointing to the same name is not OK
117
- expect { new_store.add(point_name: 'm1', point_path: '98984') }.to raise_error(Warp::Dir::Errors::PointAlreadyExists)
118
- end
119
-
120
- it 'should be able to find previously saved item' do
121
- expect(new_store['m1']).to eql(Warp::Dir::Point.new('m1', 'A1'))
122
- end
123
-
124
- it 'should be able to handle when it doesnt find a given element' do
125
- expect { new_store['ASDSADAS'] }.to raise_error(Warp::Dir::Errors::PointNotFound)
126
- end
127
- end
128
- end
129
- end
130
- end