gene_system 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,230 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe GeneSystem::CLI::Commands do
4
- describe '.new' do
5
- let(:pwd) { 'path/to/current/dir' }
6
- let(:name) { 'manifest name' }
7
- let(:args) { [name] }
8
-
9
- before do
10
- allow(Dir).to receive(:pwd).and_return(pwd)
11
- allow(GeneSystem::Generators).to receive(:render_empty_manifest)
12
- end
13
-
14
- it 'renders empty manifest at current path with given name' do
15
- described_class.new(args)
16
-
17
- expect(GeneSystem::Generators).to have_received(:render_empty_manifest)
18
- .with(name, pwd)
19
- end
20
-
21
- context 'when name is not given' do
22
- it 'raises no manifest name provided runtime error' do
23
- expect { described_class.new([]) }.to raise_error(
24
- RuntimeError,
25
- 'no manifest name provided'
26
- )
27
- end
28
- end
29
- end
30
-
31
- describe '.install' do
32
- let(:manifest_name) { 'manifest.json' }
33
- let(:pwd) { 'path/to/current/dir' }
34
-
35
- let(:args) { [manifest_name] }
36
- let(:file_exist) { true }
37
-
38
- let(:skip_cmd) { 'check something' }
39
- let(:skip_result) { 1 }
40
-
41
- let(:cmd) { 'do something' }
42
- let(:cmds) { [cmd, cmd] }
43
-
44
- let(:data) do
45
- {
46
- 'name' => 'test_manifest',
47
- 'version' => '0.1.0',
48
- 'steps' => [
49
- {
50
- 'name' => 'install',
51
- 'exe' => {
52
- 'install' => {
53
- 'skip' => skip_cmd,
54
- 'cmd' => cmds
55
- }
56
- }
57
- }
58
- ]
59
- }
60
- end
61
-
62
- let(:manifest) do
63
- GeneSystem::Manifest.new(
64
- File.join(pwd, manifest_name),
65
- data
66
- )
67
- end
68
- let(:platform) { double(GeneSystem::Platform) }
69
-
70
- before do
71
- allow(Dir).to receive(:pwd).and_return(pwd)
72
- allow(File).to receive(:exist?).and_return(file_exist)
73
-
74
- allow(GeneSystem::Manifest).to receive(:new_from_file)
75
- .and_return(manifest)
76
-
77
- allow(GeneSystem::Platform).to receive(:new)
78
- .and_return(platform)
79
-
80
- allow(platform).to receive(:execute_commands)
81
- allow(platform).to receive(:execute_command)
82
- .with(skip_cmd)
83
- .and_return(skip_result)
84
-
85
- allow(GeneSystem::CLI).to receive(:print_message)
86
- end
87
-
88
- describe 'installing manifest' do
89
- before { described_class.install(args) }
90
-
91
- it 'loads manifest' do
92
- expect(GeneSystem::Manifest)
93
- .to have_received(:new_from_file)
94
- .with(File.join(pwd, manifest_name))
95
- end
96
-
97
- it 'executes steps on platform' do
98
- expect(platform)
99
- .to have_received(:execute_commands)
100
- .with(cmds, {})
101
- end
102
-
103
- it 'prints success message' do
104
- expect(GeneSystem::CLI).to have_received(:print_message)
105
- .with("\nmanifest successfully installed")
106
- end
107
-
108
- context 'when skipping step' do
109
- let(:skip_result) { 0 }
110
-
111
- it 'does not execute steps' do
112
- expect(platform)
113
- .not_to have_received(:execute_commands)
114
- end
115
- end
116
- end
117
-
118
- context 'when path is not provided' do
119
- it 'raises no manifest path provided runtime error' do
120
- expect { described_class.install }.to raise_error(
121
- RuntimeError,
122
- 'no manifest path provided'
123
- )
124
- end
125
- end
126
-
127
- context 'when manifest cannot be created at specified path' do
128
- let(:file_exist) { false }
129
-
130
- it 'raises cannot find manifest RuntimeError' do
131
- expect { described_class.install(args) }.to raise_error(
132
- RuntimeError,
133
- 'cannot find manifest at path/to/current/dir/manifest.json'
134
- )
135
- end
136
- end
137
- end
138
-
139
- describe '.remove' do
140
- let(:manifest_name) { 'manifest.json' }
141
- let(:pwd) { 'path/to/current/dir' }
142
-
143
- let(:args) { [manifest_name] }
144
- let(:file_exist) { true }
145
-
146
- let(:cmd) { 'do something' }
147
- let(:cmds) { [cmd, cmd] }
148
-
149
- let(:data) do
150
- {
151
- 'name' => 'test_manifest',
152
- 'version' => '0.1.0',
153
- 'steps' => [
154
- {
155
- 'name' => 'remove',
156
- 'exe' => {
157
- 'remove' => {
158
- 'cmd' => cmds
159
- }
160
- }
161
- }
162
- ]
163
- }
164
- end
165
-
166
- let(:manifest) do
167
- GeneSystem::Manifest.new(
168
- File.join(pwd, manifest_name),
169
- data
170
- )
171
- end
172
- let(:platform) { double(GeneSystem::Platform) }
173
-
174
- before do
175
- allow(Dir).to receive(:pwd).and_return(pwd)
176
- allow(File).to receive(:exist?).and_return(file_exist)
177
-
178
- allow(GeneSystem::Manifest).to receive(:new_from_file)
179
- .and_return(manifest)
180
-
181
- allow(GeneSystem::Platform).to receive(:new)
182
- .and_return(platform)
183
-
184
- allow(platform).to receive(:execute_commands)
185
-
186
- allow(GeneSystem::CLI).to receive(:print_message)
187
- end
188
-
189
- describe 'remooving manifest' do
190
- before { described_class.remove(args) }
191
-
192
- it 'loads manifest' do
193
- expect(GeneSystem::Manifest)
194
- .to have_received(:new_from_file)
195
- .with(File.join(pwd, manifest_name))
196
- end
197
-
198
- it 'executes remove on platform' do
199
- expect(platform)
200
- .to have_received(:execute_commands)
201
- .with(cmds)
202
- end
203
-
204
- it 'prints success message' do
205
- expect(GeneSystem::CLI).to have_received(:print_message)
206
- .with("\nmanifest successfully removed")
207
- end
208
- end
209
-
210
- context 'when path is not provided' do
211
- it 'raises no manifest path provided runtime error' do
212
- expect { described_class.install }.to raise_error(
213
- RuntimeError,
214
- 'no manifest path provided'
215
- )
216
- end
217
- end
218
-
219
- context 'when manifest cannot be created at specified path' do
220
- let(:file_exist) { false }
221
-
222
- it 'raises cannot find manifest RuntimeError' do
223
- expect { described_class.install(args) }.to raise_error(
224
- RuntimeError,
225
- 'cannot find manifest at path/to/current/dir/manifest.json'
226
- )
227
- end
228
- end
229
- end
230
- end