mock5 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 302684b3737df5efb208d19be1208d91dfeebfb8
4
- data.tar.gz: ab4838372d0d023ad51803d070ae85a32aea430c
3
+ metadata.gz: 4b1a0b9b9f98d065812aa38ef74f35ba6bbdfac9
4
+ data.tar.gz: 1a7f7a8bca65cd7d9ed1478d5daceeb4e3592161
5
5
  SHA512:
6
- metadata.gz: 687c4d8be9ba1b200dcefd69707d04ad9f093949cfe77a69a6f33eede771e3eb980b2c708ceebf3835fd9995bddb55c6573f1e439919f8c3789804ea04eb810f
7
- data.tar.gz: 1e259f624db169f4034c08a650f44e485307179a107f989ca9eaae01e305de398231e73d3d0b45fd75d8b745dd8ea0f722eb70c30e4a1b1069a3b88a21e34ddd
6
+ metadata.gz: 47efa31c325c72faf7c36c26d485f3f49a366ee92c20d868255d314eba17a7d89e1df693a5a9755e23e79676facd7171c35115b5e29ee2eb6d13144ad0a288c6
7
+ data.tar.gz: 89fd4827b2f5b4d62f951707aeecdf2d49c4f64f9fc2a227d4af217ef03fd6f659e438bf1a9e2ac734476e236815559020fedf9b0bd6d345864d334f07463a94
@@ -1,3 +1,3 @@
1
1
  module Mock5
2
- VERSION = "1.0.7".freeze
2
+ VERSION = "1.0.8".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock5
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud
@@ -45,18 +45,10 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".gitignore"
49
- - ".travis.yml"
50
- - Gemfile
51
- - LICENSE.txt
52
48
  - README.md
53
- - Rakefile
54
49
  - lib/mock5.rb
55
50
  - lib/mock5/api.rb
56
51
  - lib/mock5/version.rb
57
- - mock5.gemspec
58
- - spec/mock5_api_spec.rb
59
- - spec/mock5_spec.rb
60
52
  homepage: https://github.com/rwz/mock5
61
53
  licenses:
62
54
  - MIT
@@ -81,6 +73,4 @@ rubygems_version: 2.4.6
81
73
  signing_key:
82
74
  specification_version: 4
83
75
  summary: Mock APIs using Sinatra
