rspecproxies 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20e5e79a339c7c8ef8b996aa4ce57b02b093b566
4
+ data.tar.gz: 60228d6d6d959779e292a86e0094d65feebdb408
5
+ SHA512:
6
+ metadata.gz: fde4298b0e9d55e12bbea57cec20e2dd9a0f64acc6a0574c2b9ab0197f34ac05fa805bdb41b0509eab6cd2f0df961b2e65b532101e30cd2ec90a448c8f256e1c
7
+ data.tar.gz: c6d64df427d70ed32067f63ddb749e1cba22a0340df33769362e8b5f3d4c02e2644c0ea3caf3640e75a529dffece2e467169df6493e29e5c522711b747ed0604
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .ruby-version
6
+ Gemfile.lock
7
+ coverage
8
+ InstalledFiles
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ vendor
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
21
+ doc/
22
+
23
+ # emacs files
24
+ *~
25
+ *#
26
+ .#*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspecproxies.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Philou
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/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rspecproxies
2
+
3
+ Special RSpec extensions to simplify mocking by providing proxies
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rspecproxies'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rspecproxies
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "rspecproxies/version"
4
+ require "rspecproxies/proxies"
@@ -0,0 +1,71 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ class Object
4
+
5
+ # Will call the given block with it's result every time the method
6
+ # returns
7
+ def on_result_from(method_name)
8
+ stock_response = self.original_response(method_name)
9
+
10
+ self.stub(method_name) do |*args, &block|
11
+ result = stock_response.call(*args, &block)
12
+ yield result
13
+ result
14
+ end
15
+ end
16
+
17
+ # Will capture all the results of the method into the returned
18
+ # array
19
+ def capture_results_from(method_name)
20
+ all_results = []
21
+ on_result_from(method_name) {|result| all_results << result }
22
+ all_results
23
+ end
24
+
25
+ # Will capture (or override) result from the target's method in
26
+ # the details[:into] instance variable
27
+ def capture_result_from(target, method_name, details)
28
+ into = details[:into]
29
+ target.on_result_from(method_name) {|result| instance_variable_set("@#{into}", result)}
30
+ end
31
+
32
+ # Will call the given block with all the actual arguments every time
33
+ # the method is called
34
+ def on_call_to(method_name)
35
+ stock_response = self.original_response(method_name)
36
+
37
+ self.stub(method_name) do |*args, &block|
38
+ yield *args
39
+ stock_response.call(*args, &block)
40
+ end
41
+
42
+ end
43
+
44
+ # Sets up proxies all down the selector chain, until the last where
45
+ # a simple method stub is created and on which the block is called.
46
+ # Allows to set up stub chains quickly and safely.
47
+ def proxy_chain(*selectors, &block)
48
+ if selectors.count == 1
49
+ final_stub = self.stub(selectors.first)
50
+ block.call(final_stub) unless block.nil?
51
+ else
52
+ self.on_result_from(selectors.first) do |result|
53
+ result.proxy_chain(*selectors[1..-1], &block)
54
+ end
55
+ end
56
+ end
57
+
58
+ protected
59
+
60
+ # Lambda that calls the original implementation of a method
61
+ def original_response(method_name)
62
+ if self.methods.include?(method_name)
63
+ self.method(method_name)
64
+ else
65
+ lambda do |*args, &block|
66
+ self.send(:method_missing, method_name, *args, &block)
67
+ end
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module RSpecProxies
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspecproxies/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspecproxies"
8
+ spec.version = RSpecProxies::VERSION
9
+ spec.authors = ["Philou"]
10
+ spec.email = ["philippe.bourgau@gmail.com"]
11
+ spec.description = %q{Proxy doubles for RSpec}
12
+ spec.summary = %q{Special RSpec extensions to simplify mocking by providing proxies}
13
+ spec.homepage = "https://github.com/philou/rspecproxies"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rspec"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspecproxies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Philou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDkjCCAnqgAwIBAgIBATANBgkqhkiG9w0BAQUFADBHMRkwFwYDVQQDDBBwaGls
14
+ aXBwZS5ib3VyZ2F1MRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/Is
15
+ ZAEZFgNjb20wHhcNMTMwOTIzMTEwOTA3WhcNMTQwOTIzMTEwOTA3WjBHMRkwFwYD
16
+ VQQDDBBwaGlsaXBwZS5ib3VyZ2F1MRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzAR
17
+ BgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
18
+ AQC8CpoqZwEbzXr55EUxdSplgn0MYZ9xPGO/XmRa8bD63n+JYWF0AS+mj452ZY18
19
+ rwM+yKrKhtsA+aJJdlOafgIUnY5SrZOr7v7kgc6T2YNoUj+M00Um2jv+shQbOtV6
20
+ qGp0Jw1HfPNUMVa+3pXZyAGCecN6rTnsZJIuW6KNaJUq6lEMVXanoTHgAKrH5aHd
21
+ Y6ofwQL86d6LDkC1S4p86iMUWvF34w8h5ItVo+JKlPRR22rzsK/ZKgNH3lfjbS6i
22
+ JWqPva70rL2xz5kCVn6DL7XhNZtqnAO4kvCQyQeWezvcoGXEnbHacKky7B+/WKec
23
+ OIWEwedl6j+X0OD5OYki3QaTAgMBAAGjgYgwgYUwCQYDVR0TBAIwADALBgNVHQ8E
24
+ BAMCBLAwHQYDVR0OBBYEFJnLz40Onu/dfpLSipU5FgTy6WLmMCUGA1UdEQQeMByB
25
+ GnBoaWxpcHBlLmJvdXJnYXVAZ21haWwuY29tMCUGA1UdEgQeMByBGnBoaWxpcHBl
26
+ LmJvdXJnYXVAZ21haWwuY29tMA0GCSqGSIb3DQEBBQUAA4IBAQBGoH72KWYACGZl
27
+ cMHMJ9d/DRU7rynJ8c4xuuM4c3Ri8bGPqI/a1BAp4QPJApS4+ANXXJ220hslrekP
28
+ 9/ExEKFiqiywh1clih9ttuN4cHqJzCP6QHqJznQrvaYToZLxGARDf3Mwz4mFSh4W
29
+ snSep53DZ1vrY2Gzmig/4PuBF4q3nhwPgxV6H3SH4/Py7QF5COZPQlCdBwPYczqW
30
+ XxIbXhRVXcgjBHT0w2HsXkOwmmYvBzbrfqtTx5NswwHcIeQZB/NID7berIf9awx3
31
+ yLcl1cmm5ALtJ/+Bkkmp0i4amXeTDMvq9r8PBsVsQwxYOYJBP+Umxz3PX6HjFHrQ
32
+ XdkXx3oZ
33
+ -----END CERTIFICATE-----
34
+ date: 2014-05-19 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ - !ruby/object:Gem::Dependency
51
+ name: bundler
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: rake
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Proxy doubles for RSpec
79
+ email:
80
+ - philippe.bourgau@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/rspecproxies.rb
91
+ - lib/rspecproxies/proxies.rb
92
+ - lib/rspecproxies/version.rb
93
+ - rspecproxies.gemspec
94
+ homepage: https://github.com/philou/rspecproxies
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Special RSpec extensions to simplify mocking by providing proxies
118
+ test_files: []
metadata.gz.sig ADDED
Binary file