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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20e5e79a339c7c8ef8b996aa4ce57b02b093b566
4
- data.tar.gz: 60228d6d6d959779e292a86e0094d65feebdb408
3
+ metadata.gz: 653a8207a9d33581245cf8d80ad0da672a1c7b1b
4
+ data.tar.gz: 34c8feeb474c18603ce170ac64f1474a7783f8f7
5
5
  SHA512:
6
- metadata.gz: fde4298b0e9d55e12bbea57cec20e2dd9a0f64acc6a0574c2b9ab0197f34ac05fa805bdb41b0509eab6cd2f0df961b2e65b532101e30cd2ec90a448c8f256e1c
7
- data.tar.gz: c6d64df427d70ed32067f63ddb749e1cba22a0340df33769362e8b5f3d4c02e2644c0ea3caf3640e75a529dffece2e467169df6493e29e5c522711b747ed0604
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
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ script: bundle exec rake
6
+
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
- # Rspecproxies
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
- TODO: Write usage instructions here
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
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Run specs'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module RSpecProxies
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/rspecproxies.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "guard-rspec"
25
27
  end
@@ -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
@@ -0,0 +1,3 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rspecproxies'
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.1
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-19 00:00:00.000000000 Z
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