http_sim 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a72f2bf7f0e80cce27d8287e9f5a3539ccaf36af
4
- data.tar.gz: 41ddee6f956a5adc8229019d4b766d6a7a79749b
3
+ metadata.gz: 52e2203c08a8a947003c272b1e115eb6bada9aaa
4
+ data.tar.gz: fab04b2e41c9ed1d0b61669453f409a9f7cf7e38
5
5
  SHA512:
6
- metadata.gz: 5a889e786d1fc0197366861598a710831f82d993ca304c1d5289af96425215083522c7acf88194324ba3afa83c3acf8cb0de8a37a1d6c9001b35041243e3f861
7
- data.tar.gz: f4ec7db79b14c0636e1decf242fac83d9a6e9f7e13bfaa521a3414200d2d9e016469fee3581e52ea209707b97147b97feff0c0cfe3f21558663963c3800591e9
6
+ metadata.gz: 11a4e2f0b1c3ac9ed04b1a231140462236a65cec9f0b2bd283c5cfe4df0356784733e9e0e78e823e8707c00a82ef3c4d0bb0365f47f11384e2e2fc8e6d4fdba9
7
+ data.tar.gz: ac07f76a3611e7cf26c422c5f9b7f805d0e4457eb95948f376060c6da3435452601bd1aa45c8d59413de474a8391719cc5e50a1ad53f260615aaaab12731042c
data/CHANGELOG.txt CHANGED
@@ -6,3 +6,4 @@ Version 0.0.5 run_daemon! now writes to a (configurable) log file
6
6
  Version 0.0.6 PUT and DELETE endpoints now generated for /<endpoint>/response
7
7
  Version 0.0.7 GET, PUT, DELETE /response endpoints now working
8
8
  Version 1.0.0 Responses can be changed at /<endpoint>/response. All initial features are now complete
9
+ Version 1.0.1 Fixed bug wherein responses were always using default instead of set response
data/README.md CHANGED
@@ -15,8 +15,8 @@ Simulate your external HTTP integrations.
15
15
  ```ruby
16
16
  require 'http_sim'
17
17
 
18
- HttpSimulator.register_endpoint 'GET', '/hi', read_file('fixtures/some_page.html')
19
- HttpSimulator.register_endpoint 'POST', '/bye', read_file('fixtures/some_response.json')
18
+ HttpSimulator.register_endpoint 'GET', '/hi', '{"some_json": true}'
19
+ HttpSimulator.register_endpoint 'POST', '/bye', '<html><body>some html</body></html>'
20
20
  HttpSimulator.run!(port:6565)
21
21
  ```
22
22
 
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 = '1.0.0'
7
+ spec.version = '1.0.1'
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
@@ -134,27 +134,27 @@ module HttpSimulator
134
134
  when 'GET'
135
135
  Sinatra::Base.get endpoint.path do
136
136
  endpoint.add_request request.body.read
137
- endpoint.default_response
137
+ endpoint.response
138
138
  end
139
139
  when 'PUT'
140
140
  Sinatra::Base.put endpoint.path do
141
141
  endpoint.add_request request.body.read
142
- endpoint.default_response
142
+ endpoint.response
143
143
  end
144
144
  when 'PATCH'
145
145
  Sinatra::Base.patch endpoint.path do
146
146
  endpoint.add_request request.body.read
147
- endpoint.default_response
147
+ endpoint.response
148
148
  end
149
149
  when 'POST'
150
150
  Sinatra::Base.post endpoint.path do
151
151
  endpoint.add_request request.body.read
152
- endpoint.default_response
152
+ endpoint.response
153
153
  end
154
154
  when 'DELETE'
155
155
  Sinatra::Base.delete endpoint.path do
156
156
  endpoint.add_request request.body.read
157
- endpoint.default_response
157
+ endpoint.response
158
158
  end
159
159
  end
160
160
 
@@ -167,7 +167,8 @@ module HttpSimulator
167
167
  end
168
168
 
169
169
  Sinatra::Base.put "#{endpoint.path}/response" do
170
- endpoint.response = request.body.read
170
+ new_response = request.body.read
171
+ endpoint.response = new_response
171
172
  end
172
173
 
173
174
  Sinatra::Base.post "#{endpoint.path}/response" do
@@ -4,7 +4,7 @@ describe 'responses' do
4
4
  before :each do
5
5
  HttpSimulator.reset_endpoints
6
6
 
7
- HttpSimulator.register_endpoint 'POST', '/hi', 'this is hi response'
7
+ HttpSimulator.register_endpoint 'GET', '/hi', 'this is hi response'
8
8
  HttpSimulator.register_endpoint 'POST', '/bye', 'this is bye response'
9
9
 
10
10
  HttpSimulator.run_daemon!(port: test_port)
@@ -44,12 +44,9 @@ describe 'responses' do
44
44
  end
45
45
 
46
46
  it 'PUT /<endpoint>/response alters response for endpoint' do
47
- resp = json_get '/hi/response'
48
- expect(resp.body).to eq 'this is hi response'
49
-
47
+ expect_response '/hi', 'this is hi response'
50
48
  put '/hi/response', 'this is some new response'
51
- resp = json_get '/hi/response'
52
- expect(resp.body).to eq 'this is some new response'
49
+ expect_response '/hi', 'this is some new response'
53
50
  end
54
51
 
55
52
  xit '.set_response alters response for endpoint' # TODO
@@ -66,15 +63,19 @@ describe 'responses' do
66
63
 
67
64
  it 'DELETE /<endpoint>/response resets response for endpoint' do
68
65
  put '/hi/response', 'this is some new response'
69
- resp = json_get '/hi/response'
70
- expect(resp.body).to eq 'this is some new response'
71
-
66
+ expect_response '/hi', 'this is some new response'
72
67
  delete '/hi/response'
73
-
74
- resp = json_get '/hi/response'
75
- expect(resp.body).to eq 'this is hi response'
68
+ expect_response '/hi', 'this is hi response'
76
69
  end
77
70
 
78
71
  xit '.reset_response resets response for endpoint' # TODO
79
72
  end
73
+
74
+ def expect_response(endpoint, response)
75
+ resp = json_get "#{endpoint}/response"
76
+ expect(resp.body).to eq response
77
+
78
+ resp = get endpoint
79
+ expect(resp.body).to include response
80
+ end
80
81
  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: 1.0.0
4
+ version: 1.0.1
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-30 00:00:00.000000000 Z
11
+ date: 2016-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra