surrogate 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -251,17 +251,6 @@ user.id.should == 12
251
251
  user.should have_been_initialized_with 12
252
252
  ```
253
253
 
254
- Initialization is **always recorded**, so that you don't have to override it just to be able to query.
255
-
256
- ```ruby
257
- class MockUser < Struct.new(:id)
258
- Surrogate.endow self
259
- end
260
- user = MockUser.new 12
261
- user.id.should == 12
262
- user.should have_been_initialized_with 12
263
- ```
264
-
265
254
 
266
255
  Substitutability
267
256
  ----------------
@@ -356,7 +345,9 @@ Need to put an explanation here soon. In the meantime, I wrote a [blog](http://b
356
345
  Special Thanks
357
346
  ==============
358
347
 
359
- * [Corey Haines](http://coreyhaines.com/) for pairing on it with me
348
+ * [Kyle Hargraves](https://github.com/pd) for changing the name of his internal gem so that I could take Surrogate
349
+ * [Corey Haines](http://coreyhaines.com/) for pairing on substitutability with me
350
+ * [Enova](http://www.enovafinancial.com/) for giving me time and motivation to work on this during Enova Labs.
360
351
  * [8th Light](http://8thlight.com/) for giving me time to work on this during our weekly Wazas, and the general encouragement and interest
361
352
 
362
353
 
@@ -377,3 +368,7 @@ Future Features
377
368
  * Ability to disassociate the method name from the test (e.g. you shouldn't need to change a test just because you change a name)
378
369
  * declare normal methods as being part of the API (e.g. for inheritance)
379
370
  * assertions for order of invocations & methods
371
+ * class generator? (supports a top-down style of development for when you write your mocks before you write your implementations)
372
+ * extract surrogate/rspec into its own gem?
373
+ * deal with hard dependency on rspec-mocks
374
+ * support subset-substitutabilty not being able to touch real methods (e.g. #respond_to?)
@@ -3,6 +3,7 @@ class Surrogate
3
3
  # Adds surrogate behaviour to your class / singleton class / instances
4
4
  #
5
5
  # please refactor me! ...may not be possible :(
6
+ # Can we move all method definitions into this class?
6
7
  class Endower
7
8
  def self.endow(klass, &block)
8
9
  new(klass, &block).endow
@@ -22,12 +23,11 @@ class Surrogate
22
23
  private
23
24
 
24
25
  def endow_klass
25
- add_hatchery_to klass
26
26
  klass.extend ClassMethods
27
+ add_hatchery_to klass
27
28
  enable_defining_methods klass
28
29
  record_initialization_for_instances_of klass
29
30
  remember_invocations_for_instances_of klass
30
- remember_invocations_for_instances_of klass.singleton_class
31
31
  end
32
32
 
33
33
  def endow_singleton_class
@@ -35,6 +35,7 @@ class Surrogate
35
35
  enable_defining_methods singleton
36
36
  singleton.module_eval &block if block
37
37
  klass.instance_variable_set :@hatchling, Hatchling.new(klass, hatchery)
38
+ remember_invocations_for_instances_of singleton
38
39
  klass
39
40
  end
40
41
 
@@ -87,6 +88,9 @@ class Surrogate
87
88
 
88
89
  # use a module so that the method is inherited (important for substitutability)
89
90
  module ClassMethods
91
+
92
+ # Should this be dup? (dup seems to copy singleton methods) and may be able to use #initialize_copy to reset ivars
93
+ # Can we just remove this feature an instead provide a reset feature which could be hooked into in before/after blocks (e.g. https://github.com/rspec/rspec-core/blob/622505d616d950ed53d12c6e82dbb953ba6241b4/lib/rspec/core/mocking/with_rspec.rb)
90
94
  def clone
91
95
  hatchling, hatchery = @hatchling, @hatchery
92
96
  Class.new self do
@@ -97,7 +101,8 @@ class Surrogate
97
101
  end
98
102
  end
99
103
 
100
- # Custom new, because user can define initialize, and ivars should be set before it
104
+ # Custom new, because user can define initialize, and we need to record it
105
+ # Can we move this into the redefinition of initialize and have it explicitly record itself?
101
106
  def new(*args)
102
107
  instance = allocate
103
108
  instance.instance_variable_set :@hatchling, Hatchling.new(instance, @hatchery)
@@ -12,7 +12,7 @@ class Surrogate
12
12
  elsif arg.kind_of? Exception
13
13
  Raisable.new arg
14
14
  elsif arg.kind_of? Value
15
- Recursive.new arg
15
+ arg
16
16
  else
17
17
  Value.new arg
18
18
  end
@@ -45,13 +45,6 @@ class Surrogate
45
45
  end
46
46
 
47
47
 
48
- class Recursive < Value
49
- def value(hatchling, method_name)
50
- @value.value hatchling, method_name
51
- end
52
- end
53
-
54
-
55
48
  class MethodQueue < Value
56
49
  QueueEmpty = Class.new StandardError
57
50
 
@@ -1,3 +1,3 @@
1
1
  class Surrogate
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/surrogate.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Surrogate::VERSION
8
8
  s.authors = ["Josh Cheek"]
9
9
  s.email = ["josh.cheek@gmail.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/JoshCheek/surrogate"
11
11
  s.summary = %q{Framework to aid in handrolling mock/spy objects.}
12
12
  s.description = %q{Framework to aid in handrolling mock/spy objects.}
13
13
 
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.3.1
4
+ version: 0.3.2
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-05-01 00:00:00.000000000 Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70186184231320 !ruby/object:Gem::Requirement
16
+ requirement: &70198239716160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70186184231320
24
+ version_requirements: *70198239716160
25
25
  description: Framework to aid in handrolling mock/spy objects.
26
26
  email:
27
27
  - josh.cheek@gmail.com
@@ -55,7 +55,7 @@ files:
55
55
  - spec/spec_helper.rb
56
56
  - spec/unit/api_comparer_spec.rb
57
57
  - surrogate.gemspec
58
- homepage: ''
58
+ homepage: https://github.com/JoshCheek/surrogate
59
59
  licenses: []
60
60
  post_install_message:
61
61
  rdoc_options: []