nightcrawler_swift 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -1
  4. data/Changelog.md +12 -2
  5. data/Gemfile.lock +11 -1
  6. data/README.md +112 -7
  7. data/bin/nswift +1 -1
  8. data/lib/nightcrawler_swift/cli/commands/url_for.rb +9 -0
  9. data/lib/nightcrawler_swift/cli/formatters/basic.rb +40 -0
  10. data/lib/nightcrawler_swift/cli/opt_parser.rb +81 -0
  11. data/lib/nightcrawler_swift/cli/runner.rb +127 -0
  12. data/lib/nightcrawler_swift/cli.rb +16 -173
  13. data/lib/nightcrawler_swift/command.rb +5 -14
  14. data/lib/nightcrawler_swift/commands/delete.rb +4 -6
  15. data/lib/nightcrawler_swift/commands/download.rb +4 -6
  16. data/lib/nightcrawler_swift/commands/list.rb +0 -6
  17. data/lib/nightcrawler_swift/commands/upload.rb +1 -4
  18. data/lib/nightcrawler_swift/connection.rb +15 -15
  19. data/lib/nightcrawler_swift/exceptions.rb +2 -1
  20. data/lib/nightcrawler_swift/gateway.rb +68 -0
  21. data/lib/nightcrawler_swift/version.rb +1 -1
  22. data/lib/nightcrawler_swift.rb +7 -2
  23. data/nightcrawler_swift.gemspec +1 -0
  24. data/spec/lib/nightcrawler_swift/cli/commands/url_for_spec.rb +34 -0
  25. data/spec/lib/nightcrawler_swift/cli/formatters/basic_spec.rb +117 -0
  26. data/spec/lib/nightcrawler_swift/cli/opt_parser_spec.rb +135 -0
  27. data/spec/lib/nightcrawler_swift/{cli_spec.rb → cli/runner_spec.rb} +133 -136
  28. data/spec/lib/nightcrawler_swift/command_spec.rb +17 -32
  29. data/spec/lib/nightcrawler_swift/commands/delete_spec.rb +8 -29
  30. data/spec/lib/nightcrawler_swift/commands/download_spec.rb +8 -29
  31. data/spec/lib/nightcrawler_swift/commands/list_spec.rb +14 -44
  32. data/spec/lib/nightcrawler_swift/commands/upload_spec.rb +1 -8
  33. data/spec/lib/nightcrawler_swift/connection_spec.rb +26 -9
  34. data/spec/lib/nightcrawler_swift/gateway_spec.rb +139 -0
  35. data/spec/lib/nightcrawler_swift_spec.rb +15 -2
  36. data/spec/spec_helper.rb +3 -0
  37. metadata +31 -4
