expects_chain 0.1.1 → 0.2.0
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.
@@ -7,10 +7,17 @@ module ExpectsChain
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def returns value
|
10
|
+
@rtype = :returns
|
10
11
|
set_up_call_chain value
|
11
12
|
value
|
12
13
|
end
|
13
14
|
|
15
|
+
def raises exception
|
16
|
+
@rtype = :raises
|
17
|
+
set_up_call_chain exception
|
18
|
+
exception
|
19
|
+
end
|
20
|
+
|
14
21
|
def self.mocker
|
15
22
|
if @_mocker.nil?
|
16
23
|
framework = RSpec.configuration.mock_framework.framework_name.to_s.capitalize.to_sym
|
@@ -25,21 +32,21 @@ module ExpectsChain
|
|
25
32
|
def set_up_call_chain value
|
26
33
|
current_mock = value
|
27
34
|
first_expectation = @expectations.shift
|
28
|
-
@expectations.reverse.
|
35
|
+
@expectations.reverse.each_with_index do |expectation, idx|
|
29
36
|
old_mock, current_mock = current_mock, mocker.send(@type)
|
30
|
-
set_expectation(current_mock, expectation, old_mock)
|
37
|
+
set_expectation(current_mock, expectation, old_mock, idx == 0)
|
31
38
|
end
|
32
39
|
set_expectation(@object, first_expectation, current_mock)
|
33
40
|
end
|
34
41
|
|
35
|
-
def set_expectation obj, method, ret
|
36
|
-
type = (@type == :mock ? :expects : :stubs)
|
37
|
-
|
42
|
+
def set_expectation obj, method, ret, last = false
|
43
|
+
type, rtype = (@type == :mock ? :expects : :stubs), @rtype
|
44
|
+
new_mock = mocker.new(obj)
|
38
45
|
if method.kind_of?(Array) && method.first.kind_of?(Symbol)
|
39
|
-
|
40
|
-
else
|
41
|
-
mocker.new(obj).send(type, method).send(rtype, ret)
|
46
|
+
new_mock.send(type, method.shift).with(method)
|
47
|
+
else new_mock.send(type, method)
|
42
48
|
end
|
49
|
+
new_mock.send(last ? rtype : :returns, ret)
|
43
50
|
end
|
44
51
|
|
45
52
|
def mocker
|