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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e3ff7dc93593a4f21dd450ed0874f436d1493c9
4
- data.tar.gz: 1599500a3e285e92e7931b4e24ce5790d0f6bc25
3
+ metadata.gz: f46073471999d56560318ffd53aae8d68b24af17
4
+ data.tar.gz: 9cc7ed0b830b9a56ad02f465cd1c4402b74bd3f3
5
5
  SHA512:
6
- metadata.gz: 6e93dd71cc6c4b953de995bd642764b17298a0e24c16ea2ede62d7c56dc0f70c71ad3397d9c456c43384f74f5c0f4b5dff1c1268d7a67a85026360a3f55b0005
7
- data.tar.gz: 961aa86904f8e5f6fd54007202f4f107f4301174e01a864c9d72d94e180d0c931042b068b9cd21012148daafc98972cef47bfc126a0306120ab480f97eb9b884
6
+ metadata.gz: cdef01f636598d823789ed147073b681ff4b6facdb8f836a3126674258496ae4815ef2eb550362e957a6743f9897aa57c11df2457e928066fb2da8d26c618c04
7
+ data.tar.gz: fc34feb90c6933d86ff0b7f82a1db399b53bd412d5d13954115c00b15672d6db1db36c974ca3bc0b4f33ef90692582a4ec5c21a67f338f1f84e0d158a2eb97b7
@@ -1,4 +1,4 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.1
4
+ - 2.1.2
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
- source 'https://rubygems.org'
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.5"
7
- gem "rspec", "~> 2.14"
8
- gem "rake", "~> 10.1"
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-pages.github.io/github/rwz/mock5.svg)](http://inch-pages.github.io/github/rwz/mock5)
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mock5
2
- VERSION = "1.0.5".freeze
2
+ VERSION = "1.0.6".freeze
3
3
  end
@@ -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 a invalid url string" do
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
@@ -3,9 +3,10 @@ require "mock5"
3
3
  describe Mock5 do
4
4
  describe ".mock" do
5
5
  it "creates an Api" do
6
- block = ->{}
7
- expect(described_class::Api).to receive(:new).with(/foo/, &block)
8
- described_class.mock /foo/, &block
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(:@_mounted_apis)
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(mounted_apis).to have(1).item
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(mounted_apis).to have(2).apis
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(mounted_apis).to have(3).apis
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(mounted_apis).to have(3).apis
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 be_true
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 be_false
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.5
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-03-29 00:00:00.000000000 Z
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: