verified_double 0.4.1 → 0.4.2

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.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ 0.4.2 - 2013-09-28
2
+ ------------------
3
+
4
+ [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
5
+
1
6
  0.4.1 - 2013-08-17
2
7
  ------------------
3
8
 
@@ -1,3 +1,8 @@
1
+ 0.4.2 - 2013-09-28
2
+ ------------------
3
+
4
+ [#25] Fix: cannot mock is_a? on a VerifiedDouble instance double.
5
+
1
6
  0.4.1 - 2013-08-17
2
7
  ------------------
3
8
 
@@ -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
- VerifiedDouble.record(stub_const(class_name, Class.new, options))
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
@@ -0,0 +1,8 @@
1
+ module VerifiedDouble
2
+ module IsAClassDouble
3
+ def verified_class_double?
4
+ true
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,8 @@
1
+ module VerifiedDouble
2
+ module IsAnInstanceDouble
3
+ def verified_instance_double?
4
+ true
5
+ end
6
+ end
7
+ end
8
+
@@ -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.is_a?(RSpec::Mocks::Mock)
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].is_a?(VerifiedDouble::CanRecordInteractions)
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].is_a?(VerifiedDouble::CanRecordInteractions)
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
@@ -19,7 +19,7 @@ module VerifiedDouble
19
19
  end
20
20
 
21
21
  def class_double?
22
- internal.is_a?(Class)
22
+ internal.respond_to?(:verified_class_double?)
23
23
  end
24
24
 
25
25
  def method_operator
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -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) { double(:stuff) }
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) { double(class_name) }
9
- let(:some_class_double) { stub_const(class_name, Class.new) }
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.1
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-08-17 00:00:00.000000000 Z
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