http_stub 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,26 @@ module HttpStub
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(command)
|
11
|
-
|
12
|
-
|
11
|
+
begin
|
12
|
+
response = Net::HTTP.start(host, port) { |http| http.request(command.request) }
|
13
|
+
raise "#{error_message_prefix(command)}: #{response.code} #{response.message}" unless response.code == "200"
|
14
|
+
rescue Exception => exc
|
15
|
+
raise "#{error_message_prefix(command)}: #{exc}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def host
|
22
|
+
@configurer.get_host
|
23
|
+
end
|
24
|
+
|
25
|
+
def port
|
26
|
+
@configurer.get_port
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message_prefix(command)
|
30
|
+
"Error occurred #{command.description} whilst configuring #{@configurer.get_base_uri}: "
|
13
31
|
end
|
14
32
|
|
15
33
|
end
|
data/lib/http_stub/version.rb
CHANGED
@@ -1,26 +1,56 @@
|
|
1
|
-
describe HttpStub::Configurer::CommandProcessor
|
2
|
-
include_context "server integration"
|
1
|
+
describe HttpStub::Configurer::CommandProcessor do
|
3
2
|
|
4
|
-
let(:configurer) { double(HttpStub::Configurer, get_host: "localhost", get_port: 8001) }
|
5
3
|
let(:command) { HttpStub::Configurer::Command.new(request: request, description: "performing an operation") }
|
4
|
+
let(:server_base_uri) { "http://localhost:8001" }
|
5
|
+
let(:configurer) do
|
6
|
+
double(HttpStub::Configurer, get_base_uri: server_base_uri, get_host: "localhost", get_port: 8001)
|
7
|
+
end
|
6
8
|
|
7
9
|
let(:command_processor) { HttpStub::Configurer::CommandProcessor.new(configurer) }
|
8
10
|
|
9
|
-
|
11
|
+
context "when the server is running" do
|
12
|
+
|
13
|
+
include_context "server integration"
|
14
|
+
|
15
|
+
describe "#process" do
|
16
|
+
|
17
|
+
describe "when the server responds with a 200 response" do
|
10
18
|
|
11
|
-
|
19
|
+
let(:request) { Net::HTTP::Get.new("/stubs") }
|
12
20
|
|
13
|
-
|
21
|
+
it "should execute without error" do
|
22
|
+
lambda { command_processor.process(command) }.should_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when the server responds with a non-200 response" do
|
28
|
+
|
29
|
+
let(:request) { Net::HTTP::Get.new("/causes_error") }
|
30
|
+
|
31
|
+
it "should raise an exception that includes the server base URI" do
|
32
|
+
lambda { command_processor.process(command) }.should raise_error(/#{server_base_uri}/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise an exception that includes the commands description" do
|
36
|
+
lambda { command_processor.process(command) }.should raise_error(/performing an operation/)
|
37
|
+
end
|
14
38
|
|
15
|
-
it "should execute without error" do
|
16
|
-
lambda { command_processor.process(command) }.should_not raise_error
|
17
39
|
end
|
18
40
|
|
19
41
|
end
|
20
42
|
|
21
|
-
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the server is unavailable" do
|
22
46
|
|
23
|
-
|
47
|
+
let(:request) { Net::HTTP::Get.new("/does/not/exist") }
|
48
|
+
|
49
|
+
describe "#process" do
|
50
|
+
|
51
|
+
it "should raise an exception that includes the server base URI" do
|
52
|
+
lambda { command_processor.process(command) }.should raise_error(/#{server_base_uri}/)
|
53
|
+
end
|
24
54
|
|
25
55
|
it "should raise an exception that includes the commands description" do
|
26
56
|
lambda { command_processor.process(command) }.should raise_error(/performing an operation/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_stub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-10-
|
13
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sinatra
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ~>
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '4.
|
118
|
+
version: '4.2'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
requirements:
|
124
124
|
- - ~>
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
version: '4.
|
126
|
+
version: '4.2'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
name: travis-lint
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,7 +195,7 @@ dependencies:
|
|
195
195
|
requirements:
|
196
196
|
- - ~>
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version: '0.
|
198
|
+
version: '0.12'
|
199
199
|
type: :development
|
200
200
|
prerelease: false
|
201
201
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ dependencies:
|
|
203
203
|
requirements:
|
204
204
|
- - ~>
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version: '0.
|
206
|
+
version: '0.12'
|
207
207
|
- !ruby/object:Gem::Dependency
|
208
208
|
name: wait_until
|
209
209
|
requirement: !ruby/object:Gem::Requirement
|
@@ -325,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
325
|
version: '0'
|
326
326
|
segments:
|
327
327
|
- 0
|
328
|
-
hash:
|
328
|
+
hash: 3958008164617711389
|
329
329
|
requirements: []
|
330
330
|
rubyforge_project: http_stub
|
331
331
|
rubygems_version: 1.8.25
|