84
- test_files:
85
- - spec/mock5_api_spec.rb
86
- - spec/mock5_spec.rb
76
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .ruby-*
@@ -1,4 +0,0 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- - 2.1.2
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in mock5.gemspec
4
- gemspec
5
-
6
- gem "bundler", "~> 1.6"
7
- gem "rspec", "~> 3.1"
8
- gem "rake", "~> 10.3"
9
- gem "pry"
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Pavel Pravosud
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task default: :spec
@@ -1,20 +0,0 @@
1
- # coding: utf-8
2
- require_relative "lib/mock5/version"
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "mock5"
6
- spec.version = Mock5::VERSION
7
- spec.authors = ["Pavel Pravosud"]
8
- spec.email = ["pavel@pravosud.com"]
9
- spec.summary = "Mock APIs using Sinatra"
10
- spec.description = "Create and manage API mocks with Sinatra"
11
- spec.homepage = "https://github.com/rwz/mock5"
12
- spec.license = "MIT"
13
- spec.files = `git ls-files -z`.split("\x0")
14
- spec.test_files = spec.files.grep(/^spec/)
15
- spec.require_path = "lib"
16
- spec.required_ruby_version = ">= 1.9.3"
17
-
18
- spec.add_dependency "webmock", "~> 1.15"
19
- spec.add_dependency "sinatra", "~> 1.4"
20
- end
@@ -1,71 +0,0 @@
1
- require "mock5/api"
2
- require "rack/mock"
3
-
4
- describe Mock5::Api do
5
- describe "#endpoint" do
6
- it "matches all by default" do
7
- expect(subject.endpoint).to eq(/.*/)
8
- end
9
-
10
- it "can be specified as a regex" do
11
- api = described_class.new(/foo/)
12
- expect(api.endpoint).to eq(/foo/)
13
- end
14
-
15
- it "can be specified as a valid url without path" do
16
- api = described_class.new("http://example.com")
17
- expect(api.endpoint).to eq(%r(\Ahttp://example\.com/.*\z))
18
- end
19
-
20
- it "can not be specified as a valid url with path" do
21
- expect{ described_class.new("http://example.com/foo") }
22
- .to raise_error(ArgumentError, "Endpoint URL should not include path")
23
- end
24
-
25
- it "can not be specified as an invalid url string" do
26
- expect{ described_class.new("foo") }
27
- .to raise_error(ArgumentError, "Endpoint should be a valid URL")
28
- end
29
-
30
- it "can not be specified by anything else" do
31
- [false, :foo, 123].each do |invalid_endpoint|
32
- expect{ described_class.new(invalid_endpoint) }
33
- .to raise_error(ArgumentError, "Endpoint should be string or regexp")
34
- end
35
- end
36
- end
37
-
38
- describe "#app" do
39
- it "is a Class" do
40
- expect(subject.app).to be_kind_of(Class)
41
- end
42
-
43
- it "is a Sinatra Rack app" do
44
- expect(subject.app.superclass).to eq(Sinatra::Base)
45
- end
46
-
47
- describe "configuration" do
48
- subject do
49
- described_class.new do
50
- get "/hello/:what" do |what|
51
- "Hello, #{what.capitalize}"
52
- end
53
- end
54
- end
55
-
56
- let(:server){ Rack::Server.new(app: subject.app) }
57
- let(:mock_request){ Rack::MockRequest.new(server.app) }
58
-
59
- it "can be configures by a block" do
60
- response = mock_request.get("/hello/world")
61
- expect(response.body.to_s).to eq("Hello, World")
62
- end
63
- end
64
- end
65
-
66
- describe "#request_stub" do
67
- it "returns a request stub" do
68
- expect(subject.request_stub).to be_kind_of(WebMock::RequestStub)
69
- end
70
- end
71
- end
@@ -1,209 +0,0 @@
1
- require "mock5"
2
-
3
- describe Mock5 do
4
- describe ".mock" do
5
- it "creates an Api" do
6
- expect(described_class::Api).to receive(:new).with(/foo/).and_yield
7
- described_class.mock /foo/ do
8
- # mock definition goes here
9
- end
10
- end
11
-
12
- it "returns an Api" do
13
- expect(described_class.mock).to be_kind_of(described_class::Api)
14
- end
15
- end
16
-
17
- describe "API mgmt" do
18
- before do
19
- described_class.instance_exec do
20
- if instance_variable_defined?(:@_mounted_apis)
21
- remove_instance_variable :@_mounted_apis
22
- end
23
- end
24
- end
25
-
26
- let(:mounted_apis){ described_class.mounted_apis }
27
- let(:mounted_apis_qty){ mounted_apis.size }
28
- let(:api){ described_class.mock }
29
- let(:another_api){ described_class.mock }
30
-
31
- describe ".mount" do
32
- it "raises ArgumentError when passed an invalid argument" do
33
- action = ->{ described_class.mount nil }
34
- message = "expected an instance of Mock5::Api"
35
- expect(&action).to raise_error(ArgumentError, message)
36
- end
37
- it "mounts an api" do
38
- described_class.mount api
39
- expect(mounted_apis).to include(api)
40
- end
41
-
42
- it "mounts an api only once" do
43
- 10.times{ described_class.mount api }
44
- expect(mounted_apis_qty).to eq(1)
45
- end
46
-
47
- it "mounts several APIs at once" do
48
- described_class.mount api, another_api
49
- expect(mounted_apis).to include(api)
50
- expect(mounted_apis).to include(another_api)
51
- end
52
-
53
- it "returns the list of mounted apis" do
54
- expect(described_class.mount(api)).to eq([api].to_set)
55
- expect(described_class.mount(api, another_api)).to eq([another_api].to_set)
56
- end
57
- end
58
-
59
- describe ".unmount" do
60
- before{ described_class.mount api }
61
-
62
- it "unmounts mounted api" do
63
- described_class.unmount api
64
- expect(mounted_apis).to be_empty
65
- end
66
-
67
- it "unmounts api only once" do
68
- 10.times{ described_class.unmount api }
69
- expect(mounted_apis).to be_empty
70
- end
71
-
72
- it "unmounts several APIs at once" do
73
- described_class.mount another_api
74
- expect(mounted_apis_qty).to eq(2)
75
- described_class.unmount api, another_api
76
- expect(mounted_apis).to be_empty
77
- end
78
-
79
- it "only unmount specified api" do
80
- described_class.mount another_api
81
- described_class.unmount api
82
- expect(mounted_apis).to include(another_api)
83
- end
84
-
85
- it "returns the list of unmounted apis" do
86
- expect(described_class.unmount(another_api)).to be_empty
87
- expect(described_class.unmount(api, another_api)).to eq([api].to_set)
88
- end
89
- end
90
-
91
- describe ".unmount_all!" do
92
- before do
93
- 3.times{ described_class.mount described_class.mock }
94
- end
95
-
96
- it "unmounts all currently mounted apis" do
97
- expect(mounted_apis_qty).to eq(3)
98
- described_class.unmount_all!
99
- expect(mounted_apis).to be_empty
100
- end
101
-
102
- it "has .reset! alias" do
103
- expect(mounted_apis_qty).to eq(3)
104
- described_class.reset!
105
- expect(mounted_apis).to be_empty
106
- end
107
- end
108
-
109
- describe ".mounted?" do
110
- before{ described_class.mount api }
111
-
112
- it "returns true if api is currently mounted" do
113
- expect(described_class.mounted?(api)).to be_truthy
114
- end
115
-
116
- it "returns false if api is currently not mounted" do
117
- expect(described_class.mounted?(another_api)).to be_falsy
118
- end
119
-
120
- it "returns true only when ALL api are mounted" do
121
- action = ->{ described_class.mount another_api }
122
- result = ->{ described_class.mounted? api, another_api }
123
- expect(&action).to change(&result).from(false).to(true)
124
- end
125
- end
126
-
127
- describe ".with_mounted" do
128
- it "temporary mounts an API" do
129
- action = -> do
130
- described_class.with_mounted api do
131
- expect(mounted_apis).to include(api)
132
- end
133
- end
134
-
135
- expect(mounted_apis).to be_empty
136
- expect(&action).not_to change(mounted_apis, :empty?)
137
- end
138
-
139
- it "doesn't unmount api, that was mounted before" do
140
- described_class.mount api
141
-
142
- described_class.with_mounted api, another_api do
143
- expect(mounted_apis).to include(another_api)
144
- end
145
-
146
- expect(mounted_apis).to include(api)
147
- expect(mounted_apis).not_to include(another_api)
148
- end
149
- end
150
-
151
- describe "stubbing" do
152
- def get(url)
153
- Net::HTTP.get(URI(url))
154
- end
155
-
156
- def post(url, params={})
157
- Net::HTTP.post_form(URI(url), params).body
158
- end
159
-
160
- let(:api) do
161
- described_class.mock "http://example.com" do
162
- get "/index.html" do
163
- "index.html"
164
- end
165
-
166
- post "/submit/here" do
167
- "submit"
168
- end
169
- end
170
- end
171
-
172
- let(:another_api) do
173
- described_class.mock "http://example.com" do
174
- post "/foo/:foo" do
175
- params["foo"]
176
- end
177
-
178
- get "/bar/:bar" do
179
- params["bar"]
180
- end
181
- end
182
- end
183
-
184
- context "#mount" do
185
- before{ described_class.mount api, another_api }
186
-
187
- it "stubs remote apis" do
188
- expect(get("http://example.com/index.html?foo=bar")).to eq("index.html")
189
- expect(post("http://example.com/submit/here?foo=bar")).to eq("submit")
190
- expect(post("http://example.com/foo/bar?fizz=buzz")).to eq("bar")
191
- expect(get("http://example.com/bar/foo")).to eq("foo")
192
- end
193
- end
194
-
195
- context "#with_mounted" do
196
- around do |example|
197
- described_class.with_mounted api, another_api, &example
198
- end
199
-
200
- it "stubs remote apis" do
201
- expect(get("http://example.com/index.html?foo=bar")).to eq("index.html")
202
- expect(post("http://example.com/submit/here?foo=bar")).to eq("submit")
203
- expect(post("http://example.com/foo/bar?fizz=buzz")).to eq("bar")
204
- expect(get("http://example.com/bar/foo")).to eq("foo")
205
- end
206
- end
207
- end
208
- end
209
- end