mock5 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +5 -6
- data/README.md +1 -1
- data/lib/mock5.rb +8 -2
- data/lib/mock5/version.rb +1 -1
- data/spec/mock5_api_spec.rb +1 -1
- data/spec/mock5_spec.rb +17 -10
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f46073471999d56560318ffd53aae8d68b24af17
|
4
|
+
data.tar.gz: 9cc7ed0b830b9a56ad02f465cd1c4402b74bd3f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdef01f636598d823789ed147073b681ff4b6facdb8f836a3126674258496ae4815ef2eb550362e957a6743f9897aa57c11df2457e928066fb2da8d26c618c04
|
7
|
+
data.tar.gz: fc34feb90c6933d86ff0b7f82a1db399b53bd412d5d13954115c00b15672d6db1db36c974ca3bc0b4f33ef90692582a4ec5c21a67f338f1f84e0d158a2eb97b7
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in mock5.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem "bundler", "~> 1.
|
7
|
-
gem "rspec", "~>
|
8
|
-
gem "rake", "~> 10.
|
9
|
-
|
10
|
-
gem "pry-debugger"
|
6
|
+
gem "bundler", "~> 1.6"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
gem "rake", "~> 10.3"
|
9
|
+
gem "pry"
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![Gem Version](https://img.shields.io/gem/v/mock5.svg)](https://rubygems.org/gems/mock5)
|
3
3
|
[![Build Status](https://img.shields.io/travis/rwz/mock5.svg)](http://travis-ci.org/rwz/mock5)
|
4
4
|
[![Code Climate](https://img.shields.io/codeclimate/github/rwz/mock5.svg)](https://codeclimate.com/github/rwz/mock5)
|
5
|
-
[![Inline docs](http://inch-
|
5
|
+
[![Inline docs](http://inch-ci.org/github/rwz/mock5.svg)](http://inch-ci.org/github/rwz/mock5)
|
6
6
|
|
7
7
|
Mock5 allows to mock external APIs with simple Sinatra Rack apps.
|
8
8
|
|
data/lib/mock5.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "mock5/version"
|
2
|
-
require "mock5/api"
|
3
1
|
require "set"
|
4
2
|
|
5
3
|
# The main module of the gem, exposing all API management methods.
|
@@ -7,6 +5,9 @@ require "set"
|
|
7
5
|
module Mock5
|
8
6
|
extend self
|
9
7
|
|
8
|
+
autoload :VERSION, "mock5/version"
|
9
|
+
autoload :Api, "mock5/api"
|
10
|
+
|
10
11
|
# Returns a set of currently mounted APIs
|
11
12
|
#
|
12
13
|
# @return [Set] a list of currently mounted APIs
|
@@ -49,6 +50,7 @@ module Mock5
|
|
49
50
|
# @return [Set] a list of APIs actually mounted
|
50
51
|
def mount(*apis)
|
51
52
|
apis.to_set.subtract(mounted_apis).each do |api|
|
53
|
+
check_api api
|
52
54
|
mounted_apis.add api
|
53
55
|
registry.register_request_stub api.request_stub
|
54
56
|
end
|
@@ -125,4 +127,8 @@ module Mock5
|
|
125
127
|
def registry
|
126
128
|
WebMock::StubRegistry.instance
|
127
129
|
end
|
130
|
+
|
131
|
+
def check_api(api)
|
132
|
+
fail ArgumentError, "expected an instance of Mock5::Api" unless Api === api
|
133
|
+
end
|
128
134
|
end
|
data/lib/mock5/version.rb
CHANGED
data/spec/mock5_api_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Mock5::Api do
|
|
22
22
|
.to raise_error(ArgumentError, "Endpoint URL should not include path")
|
23
23
|
end
|
24
24
|
|
25
|
-
it "can not be specified as
|
25
|
+
it "can not be specified as an invalid url string" do
|
26
26
|
expect{ described_class.new("foo") }
|
27
27
|
.to raise_error(ArgumentError, "Endpoint should be a valid URL")
|
28
28
|
end
|
data/spec/mock5_spec.rb
CHANGED
@@ -3,9 +3,10 @@ require "mock5"
|
|
3
3
|
describe Mock5 do
|
4
4
|
describe ".mock" do
|
5
5
|
it "creates an Api" do
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
9
10
|
end
|
10
11
|
|
11
12
|
it "returns an Api" do
|
@@ -18,16 +19,22 @@ describe Mock5 do
|
|
18
19
|
WebMock::StubRegistry.instance.reset!
|
19
20
|
described_class.instance_exec do
|
20
21
|
if instance_variable_defined?(:@_mounted_apis)
|
21
|
-
remove_instance_variable
|
22
|
+
remove_instance_variable :@_mounted_apis
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
let(:mounted_apis){ described_class.mounted_apis }
|
28
|
+
let(:mounted_apis_qty){ mounted_apis.size }
|
27
29
|
let(:api){ described_class.mock }
|
28
30
|
let(:another_api){ described_class.mock }
|
29
31
|
|
30
32
|
describe ".mount" do
|
33
|
+
it "raises ArgumentError when passed an invalid argument" do
|
34
|
+
action = ->{ described_class.mount nil }
|
35
|
+
message = "expected an instance of Mock5::Api"
|
36
|
+
expect(&action).to raise_error(ArgumentError, message)
|
37
|
+
end
|
31
38
|
it "mounts an api" do
|
32
39
|
described_class.mount api
|
33
40
|
expect(mounted_apis).to include(api)
|
@@ -35,7 +42,7 @@ describe Mock5 do
|
|
35
42
|
|
36
43
|
it "mounts an api only once" do
|
37
44
|
10.times{ described_class.mount api }
|
38
|
-
expect(
|
45
|
+
expect(mounted_apis_qty).to eq(1)
|
39
46
|
end
|
40
47
|
|
41
48
|
it "mounts several APIs at once" do
|
@@ -65,7 +72,7 @@ describe Mock5 do
|
|
65
72
|
|
66
73
|
it "unmounts several APIs at once" do
|
67
74
|
described_class.mount another_api
|
68
|
-
expect(
|
75
|
+
expect(mounted_apis_qty).to eq(2)
|
69
76
|
described_class.unmount api, another_api
|
70
77
|
expect(mounted_apis).to be_empty
|
71
78
|
end
|
@@ -88,13 +95,13 @@ describe Mock5 do
|
|
88
95
|
end
|
89
96
|
|
90
97
|
it "unmounts all currently mounted apis" do
|
91
|
-
expect(
|
98
|
+
expect(mounted_apis_qty).to eq(3)
|
92
99
|
described_class.unmount_all!
|
93
100
|
expect(mounted_apis).to be_empty
|
94
101
|
end
|
95
102
|
|
96
103
|
it "has .reset! alias" do
|
97
|
-
expect(
|
104
|
+
expect(mounted_apis_qty).to eq(3)
|
98
105
|
described_class.reset!
|
99
106
|
expect(mounted_apis).to be_empty
|
100
107
|
end
|
@@ -104,11 +111,11 @@ describe Mock5 do
|
|
104
111
|
before{ described_class.mount api }
|
105
112
|
|
106
113
|
it "returns true if api is currently mounted" do
|
107
|
-
expect(described_class.mounted?(api)).to
|
114
|
+
expect(described_class.mounted?(api)).to be_truthy
|
108
115
|
end
|
109
116
|
|
110
117
|
it "returns false if api is currently not mounted" do
|
111
|
-
expect(described_class.mounted?(another_api)).to
|
118
|
+
expect(described_class.mounted?(another_api)).to be_falsy
|
112
119
|
end
|
113
120
|
|
114
121
|
it "returns true only when ALL api are mounted" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webmock
|
@@ -84,4 +84,3 @@ summary: Mock APIs using Sinatra
|
|
84
84
|
test_files:
|
85
85
|
- spec/mock5_api_spec.rb
|
86
86
|
- spec/mock5_spec.rb
|
87
|
-
has_rdoc:
|