verified_double 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +5 -0
- data/features/CHANGELOG.markdown +5 -0
- data/lib/verified_double.rb +7 -1
- data/lib/verified_double/can_record_interactions.rb +5 -1
- data/lib/verified_double/is_a_class_double.rb +8 -0
- data/lib/verified_double/is_an_instance_double.rb +8 -0
- data/lib/verified_double/method_signature/value.rb +1 -1
- data/lib/verified_double/rspec_mocks_syntax_overrides.rb +2 -2
- data/lib/verified_double/simple_double.rb +1 -1
- data/lib/verified_double/version.rb +1 -1
- data/spec/verified_double/method_signature/value_spec.rb +17 -1
- data/spec/verified_double/simple_double_spec.rb +2 -2
- metadata +4 -2
data/CHANGELOG.markdown
CHANGED
data/features/CHANGELOG.markdown
CHANGED
data/lib/verified_double.rb
CHANGED
@@ -3,6 +3,8 @@ require 'rspec/mocks'
|
|
3
3
|
|
4
4
|
require 'verified_double/boolean'
|
5
5
|
require 'verified_double/can_record_interactions'
|
6
|
+
require 'verified_double/is_a_class_double'
|
7
|
+
require 'verified_double/is_an_instance_double'
|
6
8
|
require 'verified_double/matchers'
|
7
9
|
require 'verified_double/method_signature'
|
8
10
|
require 'verified_double/method_signature/value'
|
@@ -23,11 +25,15 @@ module VerifiedDouble
|
|
23
25
|
|
24
26
|
def self.of_class(class_name, options = {})
|
25
27
|
options[:transfer_nested_constants] = true if options[:transfer_nested_constants].nil?
|
26
|
-
|
28
|
+
d = stub_const(class_name, Class.new, options)
|
29
|
+
d.extend(VerifiedDouble::IsAClassDouble)
|
30
|
+
VerifiedDouble.record(d)
|
27
31
|
end
|
28
32
|
|
29
33
|
def self.of_instance(*args)
|
30
34
|
d = double(*args)
|
35
|
+
d.extend(VerifiedDouble::IsAnInstanceDouble)
|
36
|
+
|
31
37
|
simple_double = SimpleDouble.new(d)
|
32
38
|
|
33
39
|
if args[1]
|
@@ -5,6 +5,10 @@ module VerifiedDouble
|
|
5
5
|
super(*return_values)
|
6
6
|
end
|
7
7
|
|
8
|
+
def can_record_interactions?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
8
12
|
def should_receive(*args)
|
9
13
|
VerifiedDouble.registry.add_method_signature(self, args[0])
|
10
14
|
super(*args).tap {|result| result.extend(VerifiedDouble::CanRecordInteractions) }
|
@@ -21,4 +25,4 @@ module VerifiedDouble
|
|
21
25
|
super(*args)
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
@@ -6,7 +6,7 @@ module VerifiedDouble
|
|
6
6
|
def self.from(content)
|
7
7
|
if content == true || content == false
|
8
8
|
BooleanValue.new(content)
|
9
|
-
elsif content.
|
9
|
+
elsif content.respond_to?(:verified_instance_double?) && content.verified_instance_double?
|
10
10
|
RspecDoubleValue.new(content)
|
11
11
|
elsif content.is_a?(Module)
|
12
12
|
ClassValue.new(content)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module VerifiedDouble
|
2
2
|
module RSpecMocksSyntaxOverrides
|
3
3
|
def allow(*args)
|
4
|
-
if args[0].
|
4
|
+
if args[0].respond_to?(:can_record_interactions?)
|
5
5
|
VerifiedDouble.registry.current_double = args[0]
|
6
6
|
else
|
7
7
|
VerifiedDouble.registry.current_double = nil
|
@@ -10,7 +10,7 @@ module VerifiedDouble
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def expect(*args)
|
13
|
-
if args[0].
|
13
|
+
if args[0].respond_to?(:can_record_interactions?)
|
14
14
|
VerifiedDouble.registry.current_double = args[0]
|
15
15
|
else
|
16
16
|
VerifiedDouble.registry.current_double = nil
|
@@ -33,10 +33,26 @@ describe VerifiedDouble::MethodSignature::Value do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
context "where content is an rspec mock" do
|
36
|
-
let(:content) {
|
36
|
+
let(:content) { VerifiedDouble.of_instance('Stuff') }
|
37
37
|
it { expect(subject).to be_a(VerifiedDouble::MethodSignature::RspecDoubleValue) }
|
38
38
|
end
|
39
39
|
|
40
|
+
context "where content is an rspec mock mocking its is_a? method",
|
41
|
+
verifies_contract: 'Stuff#is_a?(Class)=>VerifiedDouble::Boolean' do
|
42
|
+
|
43
|
+
let(:content) { VerifiedDouble.of_instance('Stuff') }
|
44
|
+
|
45
|
+
before do
|
46
|
+
expect(content).to receive(:is_a?).with(Object).and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it { expect(subject).to be_a(VerifiedDouble::MethodSignature::RspecDoubleValue) }
|
50
|
+
|
51
|
+
after do
|
52
|
+
content.is_a?(Object)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
40
56
|
context "where content is a class double" do
|
41
57
|
let(:content){ stub_const(class_name, Class.new, transfer_nested_constants: true) }
|
42
58
|
|
@@ -5,8 +5,8 @@ describe VerifiedDouble::SimpleDouble do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
let(:class_name) { 'Dummy' }
|
8
|
-
let(:some_instance_double) {
|
9
|
-
let(:some_class_double) {
|
8
|
+
let(:some_instance_double) { VerifiedDouble.of_instance(class_name) }
|
9
|
+
let(:some_class_double) { VerifiedDouble.of_class(class_name) }
|
10
10
|
|
11
11
|
let(:simple_instance_double) { described_class.new(some_instance_double) }
|
12
12
|
let(:simple_class_double) { described_class.new(some_class_double) }
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: verified_double
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- George Mendoza
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
type: :runtime
|
@@ -117,6 +117,8 @@ files:
|
|
117
117
|
- lib/verified_double.rb
|
118
118
|
- lib/verified_double/boolean.rb
|
119
119
|
- lib/verified_double/can_record_interactions.rb
|
120
|
+
- lib/verified_double/is_a_class_double.rb
|
121
|
+
- lib/verified_double/is_an_instance_double.rb
|
120
122
|
- lib/verified_double/matchers.rb
|
121
123
|
- lib/verified_double/method_signature.rb
|
122
124
|
- lib/verified_double/method_signature/boolean_value.rb
|