rspecproxies 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Guardfile +9 -0
- data/README.md +66 -3
- data/Rakefile +6 -0
- data/lib/rspecproxies/version.rb +1 -1
- data/rspecproxies.gemspec +2 -0
- data/spec/rspecproxies/proxies_spec.rb +96 -0
- data/spec/spec_helper.rb +3 -0
- data.tar.gz.sig +0 -0
- metadata +38 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 653a8207a9d33581245cf8d80ad0da672a1c7b1b
|
4
|
+
data.tar.gz: 34c8feeb474c18603ce170ac64f1474a7783f8f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afcc35da544a16f6361efae3853b9f5f13930b41112ebf3938824bf3bda64fe28f1be1e9d2bcdd9e3b95a36d6b081f1e6674d67a85460d231f682d8233aa4b88
|
7
|
+
data.tar.gz: f412b271caa87b567f928ebd725947f47829b597848d2301b299c7bb4975f40925aa2980fa95a221b7dabb50197d2b0381fc30263b415c511b5b6d4528b9a743
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# RSpecProxies
|
2
2
|
|
3
|
-
Special RSpec extensions to simplify mocking by providing proxies
|
3
|
+
Special RSpec extensions to simplify mocking by providing proxies.
|
4
|
+
|
5
|
+
Here are the goals of mock proxies :
|
6
|
+
|
7
|
+
* simplify mock setup
|
8
|
+
* minimize method calls verifications
|
9
|
+
* capture return values and calls
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -18,7 +24,64 @@ Or install it yourself as:
|
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
Just as inspiration, here are a few sample usages :
|
28
|
+
|
29
|
+
### Verify caching with capture_results_from
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
it 'caches users' do
|
33
|
+
users = User.capture_results_from(:load)
|
34
|
+
|
35
|
+
controller.login('joe', 'secret')
|
36
|
+
controller.login('joe', 'secret')
|
37
|
+
|
38
|
+
expect(users).to have_exactly(2).items
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
### Verify loaded data with capture_result_from
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
it 'loads the actual user' do
|
46
|
+
capture_result_from(User, :load, into: :user)
|
47
|
+
|
48
|
+
controller.login('joe', 'secret')
|
49
|
+
|
50
|
+
expect(response).to redirect_to(@user.homepage)
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Simulate unreliable network with on_call_to
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
it 'retries on error' do
|
58
|
+
i = 0
|
59
|
+
Resource.on_call_to(:get) do |*args|
|
60
|
+
i++
|
61
|
+
raise RuntimeError.new if i % 3==0
|
62
|
+
end
|
63
|
+
|
64
|
+
resources = Resource.get_at_least(10)
|
65
|
+
|
66
|
+
expect(resources).to have_exactly(9).items
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
### Setup deep stubs with proxy_chain
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
it 'rounds the completion ratio' do
|
74
|
+
RenderingTask.proxy_chain(:load, :completion_ratio) {|s| s.and_return(0.2523) }
|
75
|
+
|
76
|
+
renderingController.show
|
77
|
+
|
78
|
+
expect(response).to include('25%')
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
### Get best of both worlds with in memory databases
|
83
|
+
|
84
|
+
Combine proxies with an inmemory database (like SQLite) while testing, and you'll get clear, straightforward and fast tests !
|
22
85
|
|
23
86
|
## Contributing
|
24
87
|
|
data/Rakefile
CHANGED
data/lib/rspecproxies/version.rb
CHANGED
data/rspecproxies.gemspec
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module RSpecProxies
|
6
|
+
|
7
|
+
class User
|
8
|
+
def self.load(name)
|
9
|
+
User.new(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
def url
|
18
|
+
case name
|
19
|
+
when 'Joe'
|
20
|
+
'http://www.greatjoe.net'
|
21
|
+
when 'Jim'
|
22
|
+
'http://www.bigjim.net'
|
23
|
+
when 'Joe'
|
24
|
+
"http://www.#{name}.net"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(o)
|
29
|
+
o.class == self.class && o.name == self.name
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class ProfileController
|
35
|
+
|
36
|
+
def render(name)
|
37
|
+
view_for(User.load(name))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def view_for(user)
|
43
|
+
"<html><body><a href='#{user.url}'>#{user.name}</a></body></html>"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'proxies' do
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
@controller = ProfileController.new
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'hooks on return from a method' do
|
54
|
+
user = nil
|
55
|
+
User.on_result_from(:load) {|u| user = u}
|
56
|
+
|
57
|
+
@controller.render('Joe')
|
58
|
+
|
59
|
+
expect(user).to eq(User.new('Joe'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has a shortcut to collect return values from a method' do
|
63
|
+
users = User.capture_results_from(:load)
|
64
|
+
|
65
|
+
@controller.render('Joe')
|
66
|
+
@controller.render('Jim')
|
67
|
+
|
68
|
+
expect(users).to eq([User.new('Joe'), User.new('Jim')])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'has a shortcut to collect the latest return value from a method' do
|
72
|
+
capture_result_from(User, :load, into: :user)
|
73
|
+
|
74
|
+
html = @controller.render('Joe')
|
75
|
+
|
76
|
+
expect(html).to include(@user.url)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'hooks on arguments before a method call' do
|
80
|
+
User.on_call_to(:load) do |name|
|
81
|
+
raise RuntimeError.new if name == 'Jim'
|
82
|
+
end
|
83
|
+
|
84
|
+
expect(@controller.render('Joe')).not_to be_nil
|
85
|
+
expect{@controller.render('Jim')}.to raise_error(RuntimeError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can setup deep stubs on yet unloaded instances" do
|
89
|
+
User.proxy_chain(:load, :url) {|s| s.and_return('http://pirates.net')}
|
90
|
+
|
91
|
+
html = @controller.render('Jack')
|
92
|
+
|
93
|
+
expect(html).to include('http://pirates.net')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspecproxies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philou
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
yLcl1cmm5ALtJ/+Bkkmp0i4amXeTDMvq9r8PBsVsQwxYOYJBP+Umxz3PX6HjFHrQ
|
32
32
|
XdkXx3oZ
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-05-
|
34
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
@@ -75,6 +75,34 @@ dependencies:
|
|
75
75
|
- - '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: guard-rspec
|
94
|
+
requirement: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
78
106
|
description: Proxy doubles for RSpec
|
79
107
|
email:
|
80
108
|
- philippe.bourgau@gmail.com
|
@@ -83,7 +111,10 @@ extensions: []
|
|
83
111
|
extra_rdoc_files: []
|
84
112
|
files:
|
85
113
|
- .gitignore
|
114
|
+
- .rspec
|
115
|
+
- .travis.yml
|
86
116
|
- Gemfile
|
117
|
+
- Guardfile
|
87
118
|
- LICENSE.txt
|
88
119
|
- README.md
|
89
120
|
- Rakefile
|
@@ -91,6 +122,8 @@ files:
|
|
91
122
|
- lib/rspecproxies/proxies.rb
|
92
123
|
- lib/rspecproxies/version.rb
|
93
124
|
- rspecproxies.gemspec
|
125
|
+
- spec/rspecproxies/proxies_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
94
127
|
homepage: https://github.com/philou/rspecproxies
|
95
128
|
licenses:
|
96
129
|
- MIT
|
@@ -115,4 +148,6 @@ rubygems_version: 2.0.3
|
|
115
148
|
signing_key:
|
116
149
|
specification_version: 4
|
117
150
|
summary: Special RSpec extensions to simplify mocking by providing proxies
|
118
|
-
test_files:
|
151
|
+
test_files:
|
152
|
+
- spec/rspecproxies/proxies_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|