http_stub 0.13.5 → 0.14.0.rc1

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +13 -4
  3. data/lib/http_stub/configurer.rb +9 -63
  4. data/lib/http_stub/configurer/deprecated_dsl.rb +57 -0
  5. data/lib/http_stub/configurer/request/stub.rb +7 -13
  6. data/lib/http_stub/configurer/request/stub_activator.rb +8 -4
  7. data/lib/http_stub/configurer/request/stub_activator_payload_builder.rb +25 -0
  8. data/lib/http_stub/configurer/request/stub_payload_builder.rb +44 -0
  9. data/lib/http_stub/configurer/server/buffered_command_processor.rb +24 -0
  10. data/lib/http_stub/configurer/server/command.rb +18 -0
  11. data/lib/http_stub/configurer/server/command_processor.rb +38 -0
  12. data/lib/http_stub/configurer/server/dsl.rb +56 -0
  13. data/lib/http_stub/configurer/server/facade.rb +57 -0
  14. data/lib/http_stub/configurer/server/request_processor.rb +30 -0
  15. data/lib/http_stub/models/registry.rb +4 -0
  16. data/lib/http_stub/models/stub.rb +2 -1
  17. data/lib/http_stub/models/stub_registry.rb +29 -0
  18. data/lib/http_stub/models/stub_triggers.rb +23 -0
  19. data/lib/http_stub/rake/server_tasks.rb +2 -5
  20. data/lib/http_stub/server.rb +14 -4
  21. data/lib/http_stub/version.rb +1 -1
  22. data/lib/http_stub/views/_stub.haml +7 -0
  23. data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +232 -0
  24. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +8 -8
  25. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +8 -8
  26. data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +14 -14
  27. data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +74 -0
  28. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +19 -26
  29. data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +203 -0
  30. data/spec/lib/http_stub/configurer/request/stub_spec.rb +18 -157
  31. data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +35 -0
  32. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +62 -0
  33. data/spec/lib/http_stub/configurer/server/command_spec.rb +25 -0
  34. data/spec/lib/http_stub/configurer/server/dsl_spec.rb +241 -0
  35. data/spec/lib/http_stub/configurer/server/facade_spec.rb +253 -0
  36. data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +99 -0
  37. data/spec/lib/http_stub/configurer_integration_spec.rb +172 -122
  38. data/spec/lib/http_stub/configurer_spec.rb +4 -4
  39. data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +25 -25
  40. data/spec/lib/http_stub/controllers/stub_controller_spec.rb +22 -22
  41. data/spec/lib/http_stub/hash_extensions_spec.rb +24 -24
  42. data/spec/lib/http_stub/models/exact_value_matcher_spec.rb +4 -4
  43. data/spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb +29 -29
  44. data/spec/lib/http_stub/models/headers_spec.rb +10 -10
  45. data/spec/lib/http_stub/models/omitted_value_matcher_spec.rb +8 -8
  46. data/spec/lib/http_stub/models/regexp_value_matcher_spec.rb +6 -6
  47. data/spec/lib/http_stub/models/registry_spec.rb +71 -28
  48. data/spec/lib/http_stub/models/request_header_parser_spec.rb +4 -4
  49. data/spec/lib/http_stub/models/request_pipeline_spec.rb +2 -2
  50. data/spec/lib/http_stub/models/response_spec.rb +38 -38
  51. data/spec/lib/http_stub/models/string_value_matcher_spec.rb +25 -25
  52. data/spec/lib/http_stub/models/stub_activator_spec.rb +15 -15
  53. data/spec/lib/http_stub/models/stub_headers_spec.rb +18 -18
  54. data/spec/lib/http_stub/models/stub_parameters_spec.rb +16 -16
  55. data/spec/lib/http_stub/models/stub_registry_integration_spec.rb +62 -0
  56. data/spec/lib/http_stub/models/stub_registry_spec.rb +152 -0
  57. data/spec/lib/http_stub/models/stub_spec.rb +67 -43
  58. data/spec/lib/http_stub/models/stub_triggers_spec.rb +64 -0
  59. data/spec/lib/http_stub/models/stub_uri_spec.rb +9 -9
  60. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +7 -7
  61. data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +5 -5
  62. data/spec/lib/http_stub/rake/server_tasks_spec.rb +17 -15
  63. data/spec/lib/http_stub/server_daemon_spec.rb +16 -16
  64. data/spec/lib/http_stub/server_integration_spec.rb +112 -65
  65. data/spec/lib/http_stub/server_spec.rb +134 -96
  66. data/spec/spec_helper.rb +1 -1
  67. data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +27 -0
  68. data/spec/support/server_integration.rb +2 -2
  69. metadata +69 -30
  70. data/lib/http_stub/configurer/command.rb +0 -26
  71. data/lib/http_stub/configurer/command_processor.rb +0 -36
  72. data/lib/http_stub/configurer/impatient_command_chain.rb +0 -13
  73. data/lib/http_stub/configurer/patient_command_chain.rb +0 -25
  74. data/spec/lib/http_stub/configurer/command_processor_integration_spec.rb +0 -63
  75. data/spec/lib/http_stub/configurer/command_spec.rb +0 -40
  76. data/spec/lib/http_stub/configurer/impatient_command_chain_spec.rb +0 -17
  77. data/spec/lib/http_stub/configurer/patient_command_chain_spec.rb +0 -73
