caricature 0.7.1 → 0.7.2
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/Rakefile +47 -40
- data/caricature.gemspec +50 -17
- data/lib/caricature.rb +9 -1
- data/lib/caricature/bacon/integration.rb +3 -5
- data/lib/caricature/clr/isolation.rb +1 -1
- data/lib/caricature/method_call_recorder.rb +7 -2
- data/lib/caricature/rspec.rb +1 -0
- data/lib/caricature/rspec/integration.rb +77 -0
- data/lib/caricature/verification.rb +9 -1
- data/lib/caricature/version.rb +1 -1
- data/lib/core_ext/class.rb +1 -1
- data/lib/core_ext/module.rb +1 -1
- data/lib/core_ext/object.rb +2 -2
- data/spec/{integration → bacon/integration}/callback_spec.rb +1 -1
- data/spec/{integration → bacon/integration}/clr_to_clr_spec.rb +1 -1
- data/spec/{integration → bacon/integration}/clr_to_ruby_spec.rb +1 -1
- data/spec/{integration → bacon/integration}/indexer_spec.rb +1 -1
- data/spec/{integration → bacon/integration}/ruby_to_ruby_spec.rb +1 -1
- data/spec/bacon/spec_helper.rb +5 -0
- data/spec/{unit → bacon/unit}/core_ext_spec.rb +13 -13
- data/spec/{unit → bacon/unit}/descriptor_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/expectation_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/interop_spec.rb +3 -3
- data/spec/{unit → bacon/unit}/isolation_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/isolator_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/messaging_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/method_call_spec.rb +2 -2
- data/spec/{unit → bacon/unit}/sword_spec.rb +1 -1
- data/spec/{unit → bacon/unit}/verification_spec.rb +1 -1
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/{bacon_helper.rb → models/ruby_models.rb} +9 -26
- data/spec/rspec/integration/callback_spec.rb +157 -0
- data/spec/rspec/integration/clr_to_clr_spec.rb +255 -0
- data/spec/rspec/integration/clr_to_ruby_spec.rb +228 -0
- data/spec/rspec/integration/indexer_spec.rb +28 -0
- data/spec/rspec/integration/ruby_to_ruby_spec.rb +272 -0
- data/spec/rspec/spec_helper.rb +6 -0
- data/spec/rspec/unit/core_ext_spec.rb +87 -0
- data/spec/rspec/unit/descriptor_spec.rb +160 -0
- data/spec/rspec/unit/expectation_spec.rb +301 -0
- data/spec/rspec/unit/interop_spec.rb +43 -0
- data/spec/rspec/unit/isolation_spec.rb +87 -0
- data/spec/rspec/unit/isolator_spec.rb +220 -0
- data/spec/rspec/unit/messaging_spec.rb +311 -0
- data/spec/rspec/unit/method_call_spec.rb +343 -0
- data/spec/rspec/unit/sword_spec.rb +40 -0
- data/spec/rspec/unit/verification_spec.rb +104 -0
- data/spec/spec_helper.rb +15 -0
- metadata +37 -18
data/Rakefile
CHANGED
@@ -8,26 +8,33 @@ require 'caricature'
|
|
8
8
|
desc "The default task is to run all the specs"
|
9
9
|
task :default => [:clr_models, :spec]
|
10
10
|
|
11
|
-
|
12
|
-
task :spec do
|
13
|
-
system "ibacon #{Dir.glob('spec/**/*_spec.rb').join(' ')}"
|
14
|
-
end
|
11
|
+
%w(bacon spec).each do |fw|
|
15
12
|
|
16
|
-
|
13
|
+
gem_name = fw == "bacon" ? fw : "r#{fw}"
|
17
14
|
|
18
|
-
desc "
|
19
|
-
task
|
20
|
-
|
21
|
-
system "ibacon #{specs.join(' ')}"
|
15
|
+
desc "Runs all the #{gem_name} specs"
|
16
|
+
task fw.to_sym do
|
17
|
+
system "i#{fw} #{Dir.glob("spec/#{gem_name}/**/*_spec.rb").join(' ')}"
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
namespace fw.to_sym do
|
21
|
+
|
22
|
+
desc "runs the #{gem_name} examples for the different classes"
|
23
|
+
task :unit do
|
24
|
+
specs = Dir.glob("spec/#{gem_name}/unit/**/*_spec.rb")
|
25
|
+
system "i#{fw} #{specs.join(' ')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "runs the #{gem_name} integration examples"
|
29
|
+
task :integration do
|
30
|
+
specs = Dir.glob("spec/#{gem_name}/integration/**/*_spec.rb")
|
31
|
+
system "i#{fw} #{specs.join(' ')}"
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
36
|
+
|
37
|
+
|
31
38
|
def csc
|
32
39
|
system "gmcs"
|
33
40
|
$?.pid.zero? ? "csc" : "gmcs"
|
@@ -274,30 +281,30 @@ end
|
|
274
281
|
# puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
275
282
|
# end
|
276
283
|
#
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
284
|
+
begin
|
285
|
+
require 'rake/contrib/sshpublisher'
|
286
|
+
namespace :rubyforge do
|
287
|
+
|
288
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
289
|
+
task :release => ["rubyforge:release:gem", 'rubyforge:release:docs']
|
290
|
+
|
291
|
+
namespace :release do
|
292
|
+
desc "Publish RDoc to RubyForge."
|
293
|
+
task :docs => [:rdoc] do
|
294
|
+
config = YAML.load(
|
295
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
296
|
+
)
|
297
|
+
|
298
|
+
host = "#{config['username']}@rubyforge.org"
|
299
|
+
remote_dir = "/var/www/gforge-projects/caricature/"
|
300
|
+
local_dir = 'doc'
|
301
|
+
|
302
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
rescue LoadError
|
307
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
308
|
+
end
|
309
|
+
|
310
|
+
|
data/caricature.gemspec
CHANGED
@@ -11,9 +11,12 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = ["README.rdoc",
|
12
12
|
"Rakefile",
|
13
13
|
"caricature.gemspec",
|
14
|
+
"lib/caricature",
|
14
15
|
"lib/caricature.rb",
|
16
|
+
"lib/caricature/bacon",
|
15
17
|
"lib/caricature/bacon.rb",
|
16
18
|
"lib/caricature/bacon/integration.rb",
|
19
|
+
"lib/caricature/clr",
|
17
20
|
"lib/caricature/clr.rb",
|
18
21
|
"lib/caricature/clr/aspnet_mvc.rb",
|
19
22
|
"lib/caricature/clr/descriptor.rb",
|
@@ -26,10 +29,12 @@ Gem::Specification.new do |s|
|
|
26
29
|
"lib/caricature/isolator.rb",
|
27
30
|
"lib/caricature/messenger.rb",
|
28
31
|
"lib/caricature/method_call_recorder.rb",
|
32
|
+
"lib/caricature/rspec",
|
29
33
|
"lib/caricature/rspec.rb",
|
30
34
|
"lib/caricature/rspec/integration.rb",
|
31
35
|
"lib/caricature/verification.rb",
|
32
36
|
"lib/caricature/version.rb",
|
37
|
+
"lib/core_ext",
|
33
38
|
"lib/core_ext/array.rb",
|
34
39
|
"lib/core_ext/class.rb",
|
35
40
|
"lib/core_ext/core_ext.rb",
|
@@ -37,26 +42,54 @@ Gem::Specification.new do |s|
|
|
37
42
|
"lib/core_ext/module.rb",
|
38
43
|
"lib/core_ext/object.rb",
|
39
44
|
"lib/core_ext/string.rb",
|
45
|
+
"lib/core_ext/system",
|
40
46
|
"lib/core_ext/system/string.rb",
|
41
47
|
"lib/core_ext/system/type.rb",
|
42
|
-
"spec/
|
48
|
+
"spec/bacon",
|
49
|
+
"spec/bacon/integration",
|
50
|
+
"spec/bacon/integration/callback_spec.rb",
|
51
|
+
"spec/bacon/integration/clr_to_clr_spec.rb",
|
52
|
+
"spec/bacon/integration/clr_to_ruby_spec.rb",
|
53
|
+
"spec/bacon/integration/indexer_spec.rb",
|
54
|
+
"spec/bacon/integration/ruby_to_ruby_spec.rb",
|
55
|
+
"spec/bacon/spec_helper.rb",
|
56
|
+
"spec/bacon/unit",
|
57
|
+
"spec/bacon/unit/core_ext_spec.rb",
|
58
|
+
"spec/bacon/unit/descriptor_spec.rb",
|
59
|
+
"spec/bacon/unit/expectation_spec.rb",
|
60
|
+
"spec/bacon/unit/interop_spec.rb",
|
61
|
+
"spec/bacon/unit/isolation_spec.rb",
|
62
|
+
"spec/bacon/unit/isolator_spec.rb",
|
63
|
+
"spec/bacon/unit/messaging_spec.rb",
|
64
|
+
"spec/bacon/unit/method_call_spec.rb",
|
65
|
+
"spec/bacon/unit/sword_spec.rb",
|
66
|
+
"spec/bacon/unit/verification_spec.rb",
|
67
|
+
"spec/bin",
|
43
68
|
"spec/bin/ClrModels.dll",
|
44
|
-
"spec/
|
45
|
-
"spec/
|
46
|
-
"spec/integration/clr_to_ruby_spec.rb",
|
47
|
-
"spec/integration/indexer_spec.rb",
|
48
|
-
"spec/integration/ruby_to_ruby_spec.rb",
|
69
|
+
"spec/bin/ClrModels.dll.mdb",
|
70
|
+
"spec/models",
|
49
71
|
"spec/models/ClrModels.cs",
|
50
|
-
"spec/
|
51
|
-
"spec/
|
52
|
-
"spec/
|
53
|
-
"spec/
|
54
|
-
"spec/
|
55
|
-
"spec/
|
56
|
-
"spec/
|
57
|
-
"spec/
|
58
|
-
"spec/
|
59
|
-
"spec/unit
|
72
|
+
"spec/models/ruby_models.rb",
|
73
|
+
"spec/rspec",
|
74
|
+
"spec/rspec/integration",
|
75
|
+
"spec/rspec/integration/callback_spec.rb",
|
76
|
+
"spec/rspec/integration/clr_to_clr_spec.rb",
|
77
|
+
"spec/rspec/integration/clr_to_ruby_spec.rb",
|
78
|
+
"spec/rspec/integration/indexer_spec.rb",
|
79
|
+
"spec/rspec/integration/ruby_to_ruby_spec.rb",
|
80
|
+
"spec/rspec/spec_helper.rb",
|
81
|
+
"spec/rspec/unit",
|
82
|
+
"spec/rspec/unit/core_ext_spec.rb",
|
83
|
+
"spec/rspec/unit/descriptor_spec.rb",
|
84
|
+
"spec/rspec/unit/expectation_spec.rb",
|
85
|
+
"spec/rspec/unit/interop_spec.rb",
|
86
|
+
"spec/rspec/unit/isolation_spec.rb",
|
87
|
+
"spec/rspec/unit/isolator_spec.rb",
|
88
|
+
"spec/rspec/unit/messaging_spec.rb",
|
89
|
+
"spec/rspec/unit/method_call_spec.rb",
|
90
|
+
"spec/rspec/unit/sword_spec.rb",
|
91
|
+
"spec/rspec/unit/verification_spec.rb",
|
92
|
+
"spec/spec_helper.rb"]
|
60
93
|
s.has_rdoc = true
|
61
94
|
s.homepage = "http://casualjim.github.com/caricature"
|
62
95
|
s.loaded = false
|
@@ -70,5 +103,5 @@ Gem::Specification.new do |s|
|
|
70
103
|
s.rubygems_version = "1.3.5"
|
71
104
|
s.specification_version = 3
|
72
105
|
s.summary = "Caricature brings simple mocking to Ruby, DLR and CLR."
|
73
|
-
s.version = "0.7.
|
106
|
+
s.version = "0.7.2"
|
74
107
|
end
|
data/lib/caricature.rb
CHANGED
@@ -12,4 +12,12 @@ require 'core_ext/core_ext'
|
|
12
12
|
require 'caricature/version'
|
13
13
|
require 'caricature/isolation'
|
14
14
|
require 'caricature/clr' if defined? IRONRUBY_VERSION
|
15
|
-
require 'caricature/bacon' if defined? Bacon
|
15
|
+
require 'caricature/bacon' if defined? Bacon
|
16
|
+
require 'caricature/rspec' if defined? Spec
|
17
|
+
|
18
|
+
# convenience method for creating an isolation. aliased as mock and stub for less surprises
|
19
|
+
def isolate(subject, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new)
|
20
|
+
Caricature::Isolation.for(subject, recorder, expectations)
|
21
|
+
end
|
22
|
+
alias :mock :isolate
|
23
|
+
alias :stub :isolate
|
@@ -39,11 +39,9 @@ module Caricature
|
|
39
39
|
# indicate that this method verification is successful
|
40
40
|
def successful?
|
41
41
|
a = any_args? ? [:any] : @args
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
raise Caricature::ArgumentMatchError.new :failed, e
|
46
|
-
end
|
42
|
+
res = @recorder.was_called?(@method_name, @block_args, @mode, *a)
|
43
|
+
raise Caricature::ArgumentMatchError.new(:failed, self.error) unless res
|
44
|
+
res
|
47
45
|
end
|
48
46
|
|
49
47
|
|
@@ -9,7 +9,7 @@ module Caricature
|
|
9
9
|
# method call recorder
|
10
10
|
def for(subject, recorder = MethodCallRecorder.new, expectations = Expectations.new)
|
11
11
|
context = IsolatorContext.new subject, recorder, expectations
|
12
|
-
isolation_strategy = subject.
|
12
|
+
isolation_strategy = subject.clr_type? ? get_clr_isolation_strategy(subject) : RubyIsolator
|
13
13
|
|
14
14
|
isolator = isolation_strategy.for context
|
15
15
|
isolation = new(isolator, context)
|
@@ -167,16 +167,21 @@ module Caricature
|
|
167
167
|
agc.first.add_block_variation *ags
|
168
168
|
res
|
169
169
|
})
|
170
|
-
|
170
|
+
end
|
171
|
+
|
172
|
+
def error
|
173
|
+
@error
|
174
|
+
end
|
171
175
|
|
172
176
|
# returns whether the method was actually called with the specified constraints
|
173
177
|
def was_called?(method_name, block_args, mode=:instance, *args)
|
174
178
|
mc = method_calls[mode][method_name.to_s.to_sym]
|
175
179
|
if mc
|
176
180
|
result = mc.find_argument_variations(args, block_args).first == args
|
177
|
-
|
181
|
+
@error = "Arguments don't match.\nYou expected: #{args.join(", ")}.\nI did find the following variations: #{mc.args.collect {|ar| ar.args.join(', ') }.join(' and ')}" unless result
|
178
182
|
result
|
179
183
|
else
|
184
|
+
@error = "Couldn't find a method with name #{method_name}"
|
180
185
|
return !!mc
|
181
186
|
end
|
182
187
|
end
|
data/lib/caricature/rspec.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'caricature/rspec/integration' if defined? Spec
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Spec
|
2
|
+
module Adapters
|
3
|
+
module MockFramework
|
4
|
+
|
5
|
+
def setup_mocks_for_rspec
|
6
|
+
# No setup required
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_mocks_for_rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown_mocks_for_rspec
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Caricature
|
19
|
+
|
20
|
+
module RSpecMatchers
|
21
|
+
|
22
|
+
class HaveReceived
|
23
|
+
def initialize(expected)
|
24
|
+
@expected = expected
|
25
|
+
@block_args, @error, @args = nil, "", [:any]
|
26
|
+
end
|
27
|
+
|
28
|
+
def matches?(target)
|
29
|
+
@target = target
|
30
|
+
|
31
|
+
veri = @target.did_receive?(@expected).with(*@args)
|
32
|
+
veri.with_block_args(*@block_args) if @block_args
|
33
|
+
result = veri.successful?
|
34
|
+
|
35
|
+
@error = "\n#{veri.error}" unless result
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
def failure_message_for_should
|
41
|
+
"expected #{@target.inspect} to have received #{@expected}" + @error
|
42
|
+
end
|
43
|
+
|
44
|
+
def failure_message_for_should_not
|
45
|
+
"expected #{@target.inspect} not to have received #{@expected}" + @error
|
46
|
+
end
|
47
|
+
|
48
|
+
# constrain this verification to the provided arguments
|
49
|
+
def with(*args)
|
50
|
+
ags = *args
|
51
|
+
@args = args
|
52
|
+
@args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
|
53
|
+
# @callback = b if b
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def with_block_args(*args)
|
58
|
+
@block_args = args
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
# allow any arguments ignore the argument constraint
|
63
|
+
def allow_any_arguments
|
64
|
+
@args = :any
|
65
|
+
self
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def have_received(method_name, *args)
|
70
|
+
HaveReceived.new(method_name).with(*args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Spec::Runner.configure do |config|
|
76
|
+
config.include(Caricature::RSpecMatchers)
|
77
|
+
end
|
@@ -42,10 +42,18 @@ module Caricature
|
|
42
42
|
@method_name == method_name and any_args? or @args == args
|
43
43
|
end
|
44
44
|
|
45
|
+
def error
|
46
|
+
@recorder.error
|
47
|
+
end
|
48
|
+
|
45
49
|
# indicate that this method verification is successful
|
46
50
|
def successful?
|
47
51
|
a = any_args? ? [:any] : @args
|
48
|
-
|
52
|
+
begin
|
53
|
+
@recorder.was_called?(@method_name, @block_args, @mode, *a)
|
54
|
+
rescue ArgumentError
|
55
|
+
false
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
end
|
data/lib/caricature/version.rb
CHANGED
data/lib/core_ext/class.rb
CHANGED
@@ -6,7 +6,7 @@ class Class
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# indicates whether this type has a CLR type in its ancestors
|
9
|
-
def
|
9
|
+
def clr_type?
|
10
10
|
!self.to_clr_type.nil? ||
|
11
11
|
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
12
|
self.ancestors.reject {|mod| mod == Object }.any? { |mod| !mod.to_clr_type.nil? }
|
data/lib/core_ext/module.rb
CHANGED
@@ -6,7 +6,7 @@ class Module
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# indicates whether this type has a CLR type in its ancestors
|
9
|
-
def
|
9
|
+
def clr_type?
|
10
10
|
!self.to_clr_type.nil? ||
|
11
11
|
self.included_modules.any? {|mod| !mod.to_clr_type.nil? } ||
|
12
12
|
self.ancestors.any? { |mod| !mod.to_clr_type.nil? }
|
data/lib/core_ext/object.rb
CHANGED