caricature 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/caricature.gemspec +3 -3
- data/lib/bin/Workarounds.dll.mdb +0 -0
- data/lib/caricature.rb +25 -25
- data/lib/caricature/clr.rb +6 -6
- data/lib/caricature/clr/aspnet_mvc.rb +54 -54
- data/lib/caricature/core_ext.rb +10 -10
- data/lib/caricature/core_ext/array.rb +9 -9
- data/lib/caricature/core_ext/class.rb +31 -14
- data/lib/caricature/core_ext/hash.rb +12 -12
- data/lib/caricature/core_ext/module.rb +14 -14
- data/lib/caricature/core_ext/object.rb +76 -18
- data/lib/caricature/core_ext/string.rb +16 -16
- data/lib/caricature/core_ext/system/string.rb +20 -20
- data/lib/caricature/core_ext/system/type.rb +26 -26
- data/lib/caricature/descriptor.rb +73 -73
- data/lib/caricature/expectation.rb +264 -263
- data/lib/caricature/isolation.rb +143 -143
- data/lib/caricature/isolator.rb +302 -302
- data/lib/caricature/messenger.rb +67 -67
- data/lib/caricature/method_call_recorder.rb +228 -228
- data/lib/caricature/verification.rb +60 -60
- data/lib/caricature/version.rb +1 -1
- data/spec/bacon/integration/clr_to_clr_spec.rb +4 -4
- data/spec/bacon/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/bacon/integration/event_spec.rb +2 -2
- data/spec/bacon/integration/ruby_to_ruby_spec.rb +270 -270
- data/spec/bacon/integration/syntax_spec.rb +43 -0
- data/spec/bacon/unit/core_ext_spec.rb +87 -87
- data/spec/bacon/unit/expectation_spec.rb +300 -300
- data/spec/bacon/unit/interop_spec.rb +29 -29
- data/spec/bacon/unit/isolation_spec.rb +86 -86
- data/spec/bacon/unit/isolator_spec.rb +219 -219
- data/spec/bacon/unit/messaging_spec.rb +310 -310
- data/spec/bacon/unit/method_call_spec.rb +342 -342
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/rspec/unit/event_spec.rb +1 -1
- metadata +31 -11
- data/spec/models.notused/ClrModels.cs +0 -241
- data/spec/models.notused/ruby_models.rb +0 -151
data/caricature.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = ["README.rdoc",
|
12
12
|
"Rakefile",
|
13
13
|
"caricature.gemspec",
|
14
|
+
"lib/bin/Workarounds.dll.mdb",
|
14
15
|
"lib/caricature.rb",
|
15
16
|
"lib/caricature/bacon.rb",
|
16
17
|
"lib/caricature/bacon/integration.rb",
|
@@ -48,6 +49,7 @@ Gem::Specification.new do |s|
|
|
48
49
|
"spec/bacon/integration/event_spec.rb",
|
49
50
|
"spec/bacon/integration/indexer_spec.rb",
|
50
51
|
"spec/bacon/integration/ruby_to_ruby_spec.rb",
|
52
|
+
"spec/bacon/integration/syntax_spec.rb",
|
51
53
|
"spec/bacon/spec_helper.rb",
|
52
54
|
"spec/bacon/unit/core_ext_spec.rb",
|
53
55
|
"spec/bacon/unit/descriptor_spec.rb",
|
@@ -87,8 +89,6 @@ Gem::Specification.new do |s|
|
|
87
89
|
"spec/fixtures/soldier_with_class_members.rb",
|
88
90
|
"spec/fixtures/swift_cleanup_crew.rb",
|
89
91
|
"spec/fixtures/with_class_methods.rb",
|
90
|
-
"spec/models.notused/ClrModels.cs",
|
91
|
-
"spec/models.notused/ruby_models.rb",
|
92
92
|
"spec/rspec/integration/callback_spec.rb",
|
93
93
|
"spec/rspec/integration/clr_to_clr_spec.rb",
|
94
94
|
"spec/rspec/integration/clr_to_ruby_spec.rb",
|
@@ -117,7 +117,7 @@ Gem::Specification.new do |s|
|
|
117
117
|
s.required_ruby_version = ">= 1.8.6"
|
118
118
|
s.required_rubygems_version = ">= 0"
|
119
119
|
s.rubyforge_project = "caricature"
|
120
|
-
s.rubygems_version = "1.3.
|
120
|
+
s.rubygems_version = "1.3.7"
|
121
121
|
s.specification_version = 3
|
122
122
|
s.summary = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
123
123
|
s.version = "0.7.6"
|
Binary file
|
data/lib/caricature.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'rubygems' unless defined?(Gem)
|
2
|
-
$:.unshift File.dirname(__FILE__)
|
3
|
-
require 'uuidtools'
|
4
|
-
|
5
|
-
module Caricature
|
6
|
-
#
|
7
|
-
# module Interception
|
8
|
-
#
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'caricature/core_ext'
|
14
|
-
require 'caricature/version'
|
15
|
-
require 'caricature/isolation'
|
16
|
-
require 'caricature/clr' if defined? IRONRUBY_VERSION
|
17
|
-
require 'caricature/bacon' if defined? Bacon
|
18
|
-
require 'caricature/rspec' if defined? Spec
|
19
|
-
|
20
|
-
# convenience method for creating an isolation. aliased as mock and stub for less surprises
|
21
|
-
def
|
22
|
-
Caricature::Isolation.for(subject, recorder, expectations)
|
23
|
-
end
|
24
|
-
alias :
|
25
|
-
alias :
|
1
|
+
require 'rubygems' unless defined?(Gem)
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
require 'uuidtools'
|
4
|
+
|
5
|
+
module Caricature
|
6
|
+
#
|
7
|
+
# module Interception
|
8
|
+
#
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'caricature/core_ext'
|
14
|
+
require 'caricature/version'
|
15
|
+
require 'caricature/isolation'
|
16
|
+
require 'caricature/clr' if defined? IRONRUBY_VERSION
|
17
|
+
require 'caricature/bacon' if defined? Bacon
|
18
|
+
require 'caricature/rspec' if defined? Spec
|
19
|
+
|
20
|
+
# convenience method for creating an isolation. aliased as mock and stub for less surprises
|
21
|
+
def isolation_for(subject, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new)
|
22
|
+
Caricature::Isolation.for(subject, recorder, expectations)
|
23
|
+
end
|
24
|
+
alias :mock_for :isolation_for
|
25
|
+
alias :stub_for :isolation_for
|
data/lib/caricature/clr.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/clr/descriptor"
|
2
|
-
require File.dirname(__FILE__) + "/clr/messenger"
|
3
|
-
require File.dirname(__FILE__) + "/clr/isolator"
|
4
|
-
require File.dirname(__FILE__) + "/clr/expectation"
|
5
|
-
require File.dirname(__FILE__) + "/clr/isolation"
|
6
|
-
require File.dirname(__FILE__) + "/clr/event_verification"
|
1
|
+
require File.dirname(__FILE__) + "/clr/descriptor"
|
2
|
+
require File.dirname(__FILE__) + "/clr/messenger"
|
3
|
+
require File.dirname(__FILE__) + "/clr/isolator"
|
4
|
+
require File.dirname(__FILE__) + "/clr/expectation"
|
5
|
+
require File.dirname(__FILE__) + "/clr/isolation"
|
6
|
+
require File.dirname(__FILE__) + "/clr/event_verification"
|
7
7
|
require File.dirname(__FILE__) + "/clr/method_call_recorder"
|
@@ -1,55 +1,55 @@
|
|
1
|
-
load_assembly 'System.Web.Routing'
|
2
|
-
load_assembly 'System.Web.Mvc'
|
3
|
-
load_assembly 'System.Web.Abstractions'
|
4
|
-
|
5
|
-
include System::Web
|
6
|
-
include System::Web::Routing
|
7
|
-
include System::Web::Mvc
|
8
|
-
|
9
|
-
class String
|
10
|
-
|
11
|
-
def to_url_filename
|
12
|
-
return self.gsub(/\?.*/, '') if self =~ /\?/
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_qs_parameters
|
17
|
-
if self =~ /\?/
|
18
|
-
parameters = NameValueCollection.new
|
19
|
-
self.split('?')[1].split("&").each do |pair|
|
20
|
-
parts = pair.split('=')
|
21
|
-
parameters.add pair.first, pair.last
|
22
|
-
end
|
23
|
-
return parameters
|
24
|
-
end
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def http_context_isolation(url="")
|
31
|
-
|
32
|
-
context = Caricature::Isolation.for(HttpContextBase)
|
33
|
-
request = Caricature::Isolation.for(HttpRequestBase)
|
34
|
-
response = Caricature::Isolation.for(HttpResponseBase)
|
35
|
-
session = Caricature::Isolation.for(HttpSessionStateBase)
|
36
|
-
server = Caricature::Isolation.for(HttpServerUtilityBase)
|
37
|
-
|
38
|
-
context.when_receiving(:request).return(request)
|
39
|
-
context.when_receiving(:response).return(response)
|
40
|
-
context.when_receiving(:session).return(session)
|
41
|
-
context.when_receiving(:server).return(server)
|
42
|
-
|
43
|
-
setup_request_url(context.request, url) unless url.nil? or url.empty?
|
44
|
-
|
45
|
-
context
|
46
|
-
end
|
47
|
-
|
48
|
-
def setup_request_url(request, url)
|
49
|
-
raise ArgumentError.new("url should not be nil") if url.nil? or url.empty?
|
50
|
-
raise ArgumentError.new("we expect a url to start with '~/'.") unless url =~ /^~\//
|
51
|
-
|
52
|
-
request.when_receiving(:query_string).return(url.to_s.to_qs_parameters)
|
53
|
-
request.when_receiving(:app_relative_current_execution_file_path).return(url.to_s.to_url_filename)
|
54
|
-
request.when_receiving(:path_info).return("")
|
1
|
+
load_assembly 'System.Web.Routing'
|
2
|
+
load_assembly 'System.Web.Mvc'
|
3
|
+
load_assembly 'System.Web.Abstractions'
|
4
|
+
|
5
|
+
include System::Web
|
6
|
+
include System::Web::Routing
|
7
|
+
include System::Web::Mvc
|
8
|
+
|
9
|
+
class String
|
10
|
+
|
11
|
+
def to_url_filename
|
12
|
+
return self.gsub(/\?.*/, '') if self =~ /\?/
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_qs_parameters
|
17
|
+
if self =~ /\?/
|
18
|
+
parameters = NameValueCollection.new
|
19
|
+
self.split('?')[1].split("&").each do |pair|
|
20
|
+
parts = pair.split('=')
|
21
|
+
parameters.add pair.first, pair.last
|
22
|
+
end
|
23
|
+
return parameters
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def http_context_isolation(url="")
|
31
|
+
|
32
|
+
context = Caricature::Isolation.for(HttpContextBase)
|
33
|
+
request = Caricature::Isolation.for(HttpRequestBase)
|
34
|
+
response = Caricature::Isolation.for(HttpResponseBase)
|
35
|
+
session = Caricature::Isolation.for(HttpSessionStateBase)
|
36
|
+
server = Caricature::Isolation.for(HttpServerUtilityBase)
|
37
|
+
|
38
|
+
context.when_receiving(:request).return(request)
|
39
|
+
context.when_receiving(:response).return(response)
|
40
|
+
context.when_receiving(:session).return(session)
|
41
|
+
context.when_receiving(:server).return(server)
|
42
|
+
|
43
|
+
setup_request_url(context.request, url) unless url.nil? or url.empty?
|
44
|
+
|
45
|
+
context
|
46
|
+
end
|
47
|
+
|
48
|
+
def setup_request_url(request, url)
|
49
|
+
raise ArgumentError.new("url should not be nil") if url.nil? or url.empty?
|
50
|
+
raise ArgumentError.new("we expect a url to start with '~/'.") unless url =~ /^~\//
|
51
|
+
|
52
|
+
request.when_receiving(:query_string).return(url.to_s.to_qs_parameters)
|
53
|
+
request.when_receiving(:app_relative_current_execution_file_path).return(url.to_s.to_url_filename)
|
54
|
+
request.when_receiving(:path_info).return("")
|
55
55
|
end
|
data/lib/caricature/core_ext.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/core_ext/string'
|
2
|
-
require File.dirname(__FILE__) + '/core_ext/class'
|
3
|
-
require File.dirname(__FILE__) + '/core_ext/module'
|
4
|
-
require File.dirname(__FILE__) + '/core_ext/object'
|
5
|
-
require File.dirname(__FILE__) + '/core_ext/array'
|
6
|
-
require File.dirname(__FILE__) + '/core_ext/hash'
|
7
|
-
|
8
|
-
if defined? IRONRUBY_VERSION
|
9
|
-
require File.dirname(__FILE__) + '/core_ext/system/string'
|
10
|
-
require File.dirname(__FILE__) + '/core_ext/system/type'
|
1
|
+
require File.dirname(__FILE__) + '/core_ext/string'
|
2
|
+
require File.dirname(__FILE__) + '/core_ext/class'
|
3
|
+
require File.dirname(__FILE__) + '/core_ext/module'
|
4
|
+
require File.dirname(__FILE__) + '/core_ext/object'
|
5
|
+
require File.dirname(__FILE__) + '/core_ext/array'
|
6
|
+
require File.dirname(__FILE__) + '/core_ext/hash'
|
7
|
+
|
8
|
+
if defined? IRONRUBY_VERSION
|
9
|
+
require File.dirname(__FILE__) + '/core_ext/system/string'
|
10
|
+
require File.dirname(__FILE__) + '/core_ext/system/type'
|
11
11
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class Array
|
2
|
-
|
3
|
-
# Converts an array of values to a hash.
|
4
|
-
# the even indexes are the hash keys
|
5
|
-
# the odd indexes are the hash values
|
6
|
-
def to_h
|
7
|
-
h = Hash[*self]
|
8
|
-
h.symbolize_keys!
|
9
|
-
end
|
1
|
+
class Array
|
2
|
+
|
3
|
+
# Converts an array of values to a hash.
|
4
|
+
# the even indexes are the hash keys
|
5
|
+
# the odd indexes are the hash values
|
6
|
+
def to_h
|
7
|
+
h = Hash[*self]
|
8
|
+
h.symbolize_keys!
|
9
|
+
end
|
10
10
|
end
|
@@ -1,15 +1,32 @@
|
|
1
|
-
class Class
|
2
|
-
|
3
|
-
# removes all the modules from this class name
|
4
|
-
def demodulize
|
5
|
-
self.to_s.gsub(/^.*::/, '')
|
6
|
-
end
|
7
|
-
|
8
|
-
# indicates whether this type has a CLR type in its ancestors
|
9
|
-
def clr_type?
|
10
|
-
!self.to_clr_type.nil? ||
|
11
|
-
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
|
-
self.ancestors.reject {|mod| mod == Object }.any? { |mod| !mod.to_clr_type.nil? }
|
13
|
-
end
|
14
|
-
|
1
|
+
class Class
|
2
|
+
|
3
|
+
# removes all the modules from this class name
|
4
|
+
def demodulize
|
5
|
+
self.to_s.gsub(/^.*::/, '')
|
6
|
+
end
|
7
|
+
|
8
|
+
# indicates whether this type has a CLR type in its ancestors
|
9
|
+
def clr_type?
|
10
|
+
!self.to_clr_type.nil? ||
|
11
|
+
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
|
+
self.ancestors.reject {|mod| mod == Object }.any? { |mod| !mod.to_clr_type.nil? }
|
13
|
+
end
|
14
|
+
|
15
|
+
def isolate(name=nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block)
|
16
|
+
iso = Caricature::Isolation.for(self, recorder, expectations)
|
17
|
+
return iso unless name
|
18
|
+
if block
|
19
|
+
if block.arity > 0
|
20
|
+
@expectation = iso.when_class_receives(name, &block)
|
21
|
+
else
|
22
|
+
@expectation = iso.when_class_receives(name)
|
23
|
+
instance_eval &block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
iso
|
27
|
+
end
|
28
|
+
alias_method :when_receiving, :isolate
|
29
|
+
alias_method :mock, :isolate
|
30
|
+
alias_method :stub, :isolate
|
31
|
+
|
15
32
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
# Destructively convert all keys which respond_to?(:to_sym) to symbols. Works recursively if given nested hashes.
|
4
|
-
def symbolize_keys!
|
5
|
-
each do |k,v|
|
6
|
-
sym = k.respond_to?(:to_sym) ? k.to_sym : k
|
7
|
-
self[sym] = Hash === v ? v.symbolize_keys! : v
|
8
|
-
delete(k) unless k == sym
|
9
|
-
end
|
10
|
-
self
|
11
|
-
end
|
12
|
-
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Destructively convert all keys which respond_to?(:to_sym) to symbols. Works recursively if given nested hashes.
|
4
|
+
def symbolize_keys!
|
5
|
+
each do |k,v|
|
6
|
+
sym = k.respond_to?(:to_sym) ? k.to_sym : k
|
7
|
+
self[sym] = Hash === v ? v.symbolize_keys! : v
|
8
|
+
delete(k) unless k == sym
|
9
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
13
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class Module
|
2
|
-
|
3
|
-
# Removes all but the containing modules from this module's name
|
4
|
-
def demodulize
|
5
|
-
self.to_s.gsub(/^.*::/, '')
|
6
|
-
end
|
7
|
-
|
8
|
-
# indicates whether this type has a CLR type in its ancestors
|
9
|
-
def clr_type?
|
10
|
-
!self.to_clr_type.nil? ||
|
11
|
-
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
|
-
self.ancestors.any? { |mod| !mod.to_clr_type.nil? }
|
13
|
-
end
|
14
|
-
|
1
|
+
class Module
|
2
|
+
|
3
|
+
# Removes all but the containing modules from this module's name
|
4
|
+
def demodulize
|
5
|
+
self.to_s.gsub(/^.*::/, '')
|
6
|
+
end
|
7
|
+
|
8
|
+
# indicates whether this type has a CLR type in its ancestors
|
9
|
+
def clr_type?
|
10
|
+
!self.to_clr_type.nil? ||
|
11
|
+
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
|
+
self.ancestors.any? { |mod| !mod.to_clr_type.nil? }
|
13
|
+
end
|
14
|
+
|
15
15
|
end
|
@@ -1,19 +1,77 @@
|
|
1
|
-
class Object
|
2
|
-
|
3
|
-
# returns whether this object is a clr_type.
|
4
|
-
# if it has a CLR type in one of its ancestors
|
5
|
-
def clr_type?
|
6
|
-
self.class.clr_type?
|
7
|
-
end
|
8
|
-
|
9
|
-
# returns the clr type of this object if any
|
10
|
-
def to_clr_type
|
11
|
-
self.class.to_clr_type
|
12
|
-
end
|
13
|
-
|
14
|
-
# defines a class method on an object
|
15
|
-
def define_cmethod(name, &blk)
|
16
|
-
(
|
17
|
-
|
18
|
-
|
1
|
+
class Object
|
2
|
+
|
3
|
+
# returns whether this object is a clr_type.
|
4
|
+
# if it has a CLR type in one of its ancestors
|
5
|
+
def clr_type?
|
6
|
+
self.class.clr_type?
|
7
|
+
end
|
8
|
+
|
9
|
+
# returns the clr type of this object if any
|
10
|
+
def to_clr_type
|
11
|
+
self.class.to_clr_type
|
12
|
+
end
|
13
|
+
|
14
|
+
# defines a class method on an object
|
15
|
+
def define_cmethod(name, &blk)
|
16
|
+
(
|
17
|
+
class << self;
|
18
|
+
self;
|
19
|
+
end).instance_eval { define_method name, &blk }
|
20
|
+
end
|
21
|
+
|
22
|
+
def isolate(name=nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block)
|
23
|
+
iso = Caricature::Isolation.for(self, recorder, expectations)
|
24
|
+
return iso unless name
|
25
|
+
if block
|
26
|
+
if block.arity > 0
|
27
|
+
@expectation = iso.when_receiving(name, &block)
|
28
|
+
else
|
29
|
+
@expectation = iso.when_receiving(name)
|
30
|
+
instance_eval &block
|
31
|
+
end
|
32
|
+
end
|
33
|
+
iso
|
34
|
+
end
|
35
|
+
alias_method :when_receiving, :isolate
|
36
|
+
alias_method :mock, :isolate
|
37
|
+
alias_method :stub, :isolate
|
38
|
+
|
39
|
+
# tell the expectation which arguments it needs to respond to
|
40
|
+
# there is a magic argument here +any+ which configures
|
41
|
+
# the expectation to respond to any arguments
|
42
|
+
def with(*ags, &b)
|
43
|
+
@expectation.with(*ags, &b)
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
# tell the expectation it needs to return this value or the value returned by the block
|
48
|
+
# you provide to this method.
|
49
|
+
def returns(value=nil, &b)
|
50
|
+
@expectation.return(value, &b)
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# Sets up arguments for the block that is being passed into the isolated method call
|
55
|
+
def pass_block(*ags, &b)
|
56
|
+
@expectation.pass_block(*ags, &b)
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
# tell the expectation it needs to raise an error with the specified arguments
|
61
|
+
def raise_error(*args)
|
62
|
+
@expectation.raise(*args)
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
# tell the expectation it needs to call the super before the expectation exectution
|
67
|
+
def super_before(&b)
|
68
|
+
@expectation.super_before(&b)
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
# tell the expectation it needs to call the super after the expecation execution
|
73
|
+
def super_after(&b)
|
74
|
+
@expectation.super_after &b
|
75
|
+
self
|
76
|
+
end
|
19
77
|
end
|