spoofer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +93 -0
- data/Rakefile +25 -0
- data/features/checking_requests_were_made.feature +39 -0
- data/features/configuring_spoofer_via_http.feature +175 -0
- data/features/echoing_request_in_response.feature +76 -0
- data/features/logging_requests.feature +13 -0
- data/features/resetting_stubs.feature +16 -0
- data/features/steps/http_client_steps.rb +60 -0
- data/features/steps/logging_steps.rb +3 -0
- data/features/steps/shell_steps.rb +10 -0
- data/features/steps/spoofer_steps.rb +21 -0
- data/features/stubbing_requests_by_method.feature +25 -0
- data/features/stubbing_requests_by_path.feature +60 -0
- data/features/stubbing_requests_from_a_file.feature +33 -0
- data/features/stubbing_requests_with_parameters.feature +28 -0
- data/features/support/env.rb +15 -0
- data/features/support/hash_key_path.rb +7 -0
- data/features/support/http_client.rb +50 -0
- data/features/support/spoofer_runner.rb +7 -0
- data/features/using_rack_middlewares.feature +31 -0
- data/lib/spoofer.rb +104 -0
- data/lib/spoofer/api.rb +50 -0
- data/lib/spoofer/api/api_request.rb +49 -0
- data/lib/spoofer/api/stub.rb +39 -0
- data/lib/spoofer/fake_host.rb +102 -0
- data/lib/spoofer/fake_host/helpers.rb +11 -0
- data/lib/spoofer/fake_host/request_echo.rb +42 -0
- data/lib/spoofer/fake_host/stubbed_request.rb +73 -0
- data/lib/spoofer/version.rb +3 -0
- data/spec/fixtures/import_stubs.spoof +3 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/spoofer/fake_host_spec.rb +74 -0
- data/spec/spoofer/stubbed_request_spec.rb +16 -0
- data/spec/support/.keep +0 -0
- data/spec/support/matchers.rb +7 -0
- data/spec/support/pry.rb +1 -0
- data/spec/support/request_helper.rb +7 -0
- metadata +233 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 239d4797905c9be787b45a1d3801723da8c247ab
|
4
|
+
data.tar.gz: 2eec7230cc9429933ff77bc2571a1e882a9009bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eaec9fd7a0e78ff537c890d069b06e06e235098f4762c1e918c1a794d410583f854afe896496bf6eab0f75bf21bc950dcc4c68e1bbfbe286812217d338ee985e
|
7
|
+
data.tar.gz: 2861633a8005d55d0cebec20c422502244c830ac9e442abed7221ac3f104c16f3e672eb346af10194da82c0fa2a9b4d65d426d2882f21540b3fb502a2fd13b3e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Justin Smestad
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Spoofer, simple web service stubs for testing [![Build Status](https://secure.travis-ci.org/jsmestad/spoofer.png)](https://secure.travis-ci.org/jsmestad/spoofer)
|
2
|
+
|
3
|
+
|
4
|
+
## What is Spoofer?
|
5
|
+
|
6
|
+
Spoofer is a fork of the [Mimic Ruby Gem]() project. It was not being actively maintained anymore and decided to create a new fork using Mimic as a basis.
|
7
|
+
|
8
|
+
If your unfamiliar with the Mimic gem, then... Spoofer is a testing tool that lets you set create a fake stand-in for an external web service to be used when writing integration/end-to-end tests for applications or libraries that access these services.
|
9
|
+
|
10
|
+
## Why not stub?
|
11
|
+
There are already some good tools, like [FakeWeb](http://fakeweb.rubyforge.org/) which let you stub requests at a low-level which is fine for unit and functional tests but when exercising our code through integration or end-to-end tests we want to exercise as much of the stack as possible.
|
12
|
+
|
13
|
+
Spoofer aims to make it possible to test your networking code without actually hitting the real services by starting up a real web server and responding to HTTP requests. This lets you test your application against canned responses in an as-close-to-the-real-thing-as-possible way.
|
14
|
+
|
15
|
+
Also, because Spoofer responds to real HTTP requests, it can be used when testing non-Ruby applications too.
|
16
|
+
|
17
|
+
## Examples
|
18
|
+
|
19
|
+
Registering to a single request stub:
|
20
|
+
|
21
|
+
Spoofer.mimic.get("/some/path").returning("hello world")
|
22
|
+
|
23
|
+
And the result, using RestClient:
|
24
|
+
|
25
|
+
$ RestClient.get("http://www.example.com:11988/some/path") # => 200 | hello world
|
26
|
+
|
27
|
+
Registering multiple request stubs; note that you can stub the same path with different HTTP methods separately.
|
28
|
+
|
29
|
+
Spoofer.mimic do
|
30
|
+
get("/some/path").returning("Hello World", 200)
|
31
|
+
get("/some/other/path").returning("Redirecting...", 301, {"Location" => "somewhere else"})
|
32
|
+
post("/some/path").returning("Created!", 201)
|
33
|
+
end
|
34
|
+
|
35
|
+
You can even use Rack middlewares, e.g. to handle common testing scenarios such as authentication:
|
36
|
+
|
37
|
+
Spoofer.mimic do
|
38
|
+
use Rack::Auth::Basic do |user, pass|
|
39
|
+
user == 'theuser' and pass == 'thepass'
|
40
|
+
end
|
41
|
+
|
42
|
+
get("/some/path")
|
43
|
+
end
|
44
|
+
|
45
|
+
Finally, because Spoofer is built on top of Sinatra for the core request handling, you can create your stubbed requests like you would in any Sinatra app:
|
46
|
+
|
47
|
+
Spoofer.mimic do
|
48
|
+
get "/some/path" do
|
49
|
+
[200, {}, "hello world"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
## Using Spoofer with non-Ruby processes
|
54
|
+
|
55
|
+
Spoofer has a built-in REST API that lets you configure your request stubs over HTTP. This makes it possible to use Spoofer from other processes that can perform HTTP requests.
|
56
|
+
|
57
|
+
First of all, you'll need to run Spoofer as a daemon. You can do this with a simple Ruby script and the [daemons](http://daemons.rubyforge.org/) gem:
|
58
|
+
|
59
|
+
#!/usr/bin/env ruby
|
60
|
+
require 'spoofer'
|
61
|
+
require 'daemons'
|
62
|
+
|
63
|
+
Daemons.run_proc("mimic") do
|
64
|
+
Spoofer.mimic(:port => 11988, :fork => false, :remote_configuration_path => '/api') do
|
65
|
+
# configure your stubs here
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Give the script executable permissions and then start it:
|
70
|
+
|
71
|
+
$ your_spoofer_script.rb start (or run)
|
72
|
+
|
73
|
+
The remote configuration path is where the API endpoints will be mounted - this is configurable as you will not be able this path or any paths below it in your stubs, so choose one that doesn't conflict with the paths you need to stub.
|
74
|
+
|
75
|
+
The API supports both JSON and Plist payloads, defaulting to JSON. Set the request Content-Type header to application/plist for Plist requests.
|
76
|
+
|
77
|
+
For the following Spoofer configuration (using the Ruby DSL):
|
78
|
+
|
79
|
+
Spoofer.mimic.get("/some/path").returning("hello world")
|
80
|
+
|
81
|
+
The equivalent stub can be configured using the REST API as follows:
|
82
|
+
|
83
|
+
$ curl -d'{"path":"/some/path", "body":"hello world"}' http://localhost:11988/api/get
|
84
|
+
|
85
|
+
Likewise, a POST request to the same path could be stubbed like so:
|
86
|
+
|
87
|
+
$ curl -d'{"path":"/some/path", "body":"hello world"}' http://localhost:11988/api/post
|
88
|
+
|
89
|
+
The end-point of the API is the HTTP verb you are stubbing, the path, response body, code and headers are specified in the POST data (a hash in JSON or Plist format). See the HTTP API Cucumber features for more examples.
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
See LICENSE file distributed with this gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'cucumber'
|
2
|
+
require 'cucumber/rake/task'
|
3
|
+
|
4
|
+
ENV["POSER_TEST_PROXY"] = nil
|
5
|
+
|
6
|
+
desc "Run all Cucumber features"
|
7
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
8
|
+
t.cucumber_opts = "features --format pretty"
|
9
|
+
end
|
10
|
+
|
11
|
+
task :all => [:spec, :features]
|
12
|
+
|
13
|
+
require "bundler/gem_tasks"
|
14
|
+
require "rspec/core/rake_task"
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(:spec)
|
17
|
+
|
18
|
+
task :default => :spec
|
19
|
+
|
20
|
+
require 'yard'
|
21
|
+
|
22
|
+
YARD::Rake::YardocTask.new do |t|
|
23
|
+
t.files = ['lib/**/*.rb'] # optional
|
24
|
+
t.options = ['--any', '--extra', '--opts'] # optional
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Checking requests were made
|
2
|
+
In order to verify requests were made to mimic (like mock expectations)
|
3
|
+
As a developer
|
4
|
+
I want to be able to ask the Spoofer API what requests were made
|
5
|
+
|
6
|
+
Scenario: Configuring a request and verifying it was called
|
7
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
8
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
9
|
+
"""
|
10
|
+
{"path": "/anything"}
|
11
|
+
"""
|
12
|
+
Then I should receive an HTTP 201 response with a body containing:
|
13
|
+
"""
|
14
|
+
{"stubs":["41f660b868e1308e8d87afbb84532b71"]}
|
15
|
+
"""
|
16
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
17
|
+
And I make an HTTP GET request to "http://localhost:11988/api/requests"
|
18
|
+
Then I should receive an HTTP 200 response with a body containing:
|
19
|
+
"""
|
20
|
+
{"requests":["41f660b868e1308e8d87afbb84532b71"]}
|
21
|
+
"""
|
22
|
+
|
23
|
+
Scenario: Configuring a request and verifying it was not called
|
24
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
25
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
26
|
+
"""
|
27
|
+
{"path": "/anything"}
|
28
|
+
"""
|
29
|
+
Then I should receive an HTTP 201 response with a body containing:
|
30
|
+
"""
|
31
|
+
{"stubs":["41f660b868e1308e8d87afbb84532b71"]}
|
32
|
+
"""
|
33
|
+
And I make an HTTP GET request to "http://localhost:11988/api/requests"
|
34
|
+
Then I should receive an HTTP 200 response with a body containing:
|
35
|
+
"""
|
36
|
+
{"requests":[]}
|
37
|
+
"""
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,175 @@
|
|
1
|
+
Feature: Configuring Spoofer via an HTTP interface
|
2
|
+
In order to use Spoofer stubs from non-Ruby test cases
|
3
|
+
As a developer
|
4
|
+
I want to be able to configure a background Spoofer process using an HTTP REST API
|
5
|
+
|
6
|
+
Scenario: Pinging Spoofer via the API to check it's running
|
7
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
8
|
+
When I make an HTTP GET request to "http://localhost:11988/api/ping"
|
9
|
+
Then I should receive an HTTP 200 response with a body matching "OK"
|
10
|
+
|
11
|
+
Scenario: Stubbing a request path via GET using the HTTP API
|
12
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
13
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
14
|
+
"""
|
15
|
+
{"path": "/anything"}
|
16
|
+
"""
|
17
|
+
Then I should receive an HTTP 201 response
|
18
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
19
|
+
Then I should receive an HTTP 200 response with an empty body
|
20
|
+
|
21
|
+
Scenario: Stubbing a request path via POST the HTTP API
|
22
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
23
|
+
When I make an HTTP POST request to "http://localhost:11988/api/post" with the payload:
|
24
|
+
"""
|
25
|
+
{"path": "/anything"}
|
26
|
+
"""
|
27
|
+
Then I should receive an HTTP 201 response
|
28
|
+
And I make an HTTP POST request to "http://localhost:11988/anything"
|
29
|
+
Then I should receive an HTTP 200 response with an empty body
|
30
|
+
|
31
|
+
Scenario: Stubbing a request path via PUT using the HTTP API
|
32
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
33
|
+
When I make an HTTP POST request to "http://localhost:11988/api/put" with the payload:
|
34
|
+
"""
|
35
|
+
{"path": "/anything"}
|
36
|
+
"""
|
37
|
+
Then I should receive an HTTP 201 response
|
38
|
+
And I make an HTTP PUT request to "http://localhost:11988/anything"
|
39
|
+
Then I should receive an HTTP 200 response with an empty body
|
40
|
+
|
41
|
+
Scenario: Stubbing a request path via DELETE the HTTP API for a
|
42
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
43
|
+
When I make an HTTP POST request to "http://localhost:11988/api/delete" with the payload:
|
44
|
+
"""
|
45
|
+
{"path": "/anything"}
|
46
|
+
"""
|
47
|
+
Then I should receive an HTTP 201 response
|
48
|
+
And I make an HTTP DELETE request to "http://localhost:11988/anything"
|
49
|
+
Then I should receive an HTTP 200 response with an empty body
|
50
|
+
|
51
|
+
Scenario: Stubbing a request path via HEAD using the HTTP API
|
52
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
53
|
+
When I make an HTTP POST request to "http://localhost:11988/api/head" with the payload:
|
54
|
+
"""
|
55
|
+
{"path": "/anything"}
|
56
|
+
"""
|
57
|
+
Then I should receive an HTTP 201 response
|
58
|
+
And I make an HTTP HEAD request to "http://localhost:11988/anything"
|
59
|
+
Then I should receive an HTTP 200 response with an empty body
|
60
|
+
|
61
|
+
Scenario: Stubbing a request path to return a custom response body
|
62
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
63
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
64
|
+
"""
|
65
|
+
{"path": "/anything", "body": "Hello World"}
|
66
|
+
"""
|
67
|
+
Then I should receive an HTTP 201 response
|
68
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
69
|
+
Then I should receive an HTTP 200 response with a body matching "Hello World"
|
70
|
+
|
71
|
+
Scenario: Stubbing a request path to return a custom status code
|
72
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
73
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
74
|
+
"""
|
75
|
+
{"path": "/anything", "code": 301}
|
76
|
+
"""
|
77
|
+
Then I should receive an HTTP 201 response
|
78
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
79
|
+
Then I should receive an HTTP 301 response with an empty body
|
80
|
+
|
81
|
+
Scenario: Stubbing a request path to return custom headers
|
82
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
83
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
84
|
+
"""
|
85
|
+
{"path": "/anything", "headers": {"X-TEST-HEADER": "TESTING"}}
|
86
|
+
"""
|
87
|
+
Then I should receive an HTTP 201 response
|
88
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
89
|
+
Then I should receive an HTTP 200 response with the value "TESTING" for the header "X-TEST-HEADER"
|
90
|
+
|
91
|
+
Scenario: Stubbing a request path that only matches with the right query params
|
92
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
93
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
94
|
+
"""
|
95
|
+
{"path": "/anything", "params": {"foo": "bar"}}
|
96
|
+
"""
|
97
|
+
Then I should receive an HTTP 201 response
|
98
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
99
|
+
Then I should receive an HTTP 404 response
|
100
|
+
And I make an HTTP GET request to "http://localhost:11988/anything?foo=bar"
|
101
|
+
Then I should receive an HTTP 200 response
|
102
|
+
|
103
|
+
Scenario: Stubbing a request to echo it's request
|
104
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
105
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
106
|
+
"""
|
107
|
+
{"path": "/anything", "echo": "json"}
|
108
|
+
"""
|
109
|
+
Then I should receive an HTTP 201 response
|
110
|
+
And I make an HTTP GET request to "http://localhost:11988/anything?foo=bar"
|
111
|
+
Then I should receive an HTTP 200 response with the JSON value "bar" for the key path "echo.params.foo"
|
112
|
+
|
113
|
+
Scenario: Stubbing a request using the HTTP API in plist format
|
114
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
115
|
+
When I make an HTTP POST request with a "application/plist" content-type to "http://localhost:11988/api/get" and the payload:
|
116
|
+
"""
|
117
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
118
|
+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
119
|
+
<plist version="1.0">
|
120
|
+
<dict>
|
121
|
+
<key>path</key>
|
122
|
+
<string>/anything</string>
|
123
|
+
</dict>
|
124
|
+
</plist>
|
125
|
+
"""
|
126
|
+
Then I should receive an HTTP 201 response
|
127
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
128
|
+
Then I should receive an HTTP 200 response with an empty body
|
129
|
+
|
130
|
+
Scenario: Configuring multiple stubs for a single verb in a single request
|
131
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
132
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
133
|
+
"""
|
134
|
+
{"stubs":[{"path": "/anything"}, {"path": "/something"}]}
|
135
|
+
"""
|
136
|
+
Then I should receive an HTTP 201 response
|
137
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
138
|
+
Then I should receive an HTTP 200 response with an empty body
|
139
|
+
And I make an HTTP GET request to "http://localhost:11988/something"
|
140
|
+
Then I should receive an HTTP 200 response with an empty body
|
141
|
+
|
142
|
+
Scenario: Configuring multiple stubs for different verbs in a single request
|
143
|
+
Given that Spoofer is running and accepting remote configuration on "/api"
|
144
|
+
When I make an HTTP POST request to "http://localhost:11988/api/multi" with the payload:
|
145
|
+
"""
|
146
|
+
{"stubs":[{"method": "GET", "path": "/anything"}, {"method": "POST", "path": "/something"}]}
|
147
|
+
"""
|
148
|
+
Then I should receive an HTTP 201 response
|
149
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
150
|
+
Then I should receive an HTTP 200 response with an empty body
|
151
|
+
And I make an HTTP POST request to "http://localhost:11988/something"
|
152
|
+
Then I should receive an HTTP 200 response with an empty body
|
153
|
+
|
154
|
+
Scenario: Clearing all stubs via the HTTP API
|
155
|
+
Given that Spoofer is running and accepting remote configuration on "/api" with the existing stubs:
|
156
|
+
"""
|
157
|
+
get("/anything").returning("hello world")
|
158
|
+
"""
|
159
|
+
When I make an HTTP POST request to "http://localhost:11988/api/clear"
|
160
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
161
|
+
Then I should receive an HTTP 404 response with an empty body
|
162
|
+
|
163
|
+
Scenario: Clearing all stubs then resetting a stub via the API
|
164
|
+
Given that Spoofer is running and accepting remote configuration on "/api" with the existing stubs:
|
165
|
+
"""
|
166
|
+
get("/anything").returning("hello world")
|
167
|
+
"""
|
168
|
+
When I make an HTTP POST request to "http://localhost:11988/api/clear"
|
169
|
+
When I make an HTTP POST request to "http://localhost:11988/api/get" with the payload:
|
170
|
+
"""
|
171
|
+
{"path": "/anything", "body": "something else"}
|
172
|
+
"""
|
173
|
+
And I make an HTTP GET request to "http://localhost:11988/anything"
|
174
|
+
Then I should receive an HTTP 200 response with a body matching "something else"
|
175
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
Feature: Echoing request in response
|
2
|
+
In order to easily verify that I sent the correct request data
|
3
|
+
As a developer
|
4
|
+
I want to tell mimic to echo the request data in a specific format in it's response
|
5
|
+
|
6
|
+
Scenario: Echoing query parameters in JSON format
|
7
|
+
Given I have a spoofer specification with:
|
8
|
+
"""
|
9
|
+
Spoofer.mimic(:port => 11988).get("/some/path").echo_request!(:json)
|
10
|
+
"""
|
11
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path?foo=bar"
|
12
|
+
Then I should receive an HTTP 200 response with the JSON value "bar" for the key path "echo.params.foo"
|
13
|
+
|
14
|
+
Scenario: Echoing request headers in JSON format
|
15
|
+
Given I have a spoofer specification with:
|
16
|
+
"""
|
17
|
+
Spoofer.mimic(:port => 11988).get("/some/path").echo_request!(:json)
|
18
|
+
"""
|
19
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path" with the header "X-TEST: Some Value"
|
20
|
+
Then I should receive an HTTP 200 response with the JSON value "Some Value" for the key path "echo.env.HTTP_X_TEST"
|
21
|
+
|
22
|
+
Scenario: Echoing request body in JSON format
|
23
|
+
Given I have a spoofer specification with:
|
24
|
+
"""
|
25
|
+
Spoofer.mimic(:port => 11988).post("/some/path").echo_request!(:json)
|
26
|
+
"""
|
27
|
+
When I make an HTTP POST request to "http://localhost:11988/some/path" with the payload:
|
28
|
+
"""
|
29
|
+
REQUEST BODY
|
30
|
+
"""
|
31
|
+
Then I should receive an HTTP 200 response with the JSON value "REQUEST BODY" for the key path "echo.body"
|
32
|
+
|
33
|
+
Scenario: Echoing query parameters in Plist format
|
34
|
+
Given I have a spoofer specification with:
|
35
|
+
"""
|
36
|
+
Spoofer.mimic(:port => 11988).get("/some/path").echo_request!(:plist)
|
37
|
+
"""
|
38
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path?foo=bar"
|
39
|
+
Then I should receive an HTTP 200 response with the Plist value "bar" for the key path "echo.params.foo"
|
40
|
+
|
41
|
+
Scenario: Echoing request headers in Plist format
|
42
|
+
Given I have a spoofer specification with:
|
43
|
+
"""
|
44
|
+
Spoofer.mimic(:port => 11988).get("/some/path").echo_request!(:plist)
|
45
|
+
"""
|
46
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path" with the header "X-TEST: Some Value"
|
47
|
+
Then I should receive an HTTP 200 response with the Plist value "Some Value" for the key path "echo.env.HTTP_X_TEST"
|
48
|
+
|
49
|
+
Scenario: Echoing request body in Plist format
|
50
|
+
Given I have a spoofer specification with:
|
51
|
+
"""
|
52
|
+
Spoofer.mimic(:port => 11988).post("/some/path").echo_request!(:plist)
|
53
|
+
"""
|
54
|
+
When I make an HTTP POST request to "http://localhost:11988/some/path" with the payload:
|
55
|
+
"""
|
56
|
+
REQUEST BODY
|
57
|
+
"""
|
58
|
+
Then I should receive an HTTP 200 response with the Plist value "REQUEST BODY" for the key path "echo.body"
|
59
|
+
|
60
|
+
Scenario: Echoing query parameters but also specifying a response body results in response body being overwritten
|
61
|
+
Given I have a spoofer specification with:
|
62
|
+
"""
|
63
|
+
Spoofer.mimic(:port => 11988).get("/some/path").returning("not an echo").echo_request!(:json)
|
64
|
+
"""
|
65
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path?foo=bar"
|
66
|
+
Then I should receive an HTTP 200 response with the JSON value "bar" for the key path "echo.params.foo"
|
67
|
+
|
68
|
+
Scenario: Echoing response manually from block definition
|
69
|
+
Given I have a spoofer specification with:
|
70
|
+
"""
|
71
|
+
Spoofer.mimic(:port => 11988).get("/some/path") do
|
72
|
+
echo_request!(:json)
|
73
|
+
end
|
74
|
+
"""
|
75
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path?foo=bar"
|
76
|
+
Then I should receive an HTTP 200 response with the JSON value "bar" for the key path "echo.params.foo"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Logging incoming requests
|
2
|
+
In order to check that Spoofer is working properly or provide further debug information
|
3
|
+
As a developer
|
4
|
+
I want to be able to tell Spoofer to log incoming requests
|
5
|
+
|
6
|
+
Scenario: Logging to STDOUT
|
7
|
+
Given I have a spoofer specification with:
|
8
|
+
"""
|
9
|
+
Spoofer.mimic(:port => 11988, :log => $stdout).get("/some/path")
|
10
|
+
"""
|
11
|
+
When I make an HTTP GET request to "http://localhost:11988/some/path"
|
12
|
+
Then I should see "GET /some/path HTTP/1.1" written to STDOUT
|
13
|
+
|