@@ -0,0 +1,135 @@
1
+ require "spec_helper"
2
+ require "nightcrawler_swift/cli"
3
+
4
+ describe NightcrawlerSwift::CLI::OptParser do
5
+
6
+ let :runner do
7
+ instance_double "Runner", options: OpenStruct.new(bucket: nil, config_file: nil, default_config_file: true)
8
+ end
9
+
10
+ let :config_dir do
11
+ File.expand_path(File.join(File.dirname(__FILE__), "../../../fixtures"))
12
+ end
13
+
14
+ subject do
15
+ NightcrawlerSwift::CLI::OptParser.new runner
16
+ end
17
+
18
+ describe "options" do
19
+
20
+ ["-v", "--version"].each do |switch|
21
+ context switch do
22
+ it "prints the version number" do
23
+ allow(runner).to receive(:argv).and_return([switch])
24
+ expect(runner).to receive(:log).with(NightcrawlerSwift::VERSION)
25
+ expect { subject.parse! }.to raise_error SystemExit
26
+ end
27
+ end
28
+ end
29
+
30
+ ["-h", "--help"].each do |switch|
31
+ context switch do
32
+ it "prints the help" do
33
+ allow(runner).to receive(:argv).and_return([switch])
34
+ expect(runner).to receive(:log).with(subject.help)
35
+ expect { subject.parse! }.to raise_error SystemExit
36
+ end
37
+ end
38
+ end
39
+
40
+ ["-c PATH", "--config=PATH"].each do |switch|
41
+ context switch do
42
+ let :config_file do
43
+ File.join(config_dir, "#{NightcrawlerSwift::CLI::CONFIG_FILE}-test")
44
+ end
45
+
46
+ let :command do
47
+ switch.gsub(/PATH/, config_file)
48
+ end
49
+
50
+ before do
51
+ File.open(config_file, "w") {|f| f.write("test")}
52
+ end
53
+
54
+ after do
55
+ File.delete(config_file) if File.exist?(config_file)
56
+ end
57
+
58
+ it "configures the config_file" do
59
+ allow(runner).to receive(:log)
60
+ allow(runner).to receive(:argv).and_return([command])
61
+ subject.parse!
62
+ expect(runner.options.config_file).to eql config_file
63
+ expect(runner.options.default_config_file).to eql false
64
+ end
65
+
66
+ context "when the config file does not exist" do
67
+ let :invalid_filename do
68
+ "invalid-file"
69
+ end
70
+
71
+ let :invalid_filepath do
72
+ File.expand_path(File.join(File.dirname(__FILE__), "../../../../", invalid_filename))
73
+ end
74
+
75
+ let :command do
76
+ switch.gsub(/PATH/, invalid_filename)
77
+ end
78
+
79
+ it "prints the error and exit with a failure" do
80
+ expect(runner).to receive(:argv).and_return([command])
81
+ expect(runner).to receive(:log).with("Error: No such file or directory - #{invalid_filepath}")
82
+ exited = false
83
+
84
+ begin
85
+ subject.parse!
86
+ rescue SystemExit => e
87
+ exited = true
88
+ expect(e.status).to eql 1
89
+ ensure
90
+ expect(exited).to eql true
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ ["-b NAME", "--bucket=NAME"].each do |switch|
98
+ context switch do
99
+ let :bucket_name do
100
+ "rogue"
101
+ end
102
+
103
+ let :command do
104
+ switch.gsub(/NAME/, bucket_name)
105
+ end
106
+
107
+ it "configures the bucket name" do
108
+ allow(runner).to receive(:argv).and_return([command])
109
+ allow(runner).to receive(:log)
110
+ subject.parse!
111
+ expect(runner.options.bucket).to eql bucket_name
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "#parse!" do
118
+ before do
119
+ allow(runner).to receive(:argv).and_return([])
120
+ end
121
+
122
+ it "calls method 'parse!' in OptionParser with runner argv" do
123
+ expect(subject.parser).to receive(:parse!).with(runner.argv)
124
+ subject.parse!
125
+ end
126
+ end
127
+
128
+ describe "#help" do
129
+ it "calls method 'help' in OptionParser" do
130
+ expect(subject.parser).to receive(:help)
131
+ subject.help
132
+ end
133
+ end
134
+
135
+ end
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
  require "nightcrawler_swift/cli"
3
3
 
4
- describe NightcrawlerSwift::CLI do
4
+ describe NightcrawlerSwift::CLI::Runner do
5
5
 
6
6
  let :config_dir do
7
- File.expand_path(File.join(File.dirname(__FILE__), "../../fixtures"))
7
+ File.expand_path(File.join(File.dirname(__FILE__), "../../../fixtures"))
8
8
  end
9
9
 
10
10
  let :config_file do
@@ -16,7 +16,15 @@ describe NightcrawlerSwift::CLI do
16
16
  end
17
17
 
18
18
  let :connection_success_json do
19
- JSON.parse File.read(File.join(File.dirname(__FILE__), "../..", "fixtures/auth_success.json"))
19
+ JSON.parse File.read(File.join(config_dir, "auth_success.json"))
20
+ end
21
+
22
+ let :formatter do
23
+ NightcrawlerSwift::CLI::Formatters::Basic.new(subject)
24
+ end
25
+
26
+ let :filepath do
27
+ "testfile.txt"
20
28
  end