@@ -4,52 +4,52 @@ describe HttpStub::ServerDaemon do
4
4
 
5
5
  let(:server_daemon) { HttpStub::ServerDaemon.new(name: :sample_server_daemon, port: 8888, configurer: configurer) }
6
6
 
7
- before(:each) { server_daemon.logger.stub(:info) }
7
+ before(:example) { allow(server_daemon.logger).to receive(:info) }
8
8
 
9
9
  describe ".log_dir" do
10
10
 
11
- before(:each) { @original_log_dir = HttpServerManager.log_dir }
11
+ before(:example) { @original_log_dir = HttpServerManager.log_dir }
12
12
 
13
- after(:each) { HttpServerManager.log_dir = @original_log_dir }
13
+ after(:example) { HttpServerManager.log_dir = @original_log_dir }
14
14
 
15
- it "should establish the HttpServerManager log_dir" do
15
+ it "establishes the HttpServerManager log_dir" do
16
16
  HttpStub::ServerDaemon.log_dir = "/some/log/dir"
17
17
 
18
- HttpServerManager.log_dir.should eql("/some/log/dir")
18
+ expect(HttpServerManager.log_dir).to eql("/some/log/dir")
19
19
  end
20
20
 
21
21
  end
22
22
 
23
23
  describe ".pid_dir" do
24
24
 
25
- before(:each) { @original_pid_dir = HttpServerManager.pid_dir }
25
+ before(:example) { @original_pid_dir = HttpServerManager.pid_dir }
26
26
 
27
- after(:each) { HttpServerManager.pid_dir = @original_pid_dir }
27
+ after(:example) { HttpServerManager.pid_dir = @original_pid_dir }
28
28
 
29
- it "should establish the HttpServerManager pid_dir" do
29
+ it "establishes the HttpServerManager pid_dir" do
30
30
  HttpStub::ServerDaemon.pid_dir = "/some/pid/dir"
31
31
 
32
- HttpServerManager.pid_dir.should eql("/some/pid/dir")
32
+ expect(HttpServerManager.pid_dir).to eql("/some/pid/dir")
33
33
  end
34
34
 
35
35
  end
36
36
 
37
37
  describe "#start!" do
38
38
 
39
- before(:each) { server_daemon.stub(:running?).and_return(true) }
39
+ before(:example) { allow(server_daemon).to receive(:running?).and_return(true) }
40
40
 
41
41
  context "when a configurer is provided" do
42
42
 
43
43
  let(:configurer) { double(HttpStub::Configurer).as_null_object }
