verified_double 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ 0.4.1 - 2013-08-17
2
+ ------------------
3
+
4
+ [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
5
+
6
+ [#21] Fix: Class double return value cannot be verified.
7
+
1
8
  0.4.0 - 2013-07-28
2
9
  ------------------
3
10
 
@@ -1,3 +1,10 @@
1
+ 0.4.1 - 2013-08-17
2
+ ------------------
3
+
4
+ [#20] Fix: Cannot get stack frame of method signature recorded within a shared example.
5
+
6
+ [#21] Fix: Class double return value cannot be verified.
7
+
1
8
  0.4.0 - 2013-07-28
2
9
  ------------------
3
10
 
@@ -98,3 +98,31 @@ Feature: 04. Customizing arguments and return values
98
98
 
99
99
  When I run the test suite
100
100
  Then I should not see any output saying the mock is unverified
101
+
102
+ Scenario: class double as return value
103
+ Given a test that uses VerifiedDouble to mock an object:
104
+ """
105
+ require 'spec_helper'
106
+ describe ObjectUnderTest do
107
+ let(:collaborator_class){ VerifiedDouble.of_class('Collaborator') }
108
+ let(:instance_double) { VerifiedDouble.of_instance('Collaborator', class: collaborator_class) }
109
+
110
+ it "tests something" do
111
+ expect(instance_double.class).to eq(collaborator_class)
112
+ end
113
+ end
114
+ """
115
+
116
+ And the test suite has a contract test for the mock:
117
+ """
118
+ require 'spec_helper'
119
+
120
+ describe 'Collaborator' do
121
+ it "tests something", verifies_contract: 'Collaborator#class()=>Class' do
122
+ # do nothing
123
+ end
124
+ end
125
+ """
126
+
127
+ When I run the test suite
128
+ Then I should not see any output saying the mock is unverified
@@ -2,7 +2,7 @@ module VerifiedDouble
2
2
  class MethodSignature
3
3
  class ClassValue < Value
4
4
  def belongs_to?(other)
5
- self.content == other.content
5
+ self.content == other.content || self.content.is_a?(other.content)
6
6
  end
7
7
 
8
8
  def content_as_instance
@@ -3,7 +3,7 @@ module VerifiedDouble
3
3
  attr_reader :stack_frame
4
4
 
5
5
  def initialize(*args)
6
- @stack_frame = StackFrame.new(caller(0).detect{|line| line =~ /_spec\.rb/ })
6
+ @stack_frame = StackFrame.new(caller(0).detect{|line| line =~ %r{/spec/} })
7
7
  super(*args)
8
8
  end
9
9
 
@@ -1,3 +1,3 @@
1
1
  module VerifiedDouble
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pry'
2
2
  require 'verified_double'
3
3
  require 'verified_double/rspec_configuration'
4
+ require 'support/shared_examples.rb'
4
5
 
5
6
  # This file was generated by the `rspec --init` command. Conventionally, all
6
7
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -0,0 +1,9 @@
1
+ shared_examples_for "it can initialize its stack frame within a shared example" do
2
+ it "set the stack frame of the signature's caller" do
3
+ subject = described_class.new(attributes).tap {|method_signature|
4
+ method_signature.method = 'do_something' }
5
+
6
+ expect(subject.stack_frame.to_s)
7
+ .to include("./spec/support/shared_examples.rb")
8
+ end
9
+ end
@@ -10,9 +10,14 @@ describe VerifiedDouble::MethodSignature::ClassValue do
10
10
  end
11
11
 
12
12
  context "where the value and other do not have the same content" do
13
- let(:other) { described_class.new(Object) }
13
+ let(:other) { described_class.new(Float) }
14
14
  it { expect(subject.belongs_to?(other)).to be_false }
15
15
  end
16
+
17
+ context "where the other is a Class" do
18
+ let(:other) { described_class.new(Class) }
19
+ it { expect(subject.belongs_to?(other)).to be_true }
20
+ end
16
21
  end
17
22
 
18
23
  describe "#content_as_instance" do
@@ -24,4 +24,6 @@ describe VerifiedDouble::RecordedMethodSignature do
24
24
  .to include("./spec/verified_double/recorded_method_signature_spec.rb")
25
25
  end
26
26
  end
27
+
28
+ it_behaves_like "it can initialize its stack frame within a shared example"
27
29
  end
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.0
5
+ version: 0.4.1
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-07-28 00:00:00.000000000 Z
12
+ date: 2013-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -134,6 +134,7 @@ files:
134
134
  - lib/verified_double/stack_frame.rb
135
135
  - lib/verified_double/version.rb
136
136
  - spec/spec_helper.rb
137
+ - spec/support/shared_examples.rb
137
138
  - spec/verified_double/can_record_interactions_spec.rb
138
139
  - spec/verified_double/matchers_spec.rb
139
140
  - spec/verified_double/method_signature/boolean_value_spec.rb
@@ -187,6 +188,7 @@ test_files:
187
188
  - features/verified_mocks.feature
188
189
  - features/verified_stubs.feature
189
190
  - spec/spec_helper.rb
191
+ - spec/support/shared_examples.rb
190
192
  - spec/verified_double/can_record_interactions_spec.rb
191
193
  - spec/verified_double/matchers_spec.rb
192
194
  - spec/verified_double/method_signature/boolean_value_spec.rb