21
29
 
22
30
  let :opts do
@@ -30,11 +38,12 @@ describe NightcrawlerSwift::CLI do
30
38
  end
31
39
 
32
40
  subject do
33
- NightcrawlerSwift::CLI.new argv.dup
41
+ NightcrawlerSwift::CLI::Runner.new argv.dup
34
42
  end
35
43
 
36
44
  before do
37
- allow(subject).to receive(:user_home_dir).and_return(config_dir)
45
+ allow(Dir).to receive(:home).and_return(config_dir)
46
+ allow(NightcrawlerSwift::CLI::Formatters::Basic).to receive(:new).and_return(formatter)
38
47
  end
39
48
 
40
49
  after do
@@ -61,66 +70,6 @@ describe NightcrawlerSwift::CLI do
61
70
  end
62
71
  end
63
72
 
64
- shared_examples "CLI with parsed parameters" do
65
- context "--version or -v" do
66
- it "prints the version number" do
67
- subject.argv << "-v"
68
- expect(subject).to receive(:log).with(NightcrawlerSwift::VERSION)
69
- expect { subject.run }.to raise_error SystemExit
70
-
71
- expect(subject).to receive(:log).with(NightcrawlerSwift::VERSION)
72
- subject.argv = (argv << "--version")
73
- expect { subject.run }.to raise_error SystemExit
74
- end
75
- end
76
-
77
- context "--help or -h" do
78
- before do
79
- subject.send :configure_default_options
80
- subject.send :configure_opt_parser
81
-
82
- allow(subject).to receive(:configure_default_options)
83
- allow(subject).to receive(:configure_opt_parser)
84
- end
85
-
86
- it "prints the help" do
87
- subject.argv << "-h"
88
- expect(subject).to receive(:log).with(subject.opt_parser.help)
89
- expect { subject.run }.to raise_error SystemExit
90
-
91
- expect(subject).to receive(:log).with(subject.opt_parser.help)
92
- subject.argv = (argv << "--help")
93
- expect { subject.run }.to raise_error SystemExit
94
- end
95
- end
96
-
97
- context "--config or -c" do
98
- let :config_file do
99
- File.join(config_dir, "#{NightcrawlerSwift::CLI::CONFIG_FILE}-test")
100
- end
101
-
102
- before do
103
- allow(subject).to receive(:execute_command)
104
- allow(subject).to receive(:log)
105
- File.open(config_file, "w") {|f| f.write("test")}
106
- end
107
-
108
- after do
109
- File.delete(config_file) if File.exist?(config_file)
110
- end
111
-
112
- it "configures the config_file" do
113
- subject.argv << "-c #{config_file}"
114
- subject.run
115
- expect(subject.options.config_file).to eql config_file
116
-
117
- subject.argv = (argv << "--config=#{config_file}")
118
- subject.run
119
- expect(subject.options.config_file).to eql config_file
120
- end
121
- end
122
- end
123
-
124
73
  shared_examples "CLI that creates a sample config file" do
125
74
  before do
126
75
  allow(subject).to receive(:execute_command)
@@ -131,7 +80,7 @@ describe NightcrawlerSwift::CLI do
131
80
  expect(File.exist?(config_file)).to eql false
132
81
  expect { subject.run }.to raise_error SystemExit
133
82
  expect(File.exist?(config_file)).to eql true
134
- expect(File.read(config_file)).to eql subject.send(:sample_rcfile)
83
+ expect(File.read(config_file)).to eql NightcrawlerSwift::CLI.sample_rcfile
135
84
  end
136
85
 
137
86
  it "flags as not configured" do
@@ -146,7 +95,7 @@ describe NightcrawlerSwift::CLI do
146
95
  end
147
96
 
148
97
  before do
149
- allow(subject).to receive(command_method)
98
+ allow(formatter).to receive(command_method)
150
99
  allow(NightcrawlerSwift).to receive(:connection).and_return(connection)
151
100
  File.open(config_file, "w") {|f| f.write(opts.to_json)}
152
101
  end
@@ -167,6 +116,21 @@ describe NightcrawlerSwift::CLI do
167
116
  end
168
117
  end
169
118
 
119
+ context "with a custom bucket name" do
120
+ let(:bucket_name) { "rogue" }
121
+
122
+ before do
123
+ subject.send :configure_default_options
124
+ expect(subject.options.bucket).to be_nil
125
+ end
126
+
127
+ it "overrides the default name" do
128
+ allow(subject).to receive(:parse_parameters) { subject.options.bucket = bucket_name }
129
+ subject.run
130
+ expect(NightcrawlerSwift.options.bucket).to eql bucket_name
131
+ end
132
+ end
133
+
170
134
  it "writes the auth_response into cache file" do
171
135
  expect(File.exist?(cache_file)).to eql false
172
136
  expect(connection).to receive(:auth_response).and_return(OpenStruct.new(connection_success_json))
@@ -174,120 +138,153 @@ describe NightcrawlerSwift::CLI do
174
138
  expect(File.exist?(cache_file)).to eql true
175
139
  expect(File.read(cache_file)).to eql connection_success_json.to_json
176
140
  end
141
+
142
+ context "when rescue NightcrawlerSwift::Exceptions::BaseError" do
143
+ let(:message) { "error" }
144
+
145
+ before do
146
+ NightcrawlerSwift.logger = Logger.new(StringIO.new)
147
+ end
148
+
149
+ it "prints the error and exit with failure" do
150
+ expect(subject).to receive(:connect_and_execute).and_raise(NightcrawlerSwift::Exceptions::BaseError.new(message))
151
+ exited = false
152
+
153
+ begin
154
+ subject.run
155
+ rescue SystemExit => e
156
+ exited = true
157
+ expect(e.status).to eql 1
158
+ ensure
159
+ expect(exited).to eql true
160
+ end
161
+ end
162
+ end
163
+
164
+ context "when rescue Errno::ENOENT" do
165
+ before do
166
+ NightcrawlerSwift.logger = Logger.new(StringIO.new)
167
+ end
168
+
169
+ it "prints the error and exit with failure" do
170
+ expect(subject).to receive(:connect_and_execute).and_raise(Errno::ENOENT.new)
171
+ exited = false
172
+
173
+ begin
174
+ subject.run
175
+ rescue SystemExit => e
176
+ exited = true
177
+ expect(e.status).to eql 1
178
+ ensure
179
+ expect(exited).to eql true
180
+ end
181
+ end
182
+ end
177
183
  end
178
184
 
179
185
  describe "command list" do
180
186
  let(:argv) { ["list"] }
181
187
  let(:command) { NightcrawlerSwift::List.new }
182
188
  let(:command_method) { :command_list }
183
- let :result do
184
- [{
185
- "hash"=>"c9df50d4a29542f8b6d426a50c72b3de",
186
- "last_modified"=>"2014-08-27T19:35:46.053560",
187
- "bytes"=>4994,
188
- "name"=>"assets/file.png",
189
- "content_type"=>"image/png"
190
- }]
191
- end
192
189
 
193
190
  it_behaves_like "CLI with default options"
194
- it_behaves_like "CLI with parsed parameters"
195
191
  it_behaves_like "CLI that creates a sample config file"
196
192
  it_behaves_like "CLI that uses the configured command"
197
-
198
- context "when executing the command" do
199
- before do
200
- File.open(config_file, "w") {|f| f.write(opts.to_json)}
201
- end
202
-
203
- it "lists all files in the bucket/container configured" do
204
- expect(NightcrawlerSwift::List).to receive(:new).and_return(command)
205
- expect(command).to receive(:execute).and_return(result)
206
- expect(subject).to receive(:log).with(result.first["name"])
207
- subject.run
208
- end
209
- end
210
193
  end
211
194
 
212
195
  describe "command download" do
213
- let(:filepath) { "testfile.txt" }
214
196
  let(:argv) { ["download", filepath] }
215
197
  let(:command) { NightcrawlerSwift::Download.new }
216
198
  let(:command_method) { :command_download }
217
199
 
218
200
  it_behaves_like "CLI with default options"
219
- it_behaves_like "CLI with parsed parameters"
220
201
  it_behaves_like "CLI that creates a sample config file"
221
202
  it_behaves_like "CLI that uses the configured command"
222
-
223
- context "when executing the command" do
224
- before do
225
- File.open(config_file, "w") {|f| f.write(opts.to_json)}
226
- end
227
-
228
- it "downloads the file" do
229
- expect(NightcrawlerSwift::Download).to receive(:new).and_return(command)
230
- expect(command).to receive(:execute).with(filepath).and_return("test-content")
231
- expect(subject).to receive(:log).with("test-content")
232
- subject.run
233
- end
234
- end
235
203
  end
236
204
 
237
205
  describe "command upload" do
238
- let(:swiftpath) { "testfile.txt" }
239
- let(:realpath) { File.join(config_dir, swiftpath) }
240
- let(:argv) { ["upload", realpath, swiftpath] }
206
+ let(:realpath) { File.join(config_dir, filepath) }
207
+ let(:argv) { ["upload", realpath, filepath] }
241
208
  let(:command) { NightcrawlerSwift::Upload.new }
242
209
  let(:command_method) { :command_upload }
243
210
 
244
211
  it_behaves_like "CLI with default options"
245
- it_behaves_like "CLI with parsed parameters"
246
212
  it_behaves_like "CLI that creates a sample config file"
247
213
  it_behaves_like "CLI that uses the configured command"
248
-
249
- context "when executing the command" do
250
- before do
251
- File.open(config_file, "w") {|f| f.write(opts.to_json)}
252
- File.open(realpath, "w") {|f| f.write("test") }
253
- end
254
-
255
- after do
256
- File.delete(realpath) if File.exist?(realpath)
257
- end
258
-
259
- it "uploads the file" do
260
- expect(NightcrawlerSwift::Upload).to receive(:new).and_return(command)
261
- expect(command).to receive(:execute).with(swiftpath, instance_of(File)).and_return(true)
262
- expect(subject).to receive(:log).with("success")
263
- subject.run
264
- end
265
- end
266
214
  end
267
215
 
268
216
  describe "command delete" do
269
- let(:filepath) { "testfile.txt" }
270
217
  let(:argv) { ["delete", filepath] }
271
218
  let(:command) { NightcrawlerSwift::Delete.new }
272
219
  let(:command_method) { :command_delete }
273
220
 
274
221
  it_behaves_like "CLI with default options"
275
- it_behaves_like "CLI with parsed parameters"
276
222
  it_behaves_like "CLI that creates a sample config file"
277
223
  it_behaves_like "CLI that uses the configured command"
224
+ end
225
+
226
+ describe "command delete" do
227
+ let(:argv) { ["url-for", filepath] }
228
+ let(:command) { NightcrawlerSwift::CLI::UrlFor.new }
229
+ let(:command_method) { :command_url_for }
230
+
231
+ it_behaves_like "CLI with default options"
232
+ it_behaves_like "CLI that creates a sample config file"
233
+ it_behaves_like "CLI that uses the configured command"
234
+ end
235
+
236
+ describe "validation of commands" do
237
+ context "when no command is provided" do
238
+ let(:argv) { [] }
278
239
 
279
- context "when executing the command" do
280
240
  before do
281
- File.open(config_file, "w") {|f| f.write(opts.to_json)}
241
+ subject.send :configure_default_options
242
+ subject.send :configure_opt_parser
282
243
  end
283
244
 
