mocktopus 0.0.4 → 0.0.5

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: 5c7dd5e4c53bbd5b1aff16acb47abbffae3be411
4
- data.tar.gz: 4517dbbda052ffb494852ec3586f698151e45e00
3
+ metadata.gz: 28cb7cf89cc2fadda28177ec9b09e8e3e02befde
4
+ data.tar.gz: a24297d38f8c31cff6f40c7b4df2886bc08303c9
5
5
  SHA512:
6
- metadata.gz: 072bb9f8221692ce8b2ecf0a8222733096a0584068b4922d2c26be6dec79cfa9411f0e401203f947d93028aad4bacb5f114ad7643534ba0196fa482c99295480
7
- data.tar.gz: 4a9c3716d2a2dad0681cc0c5643a4179ad366dad33f78c25c7644ae23753bd2ed82bf91ec694b3520aae5245a6b9c1eebb030ad5fe761078ba23ec7bbc31e334
6
+ metadata.gz: f77bee53b77b0082bcd392959fe684295ff56399e6b09510953b6c6f7320fee19183a21f7dd002cdf6246c3b276c1664948f99ff443c52a490e8139c7e9799db
7
+ data.tar.gz: 1939142bd0dd2c5b18992c90bd135af2b3ec32ee2084ccddc11c62a5197c9e22b7a7acf2c139e5ce4e4cab51d0c2082e0c93175b060401873c793cc3dd1e0357
data/mocktopus.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mocktopus'
5
- s.version = '0.0.4'
5
+ s.version = '0.0.5'
6
6
  s.date = '2015-03-14'
7
7
  s.required_ruby_version = '>= 1.9.3'
8
8
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.email = ['racksburg_automation@lists.rackspace.com']
13
13
  s.homepage = 'https://github.com/rackspaceautomationco/mocktopus'
14
14
 
15
- s.files = `git ls-files`.split($/)
15
+ s.files = Dir.glob("{bin,lib}/**/*") + %w(MIT-LICENSE README.md Gemfile mocktopus.gemspec config.ru ascii.rb)
16
16
  s.executables = %w(mocktopus)
17
17
 
18
18
  s.add_dependency 'sinatra', '~> 1.4', '>= 1.4.4'
@@ -20,10 +20,11 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'thin', '~> 1.6.1', '>= 1.6.1'
21
21
  s.add_dependency 'thor', '~> 0.19.1', '>= 0.19.1'
22
22
  s.add_dependency 'rack', '~> 1.5.2', '>= 1.5.2'
23
- s.add_dependency 'rake', '~> 10.1.0', '>= 10.1.0'
24
- s.add_dependency 'minitest', '~> 5.2.0', '>= 5.2.0'
25
- s.add_dependency 'fakeweb', '~> 1.3.0', '>= 1.3.0'
26
- s.add_dependency 'mocha', '~> 0.14.0', '>= 0.14.0'
27
- s.add_dependency 'simplecov', '~> 0.9.2', '>= 0.9.2'
28
- s.add_dependency 'coveralls', '~> 0.7.11', '>= 0.7.11'
23
+
24
+ s.add_development_dependency 'rake', '~> 10.1.0', '>= 10.1.0'
25
+ s.add_development_dependency 'minitest', '~> 5.2.0', '>= 5.2.0'
26
+ s.add_development_dependency 'fakeweb', '~> 1.3.0', '>= 1.3.0'
27
+ s.add_development_dependency 'mocha', '~> 0.14.0', '>= 0.14.0'
28
+ s.add_development_dependency 'simplecov', '~> 0.9.2', '>= 0.9.2'
29
+ s.add_development_dependency 'coveralls', '~> 0.7.11', '>= 0.7.11'
29
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocktopus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rackspace
@@ -120,7 +120,7 @@ dependencies:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: 10.1.0
123
- type: :runtime
123
+ type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
@@ -140,7 +140,7 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: 5.2.0
143
- type: :runtime
143
+ type: :development
144
144
  prerelease: false
145
145
  version_requirements: !ruby/object:Gem::Requirement
146
146
  requirements:
@@ -160,7 +160,7 @@ dependencies:
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
162
  version: 1.3.0
163
- type: :runtime
163
+ type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
@@ -180,7 +180,7 @@ dependencies:
180
180
  - - ">="
181
181
  - !ruby/object:Gem::Version
182
182
  version: 0.14.0
183
- type: :runtime
183
+ type: :development
184
184
  prerelease: false
185
185
  version_requirements: !ruby/object:Gem::Requirement
186
186
  requirements:
@@ -200,7 +200,7 @@ dependencies:
200
200
  - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  version: 0.9.2
203
- type: :runtime
203
+ type: :development
204
204
  prerelease: false
205
205
  version_requirements: !ruby/object:Gem::Requirement
206
206
  requirements:
