surrogate 0.1.0
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/.gitignore +4 -0
- data/.rvmrc +7 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.md +54 -0
- data/lib/surrogate/api_comparer.rb +126 -0
- data/lib/surrogate/endower.rb +108 -0
- data/lib/surrogate/hatchery.rb +48 -0
- data/lib/surrogate/hatchling.rb +78 -0
- data/lib/surrogate/method_queue.rb +14 -0
- data/lib/surrogate/options.rb +28 -0
- data/lib/surrogate/rspec/api_method_matchers.rb +246 -0
- data/lib/surrogate/rspec/substitutability_matchers.rb +24 -0
- data/lib/surrogate/rspec.rb +2 -0
- data/lib/surrogate/version.rb +3 -0
- data/lib/surrogate.rb +17 -0
- data/spec/acceptance_spec.rb +131 -0
- data/spec/defining_api_methods_spec.rb +295 -0
- data/spec/rspec/have_been_asked_for_its_spec.rb +143 -0
- data/spec/rspec/have_been_initialized_with_spec.rb +29 -0
- data/spec/rspec/have_been_told_to_spec.rb +133 -0
- data/spec/rspec/messages_spec.rb +33 -0
- data/spec/rspec/substitute_for_spec.rb +73 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/api_comparer_spec.rb +138 -0
- data/surrogate.gemspec +24 -0
- metadata +92 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'substitute_for' do
|
4
|
+
|
5
|
+
context "returns true iff api methods and inherited methods match exactly to the other object's methods. Examples:" do
|
6
|
+
context "a surrogate with no api methods" do
|
7
|
+
let(:surrogate) { Surrogate.endow Class.new }
|
8
|
+
|
9
|
+
example "is substitutable for a class with no methods" do
|
10
|
+
surrogate.should substitute_for Class.new
|
11
|
+
end
|
12
|
+
|
13
|
+
example "is not substitutable for a class with instance methods" do
|
14
|
+
surrogate.should_not substitute_for Class.new { def foo()end }
|
15
|
+
end
|
16
|
+
|
17
|
+
example "is not substitutable for a class with class methods" do
|
18
|
+
surrogate.should_not substitute_for Class.new { def self.foo()end }
|
19
|
+
end
|
20
|
+
|
21
|
+
example "is not substitutable for a class with inherited instance methods" do
|
22
|
+
parent = Class.new { def foo()end }
|
23
|
+
surrogate.should_not substitute_for Class.new(parent)
|
24
|
+
end
|
25
|
+
|
26
|
+
example "is not substitutable for a class with inherited class methods" do
|
27
|
+
parent = Class.new { def self.foo()end }
|
28
|
+
surrogate.should_not substitute_for Class.new(parent)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
context "a surrogate with an instance level api method" do
|
34
|
+
let(:surrogate) { Class.new { Surrogate.endow self; define :foo } }
|
35
|
+
|
36
|
+
example "is substitutable for a class with the same method" do
|
37
|
+
surrogate.should substitute_for Class.new { def foo()end }
|
38
|
+
end
|
39
|
+
|
40
|
+
example "is substitutable for a class that inherits the method" do
|
41
|
+
parent = Class.new { def foo()end }
|
42
|
+
surrogate.should substitute_for Class.new(parent)
|
43
|
+
end
|
44
|
+
|
45
|
+
example "is not substitutable for a class without the method" do
|
46
|
+
surrogate.should_not substitute_for Class.new
|
47
|
+
end
|
48
|
+
|
49
|
+
example "is not substitutable for a class with a different method" do
|
50
|
+
surrogate.should_not substitute_for Class.new { def bar()end }
|
51
|
+
end
|
52
|
+
|
53
|
+
example "is not substitutable for a class with additional methods" do
|
54
|
+
other = Class.new { def foo()end; def bar()end }
|
55
|
+
surrogate.should_not substitute_for other
|
56
|
+
end
|
57
|
+
|
58
|
+
example "is not substitutable for a class with the method and inerited additional methods" do
|
59
|
+
parent = Class.new { def bar()end }
|
60
|
+
surrogate.should_not substitute_for Class.new(parent) { def foo()end }
|
61
|
+
end
|
62
|
+
|
63
|
+
example "is not substitutable for a class with the method and additional class methods" do
|
64
|
+
surrogate.should_not substitute_for Class.new { def foo()end; def self.bar()end }
|
65
|
+
end
|
66
|
+
|
67
|
+
example "is not substitutable for a class with the method and inherited additional class methods" do
|
68
|
+
parent = Class.new { def self.bar()end }
|
69
|
+
surrogate.should_not substitute_for Class.new(parent) { def foo()end }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Surrogate::ApiComparer do
|
4
|
+
|
5
|
+
def set_assertion(set, expectations)
|
6
|
+
expectations[:include].each { |meth| set.should include meth }
|
7
|
+
expectations[:exclude].each { |meth| set.should_not include meth }
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe 'its knowlege about the surrogate' do
|
12
|
+
|
13
|
+
let :surrogate do
|
14
|
+
parent = Class.new do
|
15
|
+
def inherited_instance_meth()end
|
16
|
+
def self.inherited_class_meth()end
|
17
|
+
end
|
18
|
+
|
19
|
+
Class.new parent do
|
20
|
+
Surrogate.endow self do
|
21
|
+
define :api_class_meth
|
22
|
+
def class_meth()end
|
23
|
+
end
|
24
|
+
define :api_instance_meth
|
25
|
+
def instance_meth()end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:comparer) { described_class.new surrogate, Class.new }
|
30
|
+
|
31
|
+
it "knows the surrogate's instance level api methods" do
|
32
|
+
comparer.surrogate_methods[:instance][:api].should == Set[:api_instance_meth]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "knows the surrogate's inherited instance methods" do
|
36
|
+
set_assertion comparer.surrogate_methods[:instance][:inherited],
|
37
|
+
include: [:inherited_instance_meth],
|
38
|
+
exclude: [:api_instance_meth, :instance_meth, :class_meth, :inherited_class_meth, :api_class_meth]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "knows the surrogate's other instance methods" do
|
42
|
+
set_assertion comparer.surrogate_methods[:instance][:other],
|
43
|
+
include: [:instance_meth],
|
44
|
+
exclude: [:inherited_instance_meth, :api_instance_meth, :class_meth, :inherited_class_meth, :api_class_meth]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "knows the surrogate's class level api methods" do
|
48
|
+
comparer.surrogate_methods[:class][:api].should == Set[:api_class_meth]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "knows the surrogate's inherited class methods" do
|
52
|
+
# show new explicitly as we override it in lib
|
53
|
+
set_assertion comparer.surrogate_methods[:class][:inherited],
|
54
|
+
include: [:inherited_class_meth, :new],
|
55
|
+
exclude: [:api_instance_meth, :instance_meth, :class_meth, :inherited_instance_meth, :api_class_meth]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "knows the surrogate's other class methods" do
|
59
|
+
# show new explicitly as we override it in lib
|
60
|
+
set_assertion comparer.surrogate_methods[:class][:other],
|
61
|
+
include: [:class_meth],
|
62
|
+
exclude: [:new, :api_instance_meth, :instance_meth, :inherited_instance_meth, :api_class_meth, :inherited_class_meth]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
describe 'its knowledge about the other object' do
|
68
|
+
let(:surrogate) { Surrogate.endow Class.new }
|
69
|
+
|
70
|
+
let :actual do
|
71
|
+
parent = Class.new { def self.inherited_class_meth()end; def inherited_instance_meth()end }
|
72
|
+
Class.new(parent) { def self.class_meth()end; def instance_meth()end }
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:comparer) { described_class.new surrogate, actual }
|
76
|
+
|
77
|
+
it "knows the object's inherited instance methods" do
|
78
|
+
set_assertion comparer.actual_methods[:instance][:inherited],
|
79
|
+
include: [:inherited_instance_meth],
|
80
|
+
exclude: [:inherited_class_meth, :class_meth, :instance_meth]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "knows the objects other instance methods" do
|
84
|
+
comparer.actual_methods[:instance][:other].should == Set[:instance_meth]
|
85
|
+
end
|
86
|
+
|
87
|
+
it "knows the object's inherited class methods" do
|
88
|
+
set_assertion comparer.actual_methods[:class][:inherited],
|
89
|
+
include: [:inherited_class_meth],
|
90
|
+
exclude: [:inherited_instance_meth, :class_meth, :instance_meth]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "knows the object's other class methods" do
|
94
|
+
comparer.actual_methods[:class][:other].should == Set[:class_meth]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe '#compare' do
|
100
|
+
let(:parent) { Class.new { def inherited_instance_not_on_surrogate()end; def self.inherited_class_not_on_surrogate()end } }
|
101
|
+
|
102
|
+
let :actual do
|
103
|
+
Class.new parent do
|
104
|
+
def instance_not_on_surrogate()end
|
105
|
+
def self.class_not_on_surrogate()end
|
106
|
+
def instance_meth_on_both()end
|
107
|
+
def self.class_meth_on_both()end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
let :surrogate do
|
112
|
+
Class.new do
|
113
|
+
Surrogate.endow(self) { define :class_not_on_actual }
|
114
|
+
define :instance_not_on_actual
|
115
|
+
def instance_meth_on_both()end
|
116
|
+
def self.class_meth_on_both()end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:comparer) { described_class.new surrogate, actual }
|
121
|
+
|
122
|
+
it 'tells me about instance methods on actual that are not on surrogate' do
|
123
|
+
comparer.compare[:instance][:not_on_surrogate].should == Set[:instance_not_on_surrogate, :inherited_instance_not_on_surrogate, :instance_meth_on_both]
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'tells me about class methods on actual that are not on surrogate' do
|
127
|
+
comparer.compare[:class][:not_on_surrogate].should == Set[:class_not_on_surrogate, :inherited_class_not_on_surrogate, :class_meth_on_both]
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'tells me about api instance methods on surrogate that are not on actual' do
|
131
|
+
comparer.compare[:instance][:not_on_actual].should == Set[:instance_not_on_actual]
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'tells me about api class methods on surrogate that are not on actual' do
|
135
|
+
comparer.compare[:class][:not_on_actual].should == Set[:class_not_on_actual]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/surrogate.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "surrogate/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "surrogate"
|
7
|
+
s.version = Surrogate::VERSION
|
8
|
+
s.authors = ["Josh Cheek"]
|
9
|
+
s.email = ["josh.cheek@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Framework to aid in handrolling mock/spy objects.}
|
12
|
+
s.description = %q{Framework to aid in handrolling mock/spy objects.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "surrogate"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec", '~> 2.8.0' # TODO: Figure out how far back we can work with
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: surrogate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Cheek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70192551591960 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70192551591960
|
25
|
+
description: Framework to aid in handrolling mock/spy objects.
|
26
|
+
email:
|
27
|
+
- josh.cheek@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
35
|
+
- Rakefile
|
36
|
+
- Readme.md
|
37
|
+
- lib/surrogate.rb
|
38
|
+
- lib/surrogate/api_comparer.rb
|
39
|
+
- lib/surrogate/endower.rb
|
40
|
+
- lib/surrogate/hatchery.rb
|
41
|
+
- lib/surrogate/hatchling.rb
|
42
|
+
- lib/surrogate/method_queue.rb
|
43
|
+
- lib/surrogate/options.rb
|
44
|
+
- lib/surrogate/rspec.rb
|
45
|
+
- lib/surrogate/rspec/api_method_matchers.rb
|
46
|
+
- lib/surrogate/rspec/substitutability_matchers.rb
|
47
|
+
- lib/surrogate/version.rb
|
48
|
+
- spec/acceptance_spec.rb
|
49
|
+
- spec/defining_api_methods_spec.rb
|
50
|
+
- spec/rspec/have_been_asked_for_its_spec.rb
|
51
|
+
- spec/rspec/have_been_initialized_with_spec.rb
|
52
|
+
- spec/rspec/have_been_told_to_spec.rb
|
53
|
+
- spec/rspec/messages_spec.rb
|
54
|
+
- spec/rspec/substitute_for_spec.rb
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/unit/api_comparer_spec.rb
|
57
|
+
- surrogate.gemspec
|
58
|
+
homepage: ''
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project: surrogate
|
78
|
+
rubygems_version: 1.8.11
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Framework to aid in handrolling mock/spy objects.
|
82
|
+
test_files:
|
83
|
+
- spec/acceptance_spec.rb
|
84
|
+
- spec/defining_api_methods_spec.rb
|
85
|
+
- spec/rspec/have_been_asked_for_its_spec.rb
|
86
|
+
- spec/rspec/have_been_initialized_with_spec.rb
|
87
|
+
- spec/rspec/have_been_told_to_spec.rb
|
88
|
+
- spec/rspec/messages_spec.rb
|
89
|
+
- spec/rspec/substitute_for_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/unit/api_comparer_spec.rb
|
92
|
+
has_rdoc:
|