44
44
 
45
- it "should initialize the configurer" do
46
- configurer.should_receive(:initialize!)
45
+ it "initializes the configurer" do
46
+ expect(configurer).to receive(:initialize!)
47
47
 
48
48
  server_daemon.start!
49
49
  end
50
50
 
51
- it "should log that the server with the provided name has been initialized" do
52
- server_daemon.logger.should_receive(:info).with("sample_server_daemon initialized")
51
+ it "logs that the server with the provided name has been initialized" do
52
+ expect(server_daemon.logger).to receive(:info).with("sample_server_daemon initialized")
53
53
 
54
54
  server_daemon.start!
55
55
  end
@@ -58,8 +58,8 @@ describe HttpStub::ServerDaemon do
58
58
 
59
59
  context "when no configurer is provided" do
60
60
 
61
- it "should not log that the server has been initialized" do
62
- server_daemon.logger.should_not_receive(:info).with("sample_server_daemon initialized")
61
+ it "does not log that the server has been initialized" do
62
+ expect(server_daemon.logger).not_to receive(:info).with("sample_server_daemon initialized")
63
63
 
64
64
  server_daemon.start!
65
65
  end
@@ -8,22 +8,22 @@ describe HttpStub::Server, "when the server is running" do
8
8
 
9
9
  context "when provided with the minimum data required" do
10
10
 
11
- before(:each) do
11
+ before(:example) do
12
12
  @response = HTTParty.post(
13
13
  "#{server_uri}/stubs",
14
14
  body: { uri: "/some/path", method: "get", response: { status: 200, body: "Some body" } }.to_json
15
15
  )
16
16
  end
17
17
 
18
- it "should return a 200 response code" do
19
- @response.code.should eql(200)
18
+ it "returns a 200 response code" do
19
+ expect(@response.code).to eql(200)
20
20
  end
21
21
 
22
- it "should register a stub returning the provided response for a matching request" do
22
+ it "registers a stub returning the provided response for a matching request" do
23
23
  stubbed_response = HTTParty.get("#{server_uri}/some/path")
24
24
 
25
- stubbed_response.code.should eql(200)
26
- stubbed_response.body.should eql("Some body")
25
+ expect(stubbed_response.code).to eql(200)
26
+ expect(stubbed_response.body).to eql("Some body")
27
27
  end
28
28
 
29
29
  end
@@ -32,104 +32,151 @@ describe HttpStub::Server, "when the server is running" do
32
32
 
33
33
  describe "and a configurer with multiple stub activators is initialized" do
34
34
 
35
- before(:all) do
36
- HttpStub::Examples::ConfigurerWithManyActivators.host(server_host)
37
- HttpStub::Examples::ConfigurerWithManyActivators.port(server_port)
38
- HttpStub::Examples::ConfigurerWithManyActivators.initialize!
35
+ before(:context) do
36
+ configurer = HttpStub::Examples::ConfigurerWithManyActivators
37
+ configurer.host(server_host)
38
+ configurer.port(server_port)
39
+ configurer.initialize!
39
40
  end
40
41
 
41
- describe "GET #stubs/activators" do
42
-
43
- let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
44
- let(:response_document) { Nokogiri::HTML(response.body) }
42
+ shared_context "the response contains HTML describing the configurers stubs" do
45
43
 
46
- it "should return a 200 response code" do
47
- response.code.should eql(200)
44
+ it "returns a 200 response code" do
45
+ expect(response.code).to eql(200)
48
46
  end
49
47
 
50
- it "should return response whose body contains a link to each activator in alphabetical order" do
51
- response_document.css("a").each_with_index do |link, i|
52
- link['href'].should eql("/activator_#{i + 1}")
48
+ it "returns a response whose body contains the uri of each stub" do
49
+ (1..3).each do |stub_number|
50
+ expect(response.body).to match(/#{escape_html("/path_#{stub_number}")}/)
53
51
  end
54
52
  end
55
53
 
56
- it "should return a response whose body contains the uri of each activators stub" do
57
- (1..3).each { |i| response.body.should match(/#{escape_html("/path_#{i}")}/) }
54
+ it "returns a response whose body contains the uri of each stub trigger" do
55
+ (1..3).each do |stub_number|
56
+ (1..3).each do |trigger_number|
57
+ expect(response.body).to match(/#{escape_html("/path_#{stub_number}_trigger_#{trigger_number}")}/)
58
+ end
59
+ end
58
60
  end
59
61
 
60
- it "should return a response whose body contains the request headers of each activators stub" do
61
- (1..3).each { |i| response.body.should match(/request_header_#{i}:request_header_value_#{i}/) }
62
+ it "returns a response whose body contains the request headers of each stub" do
63
+ (1..3).each do |stub_number|
64
+ expect(response.body).to match(/request_header_#{stub_number}:request_header_value_#{stub_number}/)
65
+ end
62
66
  end
63
67
 
64
- it "should return a response whose body contains the parameters of each activators stub" do
65
- (1..3).each { |i| response.body.should match(/parameter_#{i}=parameter_value_#{i}/) }
68
+ it "returns a response whose body contains the request headers of each stub trigger" do
69
+ (1..3).each do |stub_number|
70
+ (1..3).each do |trigger_number|
71
+ expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
72
+ expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
73
+ expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
74
+ end
75
+ end
66
76
  end
67
77
 
68
- it "should return a response whose body contains the response status of each activators stub" do
69
- (1..3).each { |i| response.body.should match(/20#{i}/) }
78
+ it "returns a response whose body contains the parameters of each stub" do
79
+ (1..3).each do |stub_number|
80
+ expect(response.body).to match(/parameter_#{stub_number}=parameter_value_#{stub_number}/)
81
+ end
70
82
  end
71
83
 
72
- it "should return a response whose body contains the response headers of each activators stub" do
73
- (1..3).each { |i| response.body.should match(/response_header_#{i}:response_header_value_#{i}/) }
84
+ it "returns a response whose body contains the parameters of each stub trigger" do
85
+ (1..3).each do |stub_number|
86
+ (1..3).each do |trigger_number|
87
+ expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
88
+ expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
89
+ expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
90
+ end
91
+ end
74
92
  end
75
93
 
76
- it "should return a response whose body contains the response body of each activators stub" do
77
- response.body.should match(/Plain text body/)
78
- response.body.should match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
79
- response.body.should match(/#{escape_html("<html><body>HTML body</body></html>")}/)
94
+ it "returns a response whose body contains the response status of each stub" do
95
+ (1..3).each { |stub_number| expect(response.body).to match(/20#{stub_number}/) }
80
96
  end
81
97
 
82
- it "should return a response whose body contains the response delay of each activators stub" do
83
- (1..3).each { |i| response.body.should include("#{i * 8}") }
98
+ it "returns a response whose body contains the response status of each stub trigger" do
99
+ (1..3).each do |stub_number|
100
+ (1..3).each do |trigger_number|
101
+ expect(response.body).to match(/30#{stub_number * trigger_number}/)
102
+ end
103
+ end
84
104
  end
85
105
 
86
- end
106
+ it "returns a response whose body contains the response headers of each stub" do
107
+ (1..3).each do |stub_number|
108
+ expected_header_key = "response_header_#{stub_number}"
109
+ expected_header_value = "response_header_value_#{stub_number}"
110
+ expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
111
+ end
112
+ end
87
113
 
88
- describe "GET #stubs" do
114
+ it "returns a response whose body contains the response headers of each stub trigger" do
115
+ (1..3).each do |stub_number|
116
+ (1..3).each do |trigger_number|
117
+ expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
118
+ expected_header_value = "response_header_value_#{stub_number}_trigger_#{trigger_number}"
119
+ expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
120
+ end
121
+ end
122
+ end
89
123
 
90
- describe "when multiple stubs are configured" do
124
+ it "returns a response whose body contains the response body of each stub" do
125
+ expect(response.body).to match(/Plain text body/)
126
+ expect(response.body).to match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
127
+ expect(response.body).to match(/#{escape_html("<html><body>HTML body</body></html>")}/)
128
+ end
91
129
 
92
- before(:all) do
93
- (1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") }
130
+ it "returns a response whose body contains the response body of each stub trigger" do
131
+ (1..3).each do |stub_number|
132
+ (1..3).each do |trigger_number|
133
+ expect(response.body).to match(/Body of activator #{stub_number}_trigger_#{trigger_number}/)
134
+ end
94
135
  end
136
+ end
95
137
 
96
- let(:response) { HTTParty.get("#{server_uri}/stubs") }
97
- let(:response_document) { Nokogiri::HTML(response.body) }
138
+ it "returns a response whose body contains the response delay of each stub" do
139
+ (1..3).each { |stub_number| expect(response.body).to include("#{8 * stub_number}") }
140
+ end
98
141
 
99
- it "should return a 200 response code" do
100
- response.code.should eql(200)
142
+ it "returns a response whose body contains the response delay of each stub trigger" do
143
+ (1..3).each do |stub_number|
144
+ (1..3).each do |trigger_number|
145
+ expect(response.body).to include("#{3 * stub_number * trigger_number}")
146
+ end
101
147
  end
148
+ end
102
149
 
103
- it "should return a response whose body contains the uri of each stub" do
104
- (1..3).each { |i| response.body.should match(/#{escape_html("/path_#{i}")}/) }
105
- end
150
+ end
106
151
 
107
- it "should return a response whose body contains the headers of each stub" do
108
- (1..3).each { |i| response.body.should match(/request_header_#{i}:request_header_value_#{i}/) }
109
- end
152
+ describe "GET #stubs/activators" do
110
153
 
111
- it "should return a response whose body contains the parameters of each stub" do
112
- (1..3).each { |i| response.body.should match(/parameter_#{i}=parameter_value_#{i}/) }
113
- end
154
+ let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
155
+ let(:response_document) { Nokogiri::HTML(response.body) }
114
156
 
115
- it "should return a response whose body contains the response status of each stub" do
116
- (1..3).each { |i| response.body.should match(/20#{i}/) }
157
+ it "returns response whose body contains links to each activator in alphabetical order" do
158
+ response_document.css("a").each_with_index do |link, i|
159
+ expect(link['href']).to eql("/activator_#{i + 1}")
117
160
  end
161
+ end
118
162
 
119
- it "should return a response whose body contains the response headers of each stub" do
120
- (1..3).each { |i| response.body.should match(/response_header_#{i}:response_header_value_#{i}/) }
121
- end
163
+ include_context "the response contains HTML describing the configurers stubs"
122
164
 
123
- it "should return a response whose body contains the response body of each stub" do
124
- response.body.should match(/Plain text body/)
125
- response.body.should match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
126
- response.body.should match(/#{escape_html("<html><body>HTML body</body></html>")}/)
127
- end
165
+ end
166
+
167
+ describe "GET #stubs" do
168
+
169
+ describe "when multiple stubs are configured" do
128
170
 
129
- it "should return a response whose body contains the response delay of each stub" do
130
- (1..3).each { |i| response.body.should include("#{i * 8}") }
171
+ before(:context) do
172
+ (1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") }
131
173
  end
132
174
 
175
+ let(:response) { HTTParty.get("#{server_uri}/stubs") }
176
+ let(:response_document) { Nokogiri::HTML(response.body) }
177
+
178
+ include_context "the response contains HTML describing the configurers stubs"
179
+
133
180
  end
134
181
 
135
182
  end
@@ -1,168 +1,228 @@
1
1
  describe HttpStub::Server do
2
2
  include Rack::Test::Methods
3
3
 
4
- let(:response) { last_response }
4
+ let(:response) { last_response }
5
5
  let(:response_body) { response.body.to_s }
6
6
 
7
- let(:stub_registry) { double(HttpStub::Models::Registry).as_null_object }
8
- let(:stub_activator_registry) { double(HttpStub::Models::Registry).as_null_object }
7
+ let(:stub_registry) { instance_double(HttpStub::Models::StubRegistry).as_null_object }
8
+ let(:stub_activator_registry) { instance_double(HttpStub::Models::Registry).as_null_object }
9
9
 
10
- let(:stub_controller) { double(HttpStub::Controllers::StubController).as_null_object }
11
- let(:stub_activator_controller) { double(HttpStub::Controllers::StubActivatorController).as_null_object }
10
+ let(:stub_controller) { instance_double(HttpStub::Controllers::StubController).as_null_object }
11
+ let(:stub_activator_controller) { instance_double(HttpStub::Controllers::StubActivatorController).as_null_object }
12
12
 
13
13
  let(:app) { HttpStub::Server.new! }
14
14
 
15
- before(:each) do
16
- HttpStub::Models::Registry.stub(:new).with("stub").and_return(stub_registry)
17
- HttpStub::Models::Registry.stub(:new).with("stub_activator").and_return(stub_activator_registry)
18
- HttpStub::Controllers::StubController.stub(:new).and_return(stub_controller)
19
- HttpStub::Controllers::StubActivatorController.stub(:new).and_return(stub_activator_controller)
15
+ before(:example) do
16
+ allow(HttpStub::Models::StubRegistry).to receive(:new).and_return(stub_registry)
17
+ allow(HttpStub::Models::Registry).to receive(:new).with("stub_activator").and_return(stub_activator_registry)
18
+ allow(HttpStub::Controllers::StubController).to receive(:new).and_return(stub_controller)
19
+ allow(HttpStub::Controllers::StubActivatorController).to receive(:new).and_return(stub_activator_controller)
20
20
  end
21
21
 
22
- context "when a stub insertion is received" do
22
+ context "when a stub insertion request is received" do
23
23
 
24
- it "should register the insertion via the stub controller" do
25
- stub_controller.should_receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
24
+ subject do
25
+ post "/stubs", {
26
+ uri: "/a_path", method: "a method",
27
+ response: { status: 200, body: "Foo" }
28
+ }.to_json
29
+ end
30
+
31
+ it "registers the insertion via the stub controller" do
32
+ expect(stub_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
26
33
 
27
- issue_stub_request
34
+ subject
28
35
  end
29
36
 
30
- it "should respond with the response provided by the controller" do
31
- stub_controller.stub(:register).and_return(HttpStub::Models::Response.new("status" => 202, "body" => ""))
37
+ it "responds with the response provided by the controller" do
38
+ allow(stub_controller).to receive(:register).and_return(HttpStub::Models::Response.new("status" => 202, "body" => ""))
32
39
 
33
- issue_stub_request
40
+ subject
34
41
 
35
- response.status.should eql(202)
42
+ expect(response.status).to eql(202)
36
43
  end
37
44
 
38
- def issue_stub_request
39
- post "/stubs", {
40
- uri: "/a_path", method: "a method",
41
- response: { status: 200, body: "Foo" }
42
- }.to_json
45
+ end
46
+
47
+ context "when a request to commit the stubs to memory is received" do
48
+
49
+ subject { post "/stubs/memory" }
50
+
51
+ it "remembers the stubs in the stub registry" do
52
+ expect(stub_registry).to receive(:remember)
53
+
54
+ subject
55
+ end
56
+
57
+ it "responds with a 200 status code" do
58
+ subject
59
+
60
+ expect(response.status).to eql(200)
43
61
  end
44
62
 
45
63
  end
46
64
 
47
- context "when a stub activator insertion request is received" do
65
+ context "when a request to recall the stubs in memory is received" do
66
+
67
+ subject { get "/stubs/memory" }
48
68
 
49
- it "should register the insertion via the stub activator controller" do
50
- stub_activator_controller.should_receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
69
+ it "recalls the stubs remembered by the stub registry" do
70
+ expect(stub_registry).to receive(:recall)
51
71
 
52
- issue_stub_activator_request
72
+ subject
53
73
  end
54
74
 
55
- it "should respond with the response provided by the controller" do
56
- stub_activator_controller.stub(:register).and_return(
57
- HttpStub::Models::Response.new("status" => 302, "body" => "")
58
- )
75
+ it "responds with a 200 status code" do
76
+ subject
77
+
78
+ expect(response.status).to eql(200)
79
+ end
80
+
81
+ end
82
+
83
+ context "when a request to clear the stubs has been received" do
84
+
85
+ subject { delete "/stubs" }
59
86
 
60
- issue_stub_activator_request
87
+ it "delegates clearing to the stub controller" do
88
+ expect(stub_controller).to receive(:clear)
61
89
 
62
- response.status.should eql(302)
90
+ subject
63
91
  end
64
92
 
65
- def issue_stub_activator_request
66
- post "/stubs/activators", {
67
- activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
68
- response: { status: 200, body: "Foo" }
69
- }.to_json
93
+ it "responds with a 200 status code" do
94
+ subject
95
+
96
+ expect(response.status).to eql(200)
70
97
  end
71
98
 
72
99
  end
73
100
 
74
- context "when a request to clear the stubs has been received" do
101
+ context "when a stub activator insertion request is received" do
102
+
103
+ subject do
104
+ post "/stubs/activators", {
105
+ activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
106
+ response: { status: 200, body: "Foo" }
107
+ }.to_json
108
+ end
75
109
 
76
- it "should delegate clearing to the stub controller" do
77
- stub_controller.should_receive(:clear)
110
+ it "registers the insertion via the stub activator controller" do
111
+ expect(stub_activator_controller).to receive(:register).and_return(HttpStub::Models::Response::SUCCESS)
78
112
 
79
- delete "/stubs"
113
+ subject
80
114
  end
81
115
 
82
- it "should respond with a 200 status code" do
83
- delete "/stubs"
116
+ it "responds with the response provided by the controller" do
117
+ allow(stub_activator_controller).to(
118
+ receive(:register).and_return(HttpStub::Models::Response.new("status" => 302, "body" => ""))
119
+ )
120
+
121
+ subject
84
122
 
85
- response.status.should eql(200)
123
+ expect(response.status).to eql(302)
86
124
  end
87
125
 
88
126
  end
89
127
 
90
128
  context "when a request to clear the stub activators has been received" do
91
129
 
92
- it "should delegate clearing to the stub activator controller" do
93
- stub_activator_controller.should_receive(:clear)
130
+ subject { delete "/stubs/activators" }
94
131
 
95
- delete "/stubs/activators"
132
+ it "delegates clearing to the stub activator controller" do
133
+ expect(stub_activator_controller).to receive(:clear)
134
+
135
+ subject
96
136
  end
97
137
 
98
- it "should respond with a 200 status code" do
99
- delete "/stubs/activators"
138
+ it "responds with a 200 status code" do
139
+ subject
100
140
 
101
- response.status.should eql(200)
141
+ expect(response.status).to eql(200)
102
142
  end
103
143
 
104
144
  end
105
145
 
106
146
  context "when another type of request is received" do
107
147
 
148
+ subject { get "/a_path" }
149
+
108
150
  context "and the stub controller replays a response" do
109
151
 
110
- before(:each) do
111
- stub_controller.stub(:replay).and_return(HttpStub::Models::Response.new("status" => 222, "body" => "Some body"))
152
+ let(:controller_response) do
153
+ HttpStub::Models::Response.new(
154
+ "status" => 222,
155
+ "headers" => { "content-type" => "application/xhtml" },
156
+ "body" => "Some body"
157
+ )
158
+ end
159
+
160
+ before(:example) { allow(stub_controller).to receive(:replay).and_return(controller_response) }
161
+
162
+ it "responds with the replay status code" do
163
+ subject
164
+
165
+ expect(response.status).to eql(222)
112
166
  end
113
167
 
114
- it "should respond with the replay status code" do
115
- get "/a_path"
168
+ it "responds with the replay body" do
169
+ subject
116
170
 
117
- response.status.should eql(222)
171
+ expect(response_body).to eql("Some body")
118
172
  end
119
173
 
120
- it "should respond with the replay body" do
121
- get "/a_path"
174
+ it "responds with the replay content type" do
175
+ subject
122
176
 
123
- response_body.should eql("Some body")
177
+ expect(response.content_type).to eql("application/xhtml")
178
+ end
179
+
180
+ it "allows the request pipeline to process the response before the processing of the request halts" do
181
+ expect(HttpStub::Models::RequestPipeline).to receive(:before_halt).with(controller_response)
182
+
183
+ subject
124
184
  end
125
185
 
126
186
  end
127
187
 
128
188
  context "and the stub controller does not replay a response" do
129
189
 
130
- before(:each) do
131
- stub_controller.stub(:replay).and_return(HttpStub::Models::Response::EMPTY)
190
+ before(:example) do
191
+ allow(stub_controller).to receive(:replay).and_return(HttpStub::Models::Response::EMPTY)
132
192
  end
133
193
 
134
194
  context "but the stub activator controller activates a stub" do
135
195
 
136
- before(:each) do
137
- stub_activator_controller.stub(:activate).and_return(
196
+ before(:example) do
197
+ allow(stub_activator_controller).to receive(:activate).and_return(
138
198
  HttpStub::Models::Response.new("status" => 300, "body" => "A body")
139
199
  )
140
200
  end
141
201
 
142
- it "should respond with the activation response status code" do
143
- get "/a_path"
202
+ it "responds with the activation response status code" do
203
+ subject
144
204
 
145
- response.status.should eql(300)
205
+ expect(response.status).to eql(300)
146
206
  end
147
207
 
148
- it "should respond with the activation response body" do
149
- get "/a_path"
208
+ it "responds with the activation response body" do
209
+ subject
150
210
 
151
- response_body.should eql("A body")
211
+ expect(response_body).to eql("A body")
152
212
  end
153
213
 
154
214
  end
155
215
 
156
216
  context "and the stub activator controller does not activate a stub" do
157
217
 
158
- before(:each) do
159
- stub_activator_controller.stub(:activate).and_return(HttpStub::Models::Response::EMPTY)
218
+ before(:example) do
219
+ allow(stub_activator_controller).to receive(:activate).and_return(HttpStub::Models::Response::EMPTY)
160
220
  end
161
221
 
162
- it "should respond with a 404 status code" do
163
- get "/a_path"
222
+ it "responds with a 404 status code" do
223
+ subject
164
224
 
165
- response.status.should eql(404)
225
+ expect(response.status).to eql(404)
166
226
  end
167
227
 
168
228
  end
@@ -171,26 +231,4 @@ describe HttpStub::Server do
171
231
 
172
232
  end
173
233
 
174
- context "when a request to replay a stub is received" do
175
-
176
- it "should handle processing of the response via the request pipeline" do
177
- HttpStub::Models::RequestPipeline.should_receive(:before_halt).with(duck_type(:status, :body))
178
-
179
- get "/some/stubbed/uri"
180
- end
181
-
182
- it "should respond with the response's content type" do
183
- stub_controller.stub(:replay).and_return(
184
- HttpStub::Models::Response.new(
185
- "status" => 200, "headers" => { "content-type" => "application/xhtml" }, "body" => "A body"
186
- )
187
- )
188
-
189
- get "/some/stubbed/uri"
190
-
191
- response.content_type.should eql("application/xhtml")
192
- end
193
-
194
- end
195
-
196
234
  end