rspec-mocks-call-through 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/rspec/mocks-call-through.rb +61 -0
- data/rspec-mocks-call-through.gemspec +60 -0
- data/spec/rspec/mocks-call-through_spec.rb +72 -0
- data/spec/spec_helper.rb +21 -0
- metadata +138 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "yard", "~> 0.6.0"
|
11
|
+
# gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2.2)
|
11
|
+
rcov (1.0.0)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
yard (0.6.8)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
jeweler (~> 1.6.4)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.3.0)
|
29
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Piotr Banasik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= rspec-mocks-call-through
|
2
|
+
|
3
|
+
Adds call-through support for rspec stubs
|
4
|
+
|
5
|
+
== Method Stubs with call-through
|
6
|
+
|
7
|
+
o.stub!(:foo).and_call_through
|
8
|
+
|
9
|
+
o.foo then does all the standard stub stuff, and also calls the original method
|
10
|
+
|
11
|
+
== Contributing to rspec-mocks-call-through
|
12
|
+
|
13
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
14
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
15
|
+
* Fork the project
|
16
|
+
* Start a feature/bugfix branch
|
17
|
+
* Commit and push until you are happy with your contribution
|
18
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
19
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
20
|
+
|
21
|
+
== Also see
|
22
|
+
|
23
|
+
* [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2012 Piotr Banasik. See LICENSE.txt for
|
28
|
+
further details.
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rspec-mocks-call-through"
|
18
|
+
gem.homepage = "http://github.com/piotrb/rspec-mocks-call-through"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Adds call-through support for rspec stubs}
|
21
|
+
gem.description = %Q{}
|
22
|
+
gem.email = "piotr.banasik@gmail.com"
|
23
|
+
gem.authors = ["Piotr Banasik"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Mocks
|
3
|
+
|
4
|
+
module Methods
|
5
|
+
def stub(sym_or_hash, opts={}, &block)
|
6
|
+
if Hash === sym_or_hash
|
7
|
+
sym_or_hash.each {|method, value| live_stub(method).and_return value }
|
8
|
+
else
|
9
|
+
__mock_proxy.add_live_stub(caller(1)[0], sym_or_hash.to_sym, opts, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
alias :stub! :stub
|
13
|
+
end
|
14
|
+
|
15
|
+
class Proxy
|
16
|
+
def add_live_stub(location, method_name, opts={}, &implementation)
|
17
|
+
method_double[method_name].add_live_stub @error_generator, @expectation_ordering, location, opts, &implementation
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MethodDouble
|
22
|
+
attr_reader :object
|
23
|
+
def add_live_stub(error_generator, expectation_ordering, expected_from, opts={}, &implementation)
|
24
|
+
configure_method
|
25
|
+
stub = LiveMessageExpectation.new(self, error_generator, expectation_ordering, expected_from, @method_name, nil, :any, opts, &implementation)
|
26
|
+
stubs.unshift stub
|
27
|
+
stub
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class LiveMessageExpectation < MessageExpectation
|
32
|
+
|
33
|
+
attr_reader :method_double
|
34
|
+
|
35
|
+
def initialize(method_double, *args, &block)
|
36
|
+
@method_double = method_double
|
37
|
+
super(*args, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def invoke_return_block(*args, &block)
|
41
|
+
block.taint if block
|
42
|
+
super(*args, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def and_call_through
|
46
|
+
and_return { |*args|
|
47
|
+
method_name = @method_double.obfuscate(@method_double.method_name)
|
48
|
+
object = @method_double.object
|
49
|
+
|
50
|
+
method = object.method(method_name)
|
51
|
+
|
52
|
+
block = args.pop if args.last.kind_of?(Proc) && args.last.tainted?
|
53
|
+
|
54
|
+
object.send(method_name, *args, &block)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rspec-mocks-call-through"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Piotr Banasik"]
|
12
|
+
s.date = "2012-01-22"
|
13
|
+
s.description = ""
|
14
|
+
s.email = "piotr.banasik@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/rspec/mocks-call-through.rb",
|
29
|
+
"rspec-mocks-call-through.gemspec",
|
30
|
+
"spec/rspec/mocks-call-through_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/piotrb/rspec-mocks-call-through"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.15"
|
37
|
+
s.summary = "Adds call-through support for rspec stubs"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
44
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
46
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
49
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
50
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
55
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
57
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RSpec::Mocks do
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
def self.status
|
7
|
+
@status
|
8
|
+
end
|
9
|
+
def self.reset!
|
10
|
+
@status = {}
|
11
|
+
end
|
12
|
+
def one
|
13
|
+
self.class.status[:one] ||= []
|
14
|
+
self.class.status[:one] << [[], nil]
|
15
|
+
end
|
16
|
+
def two(a,b,c)
|
17
|
+
self.class.status[:two] ||= []
|
18
|
+
self.class.status[:two] << [[a,b,c], nil]
|
19
|
+
end
|
20
|
+
def three(a,&block)
|
21
|
+
self.class.status[:three] ||= []
|
22
|
+
self.class.status[:three] << [[a],block]
|
23
|
+
end
|
24
|
+
def four(a,b)
|
25
|
+
self.class.status[:four] ||= []
|
26
|
+
self.class.status[:four] << [[a,b],nil]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
Foo.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
it "arity: 0" do
|
35
|
+
o = Foo.new
|
36
|
+
o.stub!(:one).and_call_through
|
37
|
+
o.one
|
38
|
+
Foo.status[:one].should == [
|
39
|
+
[[], nil]
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "arity: 3" do
|
44
|
+
o = Foo.new
|
45
|
+
o.stub!(:two).and_call_through
|
46
|
+
o.two(:a, 2, "c")
|
47
|
+
Foo.status[:two].should == [
|
48
|
+
[[:a, 2, "c"], nil]
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "arity: 1 + block" do
|
53
|
+
o = Foo.new
|
54
|
+
o.stub!(:three).and_call_through
|
55
|
+
block = proc { "block" }
|
56
|
+
o.three(:a, &block)
|
57
|
+
Foo.status[:three].should == [
|
58
|
+
[[:a], block]
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "arity: 2, last param is a proc" do
|
63
|
+
o = Foo.new
|
64
|
+
o.stub!(:four).and_call_through
|
65
|
+
block = proc { "block" }
|
66
|
+
o.four(:a, block)
|
67
|
+
Foo.status[:four].should == [
|
68
|
+
[[:a, block], nil]
|
69
|
+
]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'rspec/mocks'
|
3
|
+
require 'rspec/expectations'
|
4
|
+
require 'rspec/mocks-call-through'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.mock_with :rspec
|
8
|
+
config.color_enabled = true
|
9
|
+
config.include(RSpec::Mocks::Methods)
|
10
|
+
|
11
|
+
config.filter_run_excluding :ruby => lambda {|version|
|
12
|
+
case version.to_s
|
13
|
+
when "!jruby"
|
14
|
+
RUBY_ENGINE != "jruby"
|
15
|
+
when /^> (.*)/
|
16
|
+
!(RUBY_VERSION.to_s > $1)
|
17
|
+
else
|
18
|
+
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-mocks-call-through
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Piotr Banasik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: 2.3.0
|
32
|
+
name: rspec
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 7
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 6
|
46
|
+
- 0
|
47
|
+
version: 0.6.0
|
48
|
+
name: yard
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 7
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 6
|
62
|
+
- 4
|
63
|
+
version: 1.6.4
|
64
|
+
name: jeweler
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
name: rcov
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
requirement: *id004
|
82
|
+
description: ""
|
83
|
+
email: piotr.banasik@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- VERSION
|
100
|
+
- lib/rspec/mocks-call-through.rb
|
101
|
+
- rspec-mocks-call-through.gemspec
|
102
|
+
- spec/rspec/mocks-call-through_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: http://github.com/piotrb/rspec-mocks-call-through
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.15
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Adds call-through support for rspec stubs
|
137
|
+
test_files: []
|
138
|
+
|