http_sim 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +1 -0
- data/README.md +25 -1
- data/http_sim.gemspec +1 -1
- data/lib/http_sim.rb +3 -2
- data/spec/features/request_spec.rb +27 -17
- data/spec/features/response_spec.rb +41 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e8b845cf4bcfebc30186771e7caa4eee7dd4bd2
|
4
|
+
data.tar.gz: 37130ffeb405e894f02fad5654e9f196dd8d7c24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3672147e1325a44908b8af46fbea3d8a7bf5d0d48c3bcbafc509593e405f96c8643023a66b0f84b4f3487521bea486dea0d22c4f4eb6ac0f5374b2bcde1eef7
|
7
|
+
data.tar.gz: e21d82cf6defa514007a1e740824406fae2b5b5705b853b08fa2938b8a9284fb853984d709f313458c18bb8c23aae2076f7354a06ac3123aa8ff6721cc4439fd
|
data/CHANGELOG.txt
CHANGED
@@ -3,3 +3,4 @@ Version 0.0.2 Allow changing port
|
|
3
3
|
Version 0.0.3 Requests to endpoints are recorded and listed at endpoint's /request endpoint
|
4
4
|
Version 0.0.4 Added run_daemon!, stop_daemon!, and wait_for_start methods
|
5
5
|
Version 0.0.5 run_daemon! now writes to a (configurable) log file
|
6
|
+
Version 0.0.6 PUT and DELETE endpoints now generated for /<endpoint>/response
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Simulate your external HTTP integrations.
|
|
6
6
|
|
7
7
|
**Contributions and issues very welcome**.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Standalone usage
|
10
10
|
|
11
11
|
1. Add `gem 'http_sim'` to your `Gemfile`
|
12
12
|
1. `bundle install`
|
@@ -22,6 +22,30 @@ Simulate your external HTTP integrations.
|
|
22
22
|
|
23
23
|
1. The endpoints `GET /hi` and `POST /bye` are now set up. Visit `http://localhost:6565/` to see an index of running simulators and their helpers.
|
24
24
|
|
25
|
+
## Test usage
|
26
|
+
|
27
|
+
1. Add `gem 'http_sim'` to your `Gemfile`
|
28
|
+
1. `bundle install`
|
29
|
+
1. `some_spec.rb`:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
describe 'some spec' do
|
33
|
+
before :each do
|
34
|
+
HttpSimulator.reset_endpoints
|
35
|
+
HttpSimulator.register_endpoint 'POST', '/some_simulated_endpoint', 'some_simulated_content'
|
36
|
+
HttpSimulator.run_daemon!(port: 6565)
|
37
|
+
end
|
38
|
+
|
39
|
+
after :each do
|
40
|
+
HttpSimulator.stop_daemon!
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does something that needs a simulator backing it' do
|
44
|
+
# your test here
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
25
49
|
## Contributing
|
26
50
|
|
27
51
|
1. Fork it ( https://github.com/[my-github-username]/scaffold/fork )
|
data/http_sim.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'http_sim'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.6'
|
8
8
|
spec.authors = ['Jean de Klerk']
|
9
9
|
spec.email = ['jadekler@gmail.com']
|
10
10
|
spec.summary = 'Simulate your external HTTP integrations.'
|
data/lib/http_sim.rb
CHANGED
@@ -3,8 +3,8 @@ require 'sinatra/base'
|
|
3
3
|
require 'httparty'
|
4
4
|
|
5
5
|
class Endpoint
|
6
|
-
attr_reader :method, :path, :default_response
|
7
|
-
attr_accessor :requests
|
6
|
+
attr_reader :method, :path, :default_response
|
7
|
+
attr_accessor :requests, :response
|
8
8
|
|
9
9
|
@@supported_methods = ['GET', 'PUT', 'PATCH', 'POST', 'DELETE']
|
10
10
|
|
@@ -103,6 +103,7 @@ module HttpSimulator
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
# TODO: Should this just be 'reset'?
|
106
107
|
def self.reset_endpoints
|
107
108
|
@@endpoints = []
|
108
109
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'requests' do
|
4
4
|
before :each do
|
5
5
|
HttpSimulator.reset_endpoints
|
6
6
|
end
|
@@ -9,26 +9,36 @@ describe '/<endpoint>/requests' do
|
|
9
9
|
HttpSimulator.stop_daemon!
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
describe 'getting requests' do
|
13
|
+
it 'sets up GET /<endpoint>/requests for each registered endpoint' do
|
14
|
+
HttpSimulator.register_endpoint 'POST', '/hi', ''
|
15
|
+
HttpSimulator.register_endpoint 'POST', '/bye', ''
|
16
|
+
HttpSimulator.run_daemon!(port: 6565)
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
resp = HTTParty.get('http://localhost:6565/hi/requests')
|
19
|
+
expect(resp.code).to eq 200
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
resp = HTTParty.get('http://localhost:6565/bye/requests')
|
22
|
+
expect(resp.code).to eq 200
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'GET /<endpoint>/requests returns recorded requests' do
|
26
|
+
HttpSimulator.register_endpoint 'POST', '/bye', 'byeeeee'
|
27
|
+
HttpSimulator.run_daemon!(port: 6565)
|
23
28
|
|
24
|
-
|
25
|
-
HttpSimulator.register_endpoint 'POST', '/bye', 'byeeeee'
|
26
|
-
HttpSimulator.run_daemon!(port: 6565)
|
29
|
+
HTTParty.post('http://localhost:6565/bye', :body => 'hello world')
|
27
30
|
|
28
|
-
|
31
|
+
resp = HTTParty.get('http://localhost:6565/bye/requests')
|
32
|
+
expect(resp.code).to eq 200
|
33
|
+
expect(resp.body).to include 'hello world'
|
34
|
+
end
|
35
|
+
|
36
|
+
xit '.resets returns recorded requests' # TODO
|
37
|
+
end
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
39
|
+
describe 'resetting requests' do
|
40
|
+
xit 'sets up a DELETE /<endpoint>/requests for each registered endpoint' # TODO
|
41
|
+
xit 'DELETE /<endpoint>/requests resets recorded requests' # TODO
|
42
|
+
xit '.reset_requests reset recorded requests' # TODO
|
33
43
|
end
|
34
44
|
end
|
@@ -1,23 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'responses' do
|
4
4
|
before :each do
|
5
5
|
HttpSimulator.reset_endpoints
|
6
|
+
|
7
|
+
HttpSimulator.register_endpoint 'POST', '/hi', ''
|
8
|
+
HttpSimulator.register_endpoint 'POST', '/bye', ''
|
9
|
+
|
10
|
+
HttpSimulator.run_daemon!(port: 6565)
|
6
11
|
end
|
7
12
|
|
8
13
|
after :each do
|
9
14
|
HttpSimulator.stop_daemon!
|
10
15
|
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
describe 'getting response' do
|
18
|
+
it 'sets up GET /<endpoint>/response for each registered endpoint' do
|
19
|
+
resp = HTTParty.get('http://localhost:6565/hi/response')
|
20
|
+
expect(resp.code).to eq 200
|
21
|
+
|
22
|
+
resp = HTTParty.get('http://localhost:6565/bye/response')
|
23
|
+
expect(resp.code).to eq 200
|
24
|
+
end
|
25
|
+
|
26
|
+
xit 'GET /<endpoint>/response returns response for endpoint' # TODO
|
27
|
+
xit '.response returns response for endpoint' # TODO
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'setting response' do
|
31
|
+
it 'sets up PUT /<endpoint>/response for each registered endpoint' do
|
32
|
+
resp = HTTParty.put('http://localhost:6565/hi/response', :body => '{}')
|
33
|
+
expect(resp.code).to eq 200
|
34
|
+
|
35
|
+
resp = HTTParty.put('http://localhost:6565/bye/response', :body => '{}')
|
36
|
+
expect(resp.code).to eq 200
|
37
|
+
end
|
38
|
+
|
39
|
+
xit 'PUT /<endpoint>/response alters response for endpoint' # TODO
|
40
|
+
xit '.set_response alters response for endpoint' # TODO
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'resetting response' do
|
44
|
+
it 'sets up a DELETE /<endpoint>/response for each registered endpoint' do
|
45
|
+
resp = HTTParty.delete('http://localhost:6565/hi/response')
|
46
|
+
expect(resp.code).to eq 200
|
16
47
|
|
17
|
-
|
18
|
-
|
48
|
+
resp = HTTParty.put('http://localhost:6565/bye/response')
|
49
|
+
expect(resp.code).to eq 200
|
50
|
+
end
|
19
51
|
|
20
|
-
|
21
|
-
|
52
|
+
xit 'DELETE /<endpoint>/response resets response for endpoint' # TODO
|
53
|
+
xit '.reset_response resets response for endpoint' # TODO
|
22
54
|
end
|
23
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_sim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean de Klerk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|