284
- it "downloads the file" do
285
- expect(NightcrawlerSwift::Delete).to receive(:new).and_return(command)
286
- expect(command).to receive(:execute).with(filepath).and_return(true)
287
- expect(subject).to receive(:log).with("success")
288
- subject.run
245
+ it "prints the help and exit with success" do
246
+ exited = false
247
+ expect(subject).to receive(:log).with(subject.opt_parser.help)
248
+ begin
249
+ subject.run
250
+ rescue SystemExit => e
251
+ exited = true
252
+ expect(e.status).to eql 0
253
+ ensure
254
+ expect(exited).to eql true
255
+ end
256
+ end
257
+ end
258
+
259
+ context "when the command does not exist" do
260
+ let(:argv) { ["wrong"] }
261
+
262
+ it "prints the error and exit with failure" do
263
+ exited = false
264
+ expect(subject).to receive(:log).with("Error: Unknown command 'wrong'")
265
+ begin
266
+ subject.run
267
+ rescue SystemExit => e
268
+ exited = true
269
+ expect(e.status).to eql 1
270
+ ensure
271
+ expect(exited).to eql true
272
+ end
289
273
  end
290
274
  end
291
275
  end
292
276
 
277
+ describe "#log" do
278
+ let(:argv) { [] }
279
+
280
+ before do
281
+ NightcrawlerSwift.logger = Logger.new(StringIO.new)
282
+ end
283
+
284
+ it "uses NightcrawlerSwift.logger" do
285
+ expect(NightcrawlerSwift).to receive(:logger).and_call_original
286
+ subject.log "stuff"
287
+ end
288
+ end
289
+
293
290
  end
@@ -17,21 +17,14 @@ describe NightcrawlerSwift::Command do
17
17
  let(:connection) { NightcrawlerSwift::Connection.new }
18
18
  let(:restclient) { double(:restclient, put: response, get: response, delete: response) }
19
19
  let(:response) { double(:response) }
20
- let(:url) { "http://url.com" }
20
+ let(:url) { "http://url-com" }
21
21
  let(:token) { "token" }
22
22
  let(:expires_at) { (DateTime.now + 60).to_time }
23
23
 
24
- shared_examples "resource configured with NightcrawlerSwift.options" do
25
- it "uses the configured verify_ssl" do
26
- NightcrawlerSwift.configure verify_ssl: true
24
+ shared_examples "command with configured gateway" do
25
+ it "creates a new gateway with the url" do
26
+ expect(NightcrawlerSwift::Gateway).to receive(:new).with(url).and_call_original
27
27
  execute_http
28
- expect(RestClient::Resource).to have_received(:new).with(url, hash_including(verify_ssl: true))
29
- end
30
-
31
- it "uses the configured timeout" do
32
- NightcrawlerSwift.configure timeout: 10
33
- execute_http
34
- expect(RestClient::Resource).to have_received(:new).with(url, hash_including(timeout: 10))
35
28
  end
36
29
  end
37
30
 
@@ -66,67 +59,59 @@ describe NightcrawlerSwift::Command do
66
59
  end
67
60
 
68
61
  describe "#get" do
69
- let :get do
62
+ let :execute_http do
70
63
  subject.send :get, url, headers: {content_type: :json}
71
64
  end
72
65
 
73
- let(:execute_http) { get }
74
- it_behaves_like "resource configured with NightcrawlerSwift.options"
66
+ it_behaves_like "command with configured gateway"
75
67
 
76
68
  it "sends headers with token" do
77
- get
69
+ execute_http
78
70
  expect(restclient).to have_received(:get).with(content_type: :json, "X-Storage-Token" => token)
79
71
  end
80
72
 
81
73
  it "returns RestClient response" do
82
- expect(get).to eql(response)
74
+ expect(execute_http).to eql(response)
83
75
  end
84
76
  end
85
77
 
86
78
  describe "#delete" do
87
- let :delete do
79
+ let :execute_http do
88
80
  subject.send :delete, url, headers: {content_type: :json}
89
81
  end
90
82
 
91
- let(:execute_http) { delete }
92
- it_behaves_like "resource configured with NightcrawlerSwift.options"
83
+ it_behaves_like "command with configured gateway"
93
84
 
94
85
  it "sends headers with token" do
95
- delete
86
+ execute_http
96
87
  expect(restclient).to have_received(:delete).with(content_type: :json, "X-Storage-Token" => token)
97
88
  end
98
89
 
99
90
  it "returns RestClient response" do
100
- expect(delete).to eql(response)
91
+ expect(execute_http).to eql(response)
101
92
  end
102
93
  end
103
94
 
104
95
  describe "#put" do
105
- let :put do
96
+ let :execute_http do
106
97
  subject.send(:put, url, body: 'content', headers: {a: 1})
107
98
  end
108
99
 
109
- let(:execute_http) { put }
110
- it_behaves_like "resource configured with NightcrawlerSwift.options"
100
+ it_behaves_like "command with configured gateway"
111
101
 
112
102
  it "returns RestClient response" do
113
- expect(put).to eql(response)
103
+ expect(execute_http).to eql(response)
114
104
  end
115
105
 
116
106
  it "sends body" do
117
- put
107
+ execute_http
118
108
  expect(restclient).to have_received(:put).with('content', anything)
119
109
  end
120
110
 
121
111
  it "sends headers with token" do
122
- put
112
+ execute_http
123
113
  expect(restclient).to have_received(:put).with(anything, {a: 1, "X-Storage-Token" => token})
124
114
  end
125
-
126
- it "uses url to initialize RestClient" do
127
- put
128
- expect(RestClient::Resource).to have_received(:new).with(url, verify_ssl: false, timeout: nil)
129
- end
130
115
  end
131
116
 
132
117
  end
@@ -23,15 +23,15 @@ describe NightcrawlerSwift::Delete do
23
23
  subject.execute "file_path"
24
24
  end
25
25
 
26
- before do
27
- allow(subject).to receive(:delete).and_return(response)
28
- end
29
-
30
26
  context "success" do
31
27
  let :response do
32
28
  double(:response, code: 200)
33
29
  end
34
30
 
31
+ before do
32
+ allow(subject).to receive(:delete).and_return(response)
33
+ end
34
+
35
35
  it "deletes using upload url" do
36
36
  execute
37
37
  expect(subject).to have_received(:delete).with("server-url/file_path", headers: {accept: :json})
@@ -42,31 +42,10 @@ describe NightcrawlerSwift::Delete do
42
42
  end
43
43
  end
44
44
 
45
- context "when the file does not exist" do
46
- let :response do
47
- double(:response, code: 404)
48
- end
49
-
50
- before do
51
- allow(subject).to receive(:delete).and_raise(RestClient::ResourceNotFound.new(response))
52
- end
53
-
54
- it "raises NightcrawlerSwift::Exceptions::NotFoundError" do
55
- expect { execute }.to raise_error NightcrawlerSwift::Exceptions::NotFoundError
56
- end
57
- end
58
-
59
- context "when another error happens" do
60
- let :response do
61
- double(:response, code: 500)
62
- end
63
-
64
- before do
65
- allow(subject).to receive(:delete).and_raise(RuntimeError.new(response))
66
- end
67
-
68
- it "raises NightcrawlerSwift::Exceptions::ConnectionError" do
69
- expect { execute }.to raise_error NightcrawlerSwift::Exceptions::ConnectionError
45
+ context "when the path was not informed" do
46
+ it "raises NightcrawlerSwift::Exceptions::ValidationError" do
47
+ expect { subject.execute nil }.to raise_error NightcrawlerSwift::Exceptions::ValidationError
48
+ expect { subject.execute "" }.to raise_error NightcrawlerSwift::Exceptions::ValidationError
70
49
  end
71
50
  end
72
51
  end