@@ -220,7 +220,7 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: 0.7.11
223
- type: :runtime
223
+ type: :development
224
224
  prerelease: false
225
225
  version_requirements: !ruby/object:Gem::Requirement
226
226
  requirements:
@@ -239,13 +239,9 @@ executables:
239
239
  extensions: []
240
240
  extra_rdoc_files: []
241
241
  files:
242
- - ".coveralls.yml"
243
- - ".gitignore"
244
- - ".travis.yml"
245
242
  - Gemfile
246
243
  - MIT-LICENSE
247
244
  - README.md
248
- - Rakefile
249
245
  - ascii.rb
250
246
  - bin/mocktopus
251
247
  - config.ru
@@ -258,14 +254,6 @@ files:
258
254
  - lib/mocktopus/mock_api_call_container.rb
259
255
  - lib/mocktopus/response.rb
260
256
  - mocktopus.gemspec
261
- - test/app_test.rb
262
- - test/cli_test.rb
263
- - test/input_container_test.rb
264
- - test/input_test.rb
265
- - test/mock_api_call_container_test.rb
266
- - test/mock_api_call_test.rb
267
- - test/response_test.rb
268
- - test/test_helper.rb
269
257
  homepage: https://github.com/rackspaceautomationco/mocktopus
270
258
  licenses: []
271
259
  metadata: {}
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *DS_STORE
2
- /Gemfile.lock
3
- *.gem
4
- coverage/
5
- .ruby-version
6
- *.log.*
7
- *.log
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.2
4
- - 2.0.0
5
- - 1.9.3
6
- notifications:
7
- email:
8
- - justin.brown@rackspace.com
9
- script: "rake test"
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'bundler/gem_tasks'
4
-
5
- require 'rake/testtask'
6
- Rake::TestTask.new(:test) do |test|
7
- test.libs << 'lib' << 'test'
8
- test.pattern = 'test/**/*_test.rb'
9
- end
10
-
11
- task :default => [:test]
data/test/app_test.rb DELETED
@@ -1,276 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
-
4
- class AppTest < Mocktopus::Test
5
-
6
- def setup
7
-
8
- end
9
-
10
- def app
11
- Sinatra::Application
12
- end
13
-
14
- def test_inputs_nothing_raised
15
- body = {
16
- 'foo' => 'bar'
17
- }
18
- input_object = create_input('/v0/bar', 'GET', nil, JSON.pretty_generate(body), 200, nil, "")
19
-
20
- response = post '/mocktopus/inputs/test_inputs_nothing_raised', JSON.pretty_generate(input_object)
21
- assert_equal(200, response.status)
22
- end
23
-
24
- def test_bad_input_returns_400
25
- post '/mocktopus/inputs/test_bad_input_returns_400', {}, {}
26
- assert_equal 400, last_response.status
27
- end
28
-
29
- def test_all_inputs
30
- input1 = create_input('/v0/test_all_inputs_foo', 'GET', nil, nil, 200, nil, "")
31
- post '/mocktopus/inputs/test_all_inputs_foo', JSON.pretty_generate(input1)
32
-
33
- input2 = create_input('/v0/test_all_inputs_bar', 'GET', nil, nil, 200, nil, "")
34
- post '/mocktopus/inputs/test_all_inputs_bar', JSON.pretty_generate(input2)
35
-
36
- inputs_response = get '/mocktopus/inputs'
37
- json = JSON.parse(inputs_response.body)
38
- refute_nil json['test_all_inputs_foo']
39
- refute_nil json['test_all_inputs_bar']
40
- end
41
-
42
- def test_match_get
43
- response_body_hash = {
44
- "key1" => "value1",
45
- "key2" => "value2"
46
- }
47
- input1 = create_input('/v0/test_match_get1', 'GET', { "host"=>"example.org", "cookie"=>"" }, nil, 200, nil, response_body_hash)
48
- post '/mocktopus/inputs/test_match_get1', JSON.pretty_generate(input1)
49
-
50
- response = get '/v0/test_match_get1'
51
- assert_equal(200, response.status)
52
- assert_equal(response_body_hash, JSON.parse(response.body))
53
- end
54
-
55
- def test_match_post
56
- post_body_hash = {
57
- "name" => "John",
58
- "email" => "john@127.0.0.1"
59
- }
60
- response_body_hash = {
61
- "response" => "ok!"
62
- }
63
- input1 = create_input('/v0/test_match_post1', 'POST', { "host"=>"example.org", "cookie"=>"" }, post_body_hash, 202, nil, response_body_hash)
64
- post '/mocktopus/inputs/test_match_post1', input1.to_json
65
-
66
- response = post '/v0/test_match_post1', post_body_hash.to_json
67
- assert_equal(202, response.status)
68
- assert_equal(response_body_hash, JSON.parse(response.body))
69
- end
70
-
71
- def test_input_by_name
72
- input1 = create_input('/v0/test_input_by_name_foo', 'GET', nil, "", 200, nil, "")
73
- post '/mocktopus/inputs/test_input_by_name_foo', input1.to_json
74
-
75
- input2 = create_input('/v0/test_input_by_name_bar', 'GET', nil, "", 200, nil, "")
76
- post '/mocktopus/inputs/test_input_by_name_bar', input2.to_json
77
-
78
- input_by_name_response = get '/mocktopus/inputs/test_input_by_name_foo'
79
- json = JSON.parse(input_by_name_response.body)
80
- refute_nil json
81
- assert_equal(input1, json)
82
- assert (json != input2)
83
- end
84
-
85
- def test_delete_all
86
- input1 = create_input('/v0/test_delete_all_foo', 'GET', nil, nil, 200, nil, "")
87
- post '/mocktopus/inputs/test_delete_all_foo', JSON.pretty_generate(input1)
88
-
89
- delete '/mocktopus/inputs'
90
-
91
- inputs_response = get'/mocktopus/inputs'
92
- json = JSON.parse(inputs_response.body)
93
- assert_equal(0, json.size())
94
- end
95
-
96
- def test_delete_by_name
97
- input1 = create_input('/v0/test_delete_by_name_foo', 'GET', nil, "", 200, nil, "")
98
- post '/mocktopus/inputs/test_delete_by_name_foo', JSON.pretty_generate(input1)
99
-
100
- input2 = create_input('/v0/test_delete_by_name_bar', 'GET', nil, "", 200, nil, "")
101
- post '/mocktopus/inputs/test_delete_by_name_bar', JSON.pretty_generate(input2)
102
-
103
- delete '/mocktopus/inputs/test_delete_by_name_foo'
104
-
105
- inputs_response = get '/mocktopus/inputs/test_delete_by_name_bar'
106
- json = JSON.parse(inputs_response.body)
107
- refute_nil json
108
- assert_equal(input2, json)
109
- assert (json != input1)
110
- end
111
-
112
- def test_not_found_matching_input_found
113
- input1 = create_input('/test_not_found_matching_input_found/1', 'POST', { "host" => "example.org", "cookie" => "" }, JSON.pretty_generate({ "foo" => "bar" }), 200, { "bar" => "foo" }, JSON.pretty_generate({ "body" => "foobar" }))
114
- post '/mocktopus/inputs/test_not_found_matching_input_found', JSON.pretty_generate(input1)
115
-
116
- response = post '/test_not_found_matching_input_found/1', JSON.pretty_generate({"foo" => "bar"})
117
-
118
- assert_equal(200, response.status)
119
- end
120
-
121
- def test_mock_api_calls
122
- uri = '/test_mock_api_calls/1'
123
- verb = 'POST'
124
- code = 200
125
- body = {
126
- "key1" => "value_one",
127
- "key2" => "value_two"
128
- }
129
- input = create_input(uri, verb, body, '', code, {}, '')
130
- post "/mocktopus/inputs/#{uri}", input
131
-
132
- post uri, JSON.pretty_generate(body)
133
- calls = get '/mocktopus/mock_api_calls'
134
- json = JSON.parse(calls.body)
135
- this_test_call = json.select{|k| k['path'] == uri }.first
136
- refute_nil this_test_call
137
- assert_equal(uri, this_test_call['path'])
138
- assert_equal(verb, this_test_call['verb'])
139
- assert_equal(body, this_test_call['body'])
140
- end
141
-
142
- def test_mock_api_calls_with_parameters
143
- uri = '/test_mock_api_calls_with_parameters/foo?key=(domain=getstatus.com)&start=0&pageSize=100'
144
- verb = 'GET'
145
- code = 200
146
- input = create_input(uri, verb, {}, '', code, {}, '')
147
- post "/mocktopus/inputs/#{uri}", input
148
-
149
- delete '/mocktopus/mock_api_calls'
150
-
151
- get uri
152
- calls = JSON.parse(get('/mocktopus/mock_api_calls').body)
153
- this_test_call = calls.select{|k| k['path'] == uri }.first
154
- refute_nil this_test_call
155
- assert_equal(uri, this_test_call['path'])
156
- assert_equal(verb, this_test_call['verb'])
157
- end
158
-
159
- def test_delete_mock_api_calls
160
- uri = '/test_delete_mock_api_calls/1'
161
- verb = 'POST'
162
- code = 200
163
- body = {
164
- "key1" => "value_one",
165
- "key2" => "value_two"
166
- }
167
- input = create_input(uri, verb, body, '', code, {}, '')
168
- post "/mocktopus/inputs/#{uri}", input
169
-
170
- post uri, JSON.pretty_generate(body)
171
- calls = get '/mocktopus/mock_api_calls'
172
- json = JSON.parse(calls.body)
173
- assert(0 < json.size)
174
- delete '/mocktopus/mock_api_calls'
175
- calls = get '/mocktopus/mock_api_calls'
176
- json = JSON.parse(calls.body)
177
- assert(0 == json.size)
178
- end
179
-
180
- def test_get_missing_input_returns_405
181
- response = get "/mocktopus/inputs/does_not_exist"
182
- assert_equal(405, response.status)
183
- end
184
-
185
- def test_input_sequencing
186
- uri = '/test_input_sequencing'
187
- verb = 'GET'
188
- code = 200
189
- body1 = {
190
- "status" => "pending"
191
- }
192
- body2 = {
193
- "status" => "completed"
194
- }
195
-
196
- input1 = create_input(uri, verb, {}, nil, code, {}, body1)
197
- input2 = create_input(uri, verb, {}, nil, code, {}, body1)
198
- input3 = create_input(uri, verb, {}, nil, code, {}, body2)
199
-
200
- post "/mocktopus/inputs/test_input_sequencing_1", JSON.pretty_generate(input1)
201
- post "/mocktopus/inputs/test_input_sequencing_2", JSON.pretty_generate(input2)
202
- post "/mocktopus/inputs/test_input_sequencing_3", JSON.pretty_generate(input3)
203
-
204
- response = get uri, nil
205
- assert_equal(body1, JSON.parse(response.body))
206
- response = get uri, nil
207
- assert_equal(body1, JSON.parse(response.body))
208
- response = get uri, nil
209
- assert_equal(body2, JSON.parse(response.body))
210
- end
211
-
212
- def test_nil_headers
213
- uri = '/test_nil_headers?foo=bar&email=test@test.com'
214
- verb = 'GET'
215
- code = 200
216
- input = create_input(uri, verb, nil, nil, code, nil, {})
217
- post '/mocktopus/inputs/test_nil_headers', JSON.pretty_generate(input)
218
-
219
- response = get uri, nil
220
- assert_equal(code, response.status)
221
- end
222
-
223
- def test_unicode_in_body
224
- uri = 'test_unicode'
225
- verb = 'POST'
226
- body =
227
- {
228
- "uri" => "¾öäëöäëü",
229
- "msg" => "I am the unicöde monster"
230
- }
231
- code = 200
232
- input = create_input(uri, verb, {}, body, code, {}, body)
233
- post "/mocktopus/inputs/test_unicode_in_body", JSON.pretty_generate(input)
234
-
235
- response = get "/mocktopus/inputs/test_unicode_in_body"
236
- assert_equal(body, JSON.parse(JSON.parse(response.body)['body']))
237
- end
238
-
239
- def test_uri_encoding
240
- uri = 'test_unicode'
241
- verb = 'POST'
242
- body =
243
- {
244
- "uri" => 'https://web.archive.org/web/20060204114947/http://www.googles.com/index_noflash.html'
245
- }
246
- code = 200
247
- input = create_input(uri, verb, {}, body, code, {}, body)
248
- post "/mocktopus/inputs/test_uri_encoding", JSON.pretty_generate(input)
249
-
250
- response = get "/mocktopus/inputs/test_uri_encoding"
251
- assert_equal(body, JSON.parse(JSON.parse(response.body)['body']))
252
- end
253
-
254
- def test_failed_match_returns_json
255
- random_uri = "/#{SecureRandom.uuid}"
256
- get random_uri
257
- assert_equal 428, last_response.status
258
- assert_equal random_uri, JSON.parse(last_response.body)['call']['path']
259
- end
260
-
261
- private
262
- def create_input(uri, verb, headers, body, response_code, response_headers, response_body)
263
- input = {}
264
- input['uri'] = uri
265
- input['headers'] = headers
266
- input['body'] = body
267
- input['verb'] = verb
268
- input['response'] = {
269
- "code" => response_code,
270
- "headers" => response_headers,
271
- "body" => response_body,
272
- "delay" => 0
273
- }
274
- return input
275
- end
276
- end
data/test/cli_test.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CLITest < Mocktopus::Test
4
- def setup
5
- @cli = Mocktopus::CLI.new
6
- end
7
-
8
- def test_start_task_starts_mocktopus_with_default_port
9
- command = 'bundle exec thin -R config.ru start -p 8081 '
10
- @cli.stubs(:run_command).with(command).once
11
- @cli.start
12
- end
13
-
14
- def test_start_task_starts_mocktopus_with_custom_port
15
- command = 'bundle exec thin -R config.ru start -p 7071'
16
- @cli.stubs(:run_command).with(command).once
17
- @cli.start('-p', '7071')
18
- end
19
-
20
- def test_stop_task_stops_mocktopus
21
- @cli.stubs(:run_command).with('bundle exec thin stop')
22
- @cli.stop
23
- end
24
-
25
- end
@@ -1,229 +0,0 @@
1
- require 'test_helper'
2
-
3
- class InputContainerTest < Mocktopus::Test
4
-
5
- def test_initialize_not_nil
6
- container = Mocktopus::InputContainer.new
7
- refute_nil container
8
- end
9
-
10
- def test_all_returns_zero_on_init
11
- container = Mocktopus::InputContainer.new
12
- all_inputs = container.all()
13
- assert_equal(0, all_inputs.size())
14
- end
15
-
16
- def test_all_returns_count_after_add
17
- container = Mocktopus::InputContainer.new
18
- container.add("hash1", {})
19
- container.add("hash2", {})
20
- all_inputs = container.all()
21
- assert_equal(2, all_inputs.size())
22
- end
23
-
24
- def test_get_by_returns_existing_input
25
- container = Mocktopus::InputContainer.new
26
- container.add("hash1", {})
27
- hash1 = container.get_by("hash1")
28
- refute_nil hash1
29
- end
30
-
31
- def test_get_by_returns_nil_for_missing_input
32
- container = Mocktopus::InputContainer.new
33
- container.add("hash1", {})
34
- hash2 = container.get_by("hash2")
35
- assert_nil(hash2)
36
- end
37
-
38
- def test_delete_all_returns_empty_hash
39
- container = Mocktopus::InputContainer.new
40
- container.add("hash1", {})
41
- container.add("hash2", {})
42
- container.delete_all()
43
- all_after_delete = container.all()
44
- assert_equal(0, all_after_delete.size())
45
- end
46
-
47
- def test_delete_by_deletes_input
48
- container = Mocktopus::InputContainer.new
49
- container.add("hash1", {})
50
- container.add("hash2", {})
51
- container.delete_by("hash2")
52
- all = container.all()
53
- assert_equal(1, all.size())
54
- hash1 = container.get_by("hash1")
55
- refute_nil hash1
56
- end
57
-
58
- def test_delete_by_missing_input_does_nothing
59
- container = Mocktopus::InputContainer.new
60
- container.add("hash1", {})
61
- container.delete_by("hash2")
62
- all = container.all()
63
- assert_equal(1, all.size())
64
- hash1 = container.get_by("hash1")
65
- refute_nil hash1
66
- end
67
-
68
- def test_single_match_returns_match
69
- response = Mocktopus::Response.new({
70
- "code" => "200",
71
- "headers" => {},
72
- "body" => {
73
- "foo" => "baz"
74
- }
75
- })
76
-
77
- input = Mocktopus::Input.new({
78
- "uri" => "/v0/test_single_match_returns_match",
79
- "verb" => "POST",
80
- "headers" => {},
81
- "body" => {
82
- "foo" => "bar"
83
- }
84
- }, response)
85
-
86
- container = Mocktopus::InputContainer.new
87
- container.add("input1", input)
88
- match_result = container.match("/v0/test_single_match_returns_match", "POST", {}, JSON.pretty_generate({"foo" => "bar"}), {})
89
- refute_nil match_result
90
- assert_equal(response, match_result.response)
91
- end
92
-
93
- def test_single_match_returns_match_encoded
94
- response = Mocktopus::Response.new({
95
- "code" => "200",
96
- "headers" => {},
97
- "body" => {
98
- "key" => "test_single_match_returns_match_encoded"
99
- }
100
- })
101
-
102
- input = Mocktopus::Input.new({
103
- "uri" => "/v0/test_single_match_returns_match_encoded/(key%3Dvalue)",
104
- "verb" => "POST",
105
- "headers" => {},
106
- "body" => {
107
- "key" => "test_single_match_returns_match_encoded"
108
- }
109
- }, response)
110
-
111
- container = Mocktopus::InputContainer.new
112
- container.add("input1", input)
113
- match_result = container.match("/v0/test_single_match_returns_match_encoded/(key=value)", "POST", {}, JSON.pretty_generate({"key" => "test_single_match_returns_match_encoded"}), {})
114
- refute_nil match_result
115
- assert_equal(response, match_result.response)
116
- end
117
-
118
- def test_headers_match_returns_single_result_for_dashes
119
- response = Mocktopus::Response.new({
120
- "code" => "200",
121
- "headers" => {},
122
- "body" => {
123
- "key" => "test_headers_match_returns_single_result_for_dashes"
124
- }
125
- })
126
-
127
- input = Mocktopus::Input.new({
128
- "uri" => "/v0/test_headers_match_returns_single_result_for_dashes",
129
- "verb" => "GET",
130
- "headers" => { 'g-sub-me' => 'fizz'},
131
- 'body' => {}
132
- }, response)
133
-
134
- container = Mocktopus::InputContainer.new
135
- container.add("input1", input)
136
- match_result = container.match("/v0/test_headers_match_returns_single_result_for_dashes", "GET", {'g_sub_me' => 'fizz'}, {}, {})
137
- refute_nil match_result
138
- assert_equal(response, match_result.response)
139
- end
140
-
141
- def test_headers_different_value_no_result_for_dashes
142
- response = Mocktopus::Response.new({
143
- "code" => "200",
144
- "headers" => {},
145
- "body" => {
146
- "key" => "test_headers_different_value_no_result_for_dashes"
147
- }
148
- })
149
-
150
- input = Mocktopus::Input.new({
151
- "uri" => "/v0/test_headers_different_value_no_result_for_dashes",
152
- "verb" => "GET",
153
- "headers" => { 'g-sub-mez' => 'fizz'},
154
- 'body' => {}
155
- }, response)
156
-
157
- container = Mocktopus::InputContainer.new
158
- container.add("input1", input)
159
- match_result = container.match("/v0/test_headers_different_value_no_result_for_dashes", "GET", {'g_sub_me' => 'fizz'}, {}, {})
160
- assert_nil match_result
161
- end
162
-
163
- def test_headers_no_match_returns_nil_result_for_dashes
164
- response = Mocktopus::Response.new({
165
- "code" => "200",
166
- "headers" => {},
167
- "body" => {
168
- "key" => "test_headers_no_match_returns_nil_result_for_dashes"
169
- }
170
- })
171
-
172
- input = Mocktopus::Input.new({
173
- "uri" => "/v0/test_headers_no_match_returns_nil_result_for_dashes",
174
- "verb" => "GET",
175
- "headers" => { 'g-sub-me' => 'pop'}
176
- }, response)
177
-
178
- container = Mocktopus::InputContainer.new
179
- container.add("input1", input)
180
- match_result = container.match("/v0/test_headers_no_match_returns_nil_result_for_dashes", "GET", {'g_sub_me' => 'fizz'}, nil, nil)
181
- assert_nil match_result
182
- end
183
-
184
- def test_single_match_no_inputs_returns_nil
185
- container = Mocktopus::InputContainer.new
186
- match_result = container.match("/v0/test_single_match_no_inputs_returns_nil", "POST", {}, JSON.pretty_generate({}), {})
187
- assert_nil(match_result)
188
- end
189
-
190
- def test_multiple_inputs_returns_correct_sequence
191
- response1 = Mocktopus::Response.new({
192
- "code" => "200",
193
- "headers" => {},
194
- "body" => {
195
- "status" => "pending"
196
- }
197
- })
198
-
199
- response2 = Mocktopus::Response.new({
200
- "code" => "200",
201
- "headers" => {},
202
- "body" => {
203
- "status" => "complete"
204
- }
205
- })
206
-
207
- input_hash = {
208
- "uri" => "/v0/test_multiple_inputs_returns_correct_sequence",
209
- "verb" => "GET",
210
- "headers" => {},
211
- "body" => nil
212
- }
213
-
214
- container = Mocktopus::InputContainer.new
215
- container.add("first_input", Mocktopus::Input.new(input_hash, response1))
216
- container.add("second_input", Mocktopus::Input.new(input_hash, response1))
217
- container.add("last_input", Mocktopus::Input.new(input_hash, response2))
218
-
219
- first_match = container.match("/v0/test_multiple_inputs_returns_correct_sequence", "GET", {}, "", {})
220
- assert_equal(response1, first_match.response)
221
-
222
- second_match = container.match("/v0/test_multiple_inputs_returns_correct_sequence", "GET", {}, "", {})
223
- assert_equal(response1, second_match.response)
224
-
225
- last_match = container.match("/v0/test_multiple_inputs_returns_correct_sequence", "GET", {}, "", {})
226
- assert_equal(response2, last_match.response)
227
- end
228
-
229
- end
data/test/input_test.rb DELETED
@@ -1,166 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
-
4
- class ResponseTest < Mocktopus::Test
5
-
6
- def test_to_hash
7
- input = build_input({})
8
- hash = input.to_hash
9
-
10
- assert_equal( '/uri', hash['uri'])
11
- assert_equal( 'application/json', hash['headers']['Content-Type'])
12
- assert_equal( '{}', hash['body'])
13
- assert_equal( {}, hash['response'])
14
- end
15
-
16
- def test_to_hash_extra_fields
17
- input = build_input({'nosuch' => 'extra'})
18
- hash = input.to_hash
19
-
20
- assert_equal(hash['nosuch'], nil)
21
- end
22
-
23
- def test_validate_input_errors
24
- assert_raises Mocktopus::Input::ValidationError do
25
- build_input({'uri' => '/[^\-_.!~*\'()a-zA-Z\d;\/?:@&=+$,\[\]]/
26
- => /[^\-_.!~*\'()a-zA-Z\d;\/?:@&=+$,\[\]]/
27
- irb(main):003:0> p Regexp.union([URI::Parser.new.regexp[:UNSAFE],\'~\',\'@\'])
28
- /(?-mix:[^\-_.!~*\'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
29
- => /(?-mix:[^\-_.!~*\'()a-zA-Z\d;\/?:@&'})
30
- end
31
-
32
- assert_raises Mocktopus::Input::ValidationError do
33
- build_input({'uri' => 'irb(main):005:0*'})
34
- end
35
-
36
- assert_raises Mocktopus::Input::ValidationError do
37
- build_input({'headers' => {nil => nil}})
38
- end
39
-
40
- build_input({'body' => nil})
41
-
42
- assert_raises Mocktopus::Input::ValidationError do
43
- build_input({}, "Not a response object")
44
- end
45
-
46
- assert_raises Mocktopus::Input::ValidationError do
47
- build_input({'verb' => SecureRandom.uuid})
48
- end
49
-
50
- build_input({}, nil)
51
- end
52
-
53
- def test_flexible_uris
54
- assert_equal(build_input({'uri' => '%C3%B6%C3%BF%C3%A0%C3%A1%C3%A4'}).to_hash, build_input({'uri' => 'öÿàáä'}).to_hash)
55
- end
56
-
57
- def test_to_hash_returns_properties_with_one_param
58
- hash = {
59
- 'uri' => '/test?parameter_one=foo',
60
- 'headers' => {
61
- 'Content-Type' => 'appilcation/json'
62
- },
63
- 'body' => {
64
- 'body_one' => 'uno',
65
- 'body_two' => {
66
- 'nested' => 'value'
67
- }
68
- },
69
- 'verb' => 'POST'
70
- }
71
- input = Mocktopus::Input.new(hash, response_with_empty_hash())
72
-
73
- hashed_input = input.to_hash
74
- assert_equal(hash['uri'], hashed_input['uri'])
75
- assert_equal(hash['headers'], hashed_input['headers'])
76
- assert_equal(JSON.pretty_generate(hash['body']), hashed_input['body'])
77
- assert_equal(hash['verb'], hashed_input['verb'])
78
- end
79
-
80
- def test_to_hash_returns_properties_with_no_params
81
- hash = {
82
- 'uri' => '/test',
83
- 'headers' => {
84
- 'Content-Type' => 'appilcation/json'
85
- },
86
- 'body' => {
87
- 'body_one' => 'uno',
88
- 'body_two' => {
89
- 'nested' => 'value'
90
- }
91
- },
92
- 'verb' => 'POST'
93
- }
94
- input = Mocktopus::Input.new(hash, response_with_empty_hash())
95
-
96
- hashed_input = input.to_hash
97
- assert_equal(hash['uri'], hashed_input['uri'])
98
- assert_equal(hash['headers'], hashed_input['headers'])
99
- assert_equal(JSON.pretty_generate(hash['body']), hashed_input['body'])
100
- assert_equal(hash['verb'], hashed_input['verb'])
101
- end
102
-
103
- def test_to_hash_returns_properties_with_two_params
104
- hash = {
105
- 'uri' => '/test?parameter_one=foo&parameter_two=bar',
106
- 'headers' => {
107
- 'Content-Type' => 'appilcation/json'
108
- },
109
- 'body' => {
110
- 'body_one' => 'uno',
111
- 'body_two' => {
112
- 'nested' => 'value'
113
- }
114
- },
115
- 'verb' => 'POST'
116
- }
117
- input = Mocktopus::Input.new(hash, response_with_empty_hash())
118
-
119
- hashed_input = input.to_hash
120
- assert_equal(hash['uri'], hashed_input['uri'])
121
- assert_equal(hash['headers'], hashed_input['headers'])
122
- assert_equal(JSON.pretty_generate(hash['body']), hashed_input['body'])
123
- assert_equal(hash['verb'], hashed_input['verb'])
124
- end
125
-
126
- def test_to_s
127
- hash = {
128
- 'uri' => '/test/to/s',
129
- 'verb' => 'GET'
130
- }
131
- input = Mocktopus::Input.new(hash, response_with_empty_hash())
132
- s = input.to_s
133
- assert_equal 'String', s.class.name
134
-
135
- end
136
-
137
- private
138
-
139
- def build_input(hash = {}, response = response_with_empty_hash())
140
- input = Mocktopus::Input.new(
141
- {
142
- 'uri' => 'http://localhost/uri',
143
- 'headers' => {
144
- 'Content-Type' => 'application/json'
145
- },
146
- 'body' => '{}',
147
- 'verb' => 'post'
148
- }.merge(hash),
149
- response
150
- )
151
- return input
152
- end
153
-
154
- def response_with_empty_hash
155
- response = Mocktopus::Response.new({
156
- 'code' => 200,
157
- 'headers' => nil,
158
- 'body' => nil
159
- })
160
-
161
- def response.to_hash
162
- {}
163
- end
164
- return response
165
- end
166
- end
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MockApiCallContainerTest < Mocktopus::Test
4
-
5
- def test_initialize_not_nil
6
- container = Mocktopus::MockApiCallContainer.new
7
- refute_nil container
8
- assert_equal('Mocktopus::MockApiCallContainer', container.class.name)
9
- end
10
-
11
- def test_add
12
- container = Mocktopus::MockApiCallContainer.new
13
- call = Mocktopus::MockApiCall.new('/foo/bar', 'POST', {"header1" => "header_one"}, {"body1" => "body_one"})
14
- container.add(call)
15
- end
16
-
17
- def test_all
18
- container = Mocktopus::MockApiCallContainer.new
19
- 10.times do |i|
20
- container.add(Mocktopus::MockApiCall.new("/foo/bar/#{i}", 'POST', {"header#{i}" => "header_#{i}"}, {"body#{i}" => "body_#{i}"}))
21
- end
22
- all = container.all
23
- refute_nil all.select{|a| a['path'] == '/foo/bar/0'}.first
24
- end
25
-
26
- end
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MockApiCallTest < Mocktopus::Test
4
-
5
- def test_constructor
6
- path = '/test_constructor/1'
7
- verb = 'POST'
8
- headers = {}
9
- headers['header1'] = 'header1'
10
- headers['header2'] = 'header2'
11
- body = {}
12
- body['one'] = 1
13
- body['two'] = 2
14
- call = Mocktopus::MockApiCall.new(path, verb, headers, body)
15
- refute_nil call
16
- assert_equal(path, call.path)
17
- assert_equal(verb, call.verb)
18
- assert_equal(headers, call.headers)
19
- assert_equal(body, call.body)
20
- end
21
-
22
- def test_timestamp
23
- call = Mocktopus::MockApiCall.new('/foo/bar', 'DELETE', {}, {})
24
- refute_nil call.timestamp
25
- parsed_time = Time.iso8601(call.timestamp)
26
- assert_equal('Time', parsed_time.class.name)
27
- end
28
-
29
- def test_to_s
30
- call = Mocktopus::MockApiCall.new('/test/to/s', 'GET', {}, {})
31
- s = call.to_s
32
- assert_equal 'String', s.class.name
33
- end
34
-
35
- end
@@ -1,64 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ResponseTest < Mocktopus::Test
4
-
5
- def test_to_hash
6
- input = build_response({})
7
- hash = input.to_hash
8
-
9
- assert_equal(hash['headers']['Content-Type'], 'application/json')
10
- assert_equal(hash['body'], '{}')
11
- assert_equal(hash['code'], 200)
12
- end
13
-
14
- def test_to_hash_extra_fields
15
- input = build_response({'nosuch' => 'extra'})
16
- hash = input.to_hash
17
-
18
- assert_equal(hash['nosuch'], nil)
19
- end
20
-
21
- def test_validation
22
-
23
- assert_raises Mocktopus::Response::ValidationError do
24
- build_response({'headers' => {nil => nil}})
25
- end
26
-
27
- assert_raises Mocktopus::Response::ValidationError do
28
- build_response({'code' => "Not a code"})
29
- end
30
- build_response({})
31
-
32
- end
33
-
34
- def test_delay_integer
35
- input = build_response({'delay' => 15})
36
- hash = input.to_hash
37
- assert_equal(15, hash['delay'])
38
- end
39
-
40
- def test_delay_float
41
- input = build_response({'delay' => 12.54542})
42
- hash = input.to_hash
43
- assert_equal(12.54542, hash['delay'])
44
- end
45
-
46
- def test_delay_invalid
47
- input = build_response({'delay' => 'invalid_delay'})
48
- hash = input.to_hash
49
- assert_equal(0, hash['delay'])
50
- end
51
-
52
- def build_response(hash)
53
- response = Mocktopus::Response.new(
54
- {
55
- 'code' => 200,
56
- 'headers' => {
57
- 'Content-Type' => 'application/json'
58
- },
59
- 'body' => '{}'
60
- }.merge(hash)
61
- )
62
- return response
63
- end
64
- end
data/test/test_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- Coveralls::SimpleCov::Formatter,
6
- SimpleCov::Formatter::HTMLFormatter
7
- ]
8
-
9
- SimpleCov.start do
10
- add_filter '/test/'
11
- add_filter '/ascii.rb'
12
- end
13
-
14
- require 'rack/test'
15
- require 'tmpdir'
16
- require 'fakeweb'
17
- require 'minitest/autorun'
18
- require 'mocha/setup'
19
-
20
- require_relative '../lib/mocktopus'
21
-
22
- FakeWeb.allow_net_connect = %r[^https?://coveralls.io]
23
-
24
- ENV['RACK_ENV'] = 'test'
25
- WORKING_DIRECTORY = Dir.pwd.freeze
26
- ARGV.clear
27
-
28
- module Mocktopus
29
- class Test < Minitest::Test
30
- include Rack::Test::Methods
31
-
32
- end
33
- end