surrogate 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,5 +1,8 @@
1
1
  rvm use ruby-1.9.3-p125
2
2
 
3
+ # set up gemfile
4
+ export BUNDLE_GEMFILE=gemfiles/rspec_mocks_2.11
5
+
3
6
  root_dir="$(pwd)"
4
7
 
5
8
  alias ac="rspec '$root_dir/spec/acceptance_spec.rb'"
data/Readme.md CHANGED
@@ -458,6 +458,7 @@ TODO
458
458
  * Add a last_instance option so you don't have to track it explicitly
459
459
  * make substitutability matcher go either way
460
460
  * make substitutability matcher not care whether either are surrogates
461
+ * Add support for operators
461
462
 
462
463
 
463
464
  Future Features
@@ -543,6 +543,7 @@ TODO
543
543
  * Add a last_instance option so you don't have to track it explicitly
544
544
  * make substitutability matcher go either way
545
545
  * make substitutability matcher not care whether either are surrogates
546
+ * Add support for operators
546
547
 
547
548
 
548
549
  Future Features
@@ -119,9 +119,18 @@ class Surrogate
119
119
  # Can we move this into the redefinition of initialize and have it explicitly record itself?
120
120
  def new(*args)
121
121
  instance = allocate
122
+ self.last_instance = instance
122
123
  instance.instance_variable_set :@hatchling, Hatchling.new(instance, @hatchery)
123
124
  instance.send :initialize, *args
124
125
  instance
125
126
  end
127
+
128
+ def last_instance
129
+ Thread.current["surrogate_last_instance_#{self.object_id}"]
130
+ end
131
+
132
+ def last_instance=(instance)
133
+ Thread.current["surrogate_last_instance_#{self.object_id}"] = instance
134
+ end
126
135
  end
127
136
  end
@@ -1,3 +1,3 @@
1
1
  class Surrogate
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe '.last_instance' do
4
+ let(:klass) { Surrogate.endow Class.new }
5
+ def with_inspect(n, instance)
6
+ instance.singleton_class.class_eval do
7
+ define_method(:inspect) { "#<INSTANCE #{n}>" }
8
+ end
9
+ instance
10
+ end
11
+
12
+ it 'returns nil when it was not instantiated' do
13
+ klass.last_instance.should be_nil
14
+ end
15
+
16
+ it 'returns the last instance that was created' do
17
+ instance = klass.new
18
+ klass.last_instance.should equal instance
19
+ end
20
+
21
+ specify 'threads do not fuck it up' do
22
+ fiber = Fiber.new do
23
+ fiber_instance = with_inspect 1, klass.new
24
+ Fiber.yield
25
+ klass.last_instance.should equal fiber_instance
26
+ end
27
+ instance = with_inspect 2, klass.new
28
+ fiber.resume
29
+ klass.last_instance.should equal instance
30
+ fiber.resume
31
+ end
32
+
33
+ specify 'multiple surrogates do not fuck it up' do
34
+ klass1 = Surrogate.endow Class.new
35
+ klass2 = Surrogate.endow Class.new
36
+ instance1 = with_inspect 1, klass1.new
37
+ instance2 = with_inspect 2, klass2.new
38
+ klass1.last_instance.should equal instance1
39
+ klass2.last_instance.should equal instance2
40
+ end
41
+
42
+ context 'on a clone' do
43
+ it 'the clone returns the last instance' do
44
+ clone = klass.clone
45
+ instance = clone.new
46
+ clone.last_instance.should == instance
47
+ end
48
+
49
+ it 'the original surrogate does not return the last instance' do
50
+ klass.clone.new
51
+ klass.last_instance.should be_nil
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrogate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-10 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindable_block
16
- requirement: &70136705575640 !ruby/object:Gem::Requirement
16
+ requirement: &70355417643520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.5.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70136705575640
24
+ version_requirements: *70355417643520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70136705575220 !ruby/object:Gem::Requirement
27
+ requirement: &70355417643100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70136705575220
35
+ version_requirements: *70355417643100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70136705574680 !ruby/object:Gem::Requirement
38
+ requirement: &70355417642540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.4'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70136705574680
46
+ version_requirements: *70355417642540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mountain_berry_fields
49
- requirement: &70136705574180 !ruby/object:Gem::Requirement
49
+ requirement: &70355417642020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70136705574180
57
+ version_requirements: *70355417642020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mountain_berry_fields-rspec
60
- requirement: &70136705573720 !ruby/object:Gem::Requirement
60
+ requirement: &70355417641540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70136705573720
68
+ version_requirements: *70355417641540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mountain_berry_fields-magic_comments
71
- requirement: &70136705573260 !ruby/object:Gem::Requirement
71
+ requirement: &70355417641080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.0.1
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70136705573260
79
+ version_requirements: *70355417641080
80
80
  description: Framework to aid in handrolling mock/spy objects.
81
81
  email:
82
82
  - josh.cheek@gmail.com
@@ -114,6 +114,7 @@ files:
114
114
  - lib/surrogate/version.rb
115
115
  - spec/acceptance_spec.rb
116
116
  - spec/defining_api_methods_spec.rb
117
+ - spec/other_shit_spec.rb
117
118
  - spec/rspec/block_support_spec.rb
118
119
  - spec/rspec/initialization_matcher_spec.rb
119
120
  - spec/rspec/messages_spec.rb
@@ -152,6 +153,7 @@ summary: Framework to aid in handrolling mock/spy objects.
152
153
  test_files:
153
154
  - spec/acceptance_spec.rb
154
155
  - spec/defining_api_methods_spec.rb
156
+ - spec/other_shit_spec.rb
155
157
  - spec/rspec/block_support_spec.rb
156
158
  - spec/rspec/initialization_matcher_spec.rb
157
159
  - spec/rspec/messages_spec.rb