expects_chain 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,15 @@ module ExpectsChain
|
|
11
11
|
value
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.mocker
|
15
|
+
if @_mocker.nil?
|
16
|
+
framework = RSpec.configuration.mock_framework.framework_name.to_s.capitalize.to_sym
|
17
|
+
raise StandardError.new("expects_chain unsupported framework: #{framework}") unless Mockers.constants.include?(framework)
|
18
|
+
@_mocker = Mockers::const_get(framework)
|
19
|
+
end
|
20
|
+
@_mocker
|
21
|
+
end
|
22
|
+
|
14
23
|
private
|
15
24
|
|
16
25
|
def set_up_call_chain value
|
@@ -24,20 +33,17 @@ module ExpectsChain
|
|
24
33
|
end
|
25
34
|
|
26
35
|
def set_expectation obj, method, ret
|
36
|
+
type = (@type == :mock ? :expects : :stubs)
|
37
|
+
rtype = :returns
|
27
38
|
if method.kind_of?(Array) && method.first.kind_of?(Symbol)
|
28
|
-
mocker.send(
|
39
|
+
mocker.new(obj).send(type, method.shift).with(method).send(rtype, ret)
|
29
40
|
else
|
30
|
-
mocker.send(
|
41
|
+
mocker.new(obj).send(type, method).send(rtype, ret)
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
45
|
def mocker
|
35
|
-
|
36
|
-
framework = RSpec.configuration.mock_framework.framework_name.to_s.capitalize.to_sym
|
37
|
-
raise StandardError.new("expects_chain unsupported framework: #{framework}") unless Mockers.constants.include?(framework)
|
38
|
-
@_mocker = Mockers::const_get(framework)
|
39
|
-
end
|
40
|
-
@_mocker
|
46
|
+
self.class.mocker
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module ExpectsChain
|
2
2
|
module Mockers
|
3
|
-
|
4
|
-
def
|
5
|
-
|
3
|
+
class Mocha < Base
|
4
|
+
def expects method
|
5
|
+
@object = @object.expects(method).at_least_once
|
6
|
+
self
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def stubs method
|
10
|
+
@object = @object.stubs(method)
|
11
|
+
self
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.stub_object_with_arguments obj, method, attrs, ret
|
17
|
-
obj.stubs(method).with(*attrs).at_least_once.returns(ret)
|
14
|
+
def returns ret
|
15
|
+
@object = @object.returns(ret)
|
18
16
|
end
|
19
17
|
|
20
18
|
def self.mock
|
@@ -1,20 +1,18 @@
|
|
1
1
|
module ExpectsChain
|
2
2
|
module Mockers
|
3
|
-
|
4
|
-
def
|
5
|
-
|
3
|
+
class Rspec < Base
|
4
|
+
def expects method
|
5
|
+
@object = @object.should_receive(method)
|
6
|
+
self
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def stubs method
|
10
|
+
@object = @object.stub(method)
|
11
|
+
self
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.stub_object_with_arguments obj, method, attrs, ret
|
17
|
-
obj.stub!(method).with(*attrs).and_return(ret)
|
14
|
+
def returns ret
|
15
|
+
@object = @object.and_return(ret)
|
18
16
|
end
|
19
17
|
|
20
18
|
def self.mock
|
data/lib/expects_chain.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expects_chain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: RSpec extension that allows you to set chained expectations on objects.
|
15
15
|
Currently supports rspec & mocha
|
@@ -18,10 +18,11 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- lib/expects_chain.rb
|
22
|
-
- lib/expects_chain/expectation.rb
|
23
|
-
- lib/expects_chain/mockers/mocha.rb
|
21
|
+
- lib/expects_chain/mockers/base.rb
|
24
22
|
- lib/expects_chain/mockers/rspec.rb
|
23
|
+
- lib/expects_chain/mockers/mocha.rb
|
24
|
+
- lib/expects_chain/expectation.rb
|
25
|
+
- lib/expects_chain.rb
|
25
26
|
homepage: http://github.com/pewniak747/expects_chain
|
26
27
|
licenses: []
|
27
28
|
post_install_message:
|