caricature 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +97 -97
- data/Rakefile +309 -310
- data/caricature.gemspec +123 -110
- data/lib/caricature/bacon/integration.rb +75 -75
- data/lib/caricature/bacon.rb +2 -2
- data/lib/caricature/clr/descriptor.rb +159 -159
- data/lib/caricature/clr/event_verification.rb +56 -56
- data/lib/caricature/clr/expectation.rb +100 -100
- data/lib/caricature/clr/isolation.rb +78 -78
- data/lib/caricature/clr/isolator.rb +252 -252
- data/lib/caricature/clr/messenger.rb +51 -49
- data/lib/caricature/clr/method_call_recorder.rb +96 -96
- data/lib/caricature/expectation.rb +1 -1
- data/lib/caricature/method_call_recorder.rb +3 -3
- data/lib/caricature/rspec/integration.rb +118 -118
- data/lib/caricature/version.rb +5 -5
- data/lib/caricature.rb +25 -25
- data/spec/bacon/integration/callback_spec.rb +156 -156
- data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
- data/spec/bacon/integration/event_spec.rb +97 -97
- data/spec/bacon/integration/indexer_spec.rb +27 -27
- data/spec/bacon/spec_helper.rb +4 -4
- data/spec/bacon/unit/descriptor_spec.rb +212 -212
- data/spec/bacon/unit/sword_spec.rb +39 -39
- data/spec/bacon/unit/verification_spec.rb +103 -103
- data/spec/bin/ClrModels.dll +0 -0
- data/spec/bin/ClrModels.dll.mdb +0 -0
- data/spec/fixtures/ExplodingCar.cs +56 -0
- data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
- data/spec/fixtures/ExposingWarrior.cs +58 -0
- data/spec/fixtures/IExplodingWarrior.cs +10 -0
- data/spec/fixtures/IExposing.cs +9 -0
- data/spec/fixtures/IExposingBridge.cs +9 -0
- data/spec/fixtures/IExposingWarrior.cs +8 -0
- data/spec/fixtures/IHaveAnIndexer.cs +8 -0
- data/spec/fixtures/IWarrior.cs +13 -0
- data/spec/fixtures/IWeapon.cs +9 -0
- data/spec/fixtures/IndexerCaller.cs +17 -0
- data/spec/fixtures/IndexerContained.cs +20 -0
- data/spec/fixtures/MyClassWithAStatic.cs +16 -0
- data/spec/fixtures/Ninja.cs +34 -0
- data/spec/fixtures/Samurai.cs +29 -0
- data/spec/fixtures/StaticCaller.cs +12 -0
- data/spec/fixtures/Sword.cs +16 -0
- data/spec/fixtures/SwordWithStatics.cs +19 -0
- data/spec/fixtures/clr_interaction.rb +61 -0
- data/spec/fixtures/dagger.rb +11 -0
- data/spec/fixtures/dagger_with_class_members.rb +11 -0
- data/spec/fixtures/sheath.rb +19 -0
- data/spec/fixtures/soldier.rb +29 -0
- data/spec/fixtures/soldier_with_class_members.rb +7 -0
- data/spec/fixtures/swift_cleanup_crew.rb +21 -0
- data/spec/fixtures/with_class_methods.rb +11 -0
- data/spec/{models → models.notused}/ClrModels.cs +241 -241
- data/spec/{models → models.notused}/ruby_models.rb +150 -150
- data/spec/rspec/integration/callback_spec.rb +156 -156
- data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
- data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
- data/spec/rspec/integration/indexer_spec.rb +27 -27
- data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
- data/spec/rspec/spec_helper.rb +12 -12
- data/spec/rspec/unit/core_ext_spec.rb +87 -87
- data/spec/rspec/unit/descriptor_spec.rb +210 -210
- data/spec/rspec/unit/event_spec.rb +16 -16
- data/spec/rspec/unit/expectation_spec.rb +300 -300
- data/spec/rspec/unit/interop_spec.rb +29 -29
- data/spec/rspec/unit/isolation_spec.rb +86 -86
- data/spec/rspec/unit/isolator_spec.rb +219 -219
- data/spec/rspec/unit/messaging_spec.rb +310 -310
- data/spec/rspec/unit/method_call_spec.rb +342 -342
- data/spec/rspec/unit/sword_spec.rb +39 -39
- data/spec/rspec/unit/verification_spec.rb +103 -103
- data/spec/spec_helper.rb +16 -15
- metadata +42 -11
@@ -1,50 +1,52 @@
|
|
1
|
-
module Caricature
|
2
|
-
|
3
|
-
# Encapsulates sending messages to CLR class or instance isolations
|
4
|
-
class ClrClassMessenger < Messenger
|
5
|
-
|
6
|
-
protected
|
7
|
-
|
8
|
-
# deliver the message to the receiving isolation
|
9
|
-
def internal_deliver(mode, method_name, return_type, *args, &b)
|
10
|
-
exp = expectations.find(method_name, mode, *args)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
res =
|
22
|
-
|
23
|
-
|
24
|
-
res
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
exp
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
res
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
1
|
+
module Caricature
|
2
|
+
|
3
|
+
# Encapsulates sending messages to CLR class or instance isolations
|
4
|
+
class ClrClassMessenger < Messenger
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
# deliver the message to the receiving isolation
|
9
|
+
def internal_deliver(mode, method_name, return_type, *args, &b)
|
10
|
+
exp = expectations.find(method_name, mode, *args)
|
11
|
+
# exp = expectations.find(method_name.underscore, mode, *args) unless exp
|
12
|
+
bl = record_call(method_name, mode, exp, *args, &b)
|
13
|
+
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
14
|
+
res = nil
|
15
|
+
if exp
|
16
|
+
block = exp.block || b
|
17
|
+
res = instance.__send__(method_name, *args, &block) if exp.super_before?
|
18
|
+
exp.event_recorder do |ev_nm, ev_ar, ev_h|
|
19
|
+
recorder.record_event_raise ev_nm, mode, *ev_ar, &ev_h if ev_nm
|
20
|
+
end if recorder && exp
|
21
|
+
res = exp.execute *args, &bl
|
22
|
+
res = instance.__send__(method_name, *args, &block) if !exp.super_before? and exp.call_super?
|
23
|
+
end
|
24
|
+
res ||= System::Activator.create_instance(return_type) if is_value_type
|
25
|
+
res
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# Encapsulates sending messages to CLR interface isolations
|
31
|
+
class ClrInterfaceMessenger < Messenger
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
# deliver the message to the receiving isolation
|
36
|
+
def internal_deliver(mode, method_name, return_type, *args, &b)
|
37
|
+
res = nil
|
38
|
+
is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
|
39
|
+
exp = expectations.find(method_name, mode, *args)
|
40
|
+
# exp = expectations.find(method_name.underscore, mode, *args) unless exp
|
41
|
+
exp.event_recorder do |ev_nm, ev_ar, ev_h|
|
42
|
+
recorder.record_event_raise ev_nm, mode, *ev_ar, &ev_h if ev_nm
|
43
|
+
end if recorder && exp
|
44
|
+
bl = record_call(method_name, mode, exp, *args, &b)
|
45
|
+
res = exp.execute *args, &bl if exp
|
46
|
+
res ||= System::Activator.create_instance(return_type) if is_value_type
|
47
|
+
res
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
50
52
|
end
|
@@ -1,97 +1,97 @@
|
|
1
|
-
module Caricature
|
2
|
-
|
3
|
-
# A recording that represents an event raise
|
4
|
-
# it contains argument variations that can be matched too
|
5
|
-
class EventRaiseRecording
|
6
|
-
|
7
|
-
# gets or sets the event name
|
8
|
-
attr_accessor :event_name
|
9
|
-
|
10
|
-
# gets or sets the amount of times the event was raised
|
11
|
-
attr_accessor :count
|
12
|
-
|
13
|
-
# gets or sets the arguments for this event raise
|
14
|
-
attr_accessor :args
|
15
|
-
|
16
|
-
# gets or sets the block for this event raise
|
17
|
-
attr_accessor :handler
|
18
|
-
|
19
|
-
# Initializes a new instance of a method call recording
|
20
|
-
# every time a method gets called in an isolated object
|
21
|
-
# this gets stored in the method call recorder
|
22
|
-
# It expects a +method_name+ at the very least.
|
23
|
-
def initialize(event_name, count=0)
|
24
|
-
@event_name = event_name
|
25
|
-
@count = count
|
26
|
-
@variations = []
|
27
|
-
end
|
28
|
-
|
29
|
-
# add args
|
30
|
-
def args
|
31
|
-
@variations
|
32
|
-
end
|
33
|
-
|
34
|
-
# indicates if it has an argument variation
|
35
|
-
def has_argument_variations?
|
36
|
-
@variations.size > 1
|
37
|
-
end
|
38
|
-
|
39
|
-
# add an argument variation
|
40
|
-
def add_argument_variation(args, block)
|
41
|
-
variation = find_argument_variations args
|
42
|
-
if variation.empty?
|
43
|
-
@variations << ArgumentRecording.new(args, @variations.size+1, block) if variation == []
|
44
|
-
else
|
45
|
-
variation.first.call_number += 1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# finds an argument variation that matches the provided +args+
|
50
|
-
def find_argument_variations(args)
|
51
|
-
return @variations if args.first.is_a?(Symbol) and args.last == :any
|
52
|
-
@variations.select { |ar| ar.args == args }
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
class MethodCallRecorder
|
58
|
-
|
59
|
-
def event_raises
|
60
|
-
@event_raises ||= {}
|
61
|
-
end
|
62
|
-
|
63
|
-
def record_event_raise(event_name, mode, *args, &handler)
|
64
|
-
en_sym = event_name.to_sym
|
65
|
-
event_raises[mode] ||= {}
|
66
|
-
ev = (event_raises[mode][en_sym] ||= EventRaiseRecording.new(event_name))
|
67
|
-
ev.count += 1
|
68
|
-
ev.add_argument_variation args, handler
|
69
|
-
end
|
70
|
-
|
71
|
-
def event_error
|
72
|
-
@event_error
|
73
|
-
end
|
74
|
-
|
75
|
-
# returns whether the event was actually raised with the specified constraints
|
76
|
-
def event_raised?(event_name, mode = :instance, *args)
|
77
|
-
mc = event_raises[mode][event_name.to_s.to_sym]
|
78
|
-
if mc
|
79
|
-
vari = mc.find_argument_variations(args)
|
80
|
-
result = vari.any? { |agv| agv == args }
|
81
|
-
return result if result
|
82
|
-
if args.size == 1 and args.last.is_a?(Hash)
|
83
|
-
result = vari.any? do |agv|
|
84
|
-
agv.args.last.is_a?(Hash) and args.last.all? { |k, v| agv.args.last[k] == v }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
@event_error = "Event Arguments don't match for #{event_name}.\n\nYou expected:\n#{args.join(", ")}.\n\nI did find the following variations:\n#{mc.args.collect {|ar| ar.args.join(', ') }.join(' and ')}" unless result
|
88
|
-
result
|
89
|
-
else
|
90
|
-
@event_error = "Couldn't find an event with name #{event_name}"
|
91
|
-
return !!mc
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
1
|
+
module Caricature
|
2
|
+
|
3
|
+
# A recording that represents an event raise
|
4
|
+
# it contains argument variations that can be matched too
|
5
|
+
class EventRaiseRecording
|
6
|
+
|
7
|
+
# gets or sets the event name
|
8
|
+
attr_accessor :event_name
|
9
|
+
|
10
|
+
# gets or sets the amount of times the event was raised
|
11
|
+
attr_accessor :count
|
12
|
+
|
13
|
+
# gets or sets the arguments for this event raise
|
14
|
+
attr_accessor :args
|
15
|
+
|
16
|
+
# gets or sets the block for this event raise
|
17
|
+
attr_accessor :handler
|
18
|
+
|
19
|
+
# Initializes a new instance of a method call recording
|
20
|
+
# every time a method gets called in an isolated object
|
21
|
+
# this gets stored in the method call recorder
|
22
|
+
# It expects a +method_name+ at the very least.
|
23
|
+
def initialize(event_name, count=0)
|
24
|
+
@event_name = event_name
|
25
|
+
@count = count
|
26
|
+
@variations = []
|
27
|
+
end
|
28
|
+
|
29
|
+
# add args
|
30
|
+
def args
|
31
|
+
@variations
|
32
|
+
end
|
33
|
+
|
34
|
+
# indicates if it has an argument variation
|
35
|
+
def has_argument_variations?
|
36
|
+
@variations.size > 1
|
37
|
+
end
|
38
|
+
|
39
|
+
# add an argument variation
|
40
|
+
def add_argument_variation(args, block)
|
41
|
+
variation = find_argument_variations args
|
42
|
+
if variation.empty?
|
43
|
+
@variations << ArgumentRecording.new(args, @variations.size+1, block) if variation == []
|
44
|
+
else
|
45
|
+
variation.first.call_number += 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# finds an argument variation that matches the provided +args+
|
50
|
+
def find_argument_variations(args)
|
51
|
+
return @variations if args.first.is_a?(Symbol) and args.last == :any
|
52
|
+
@variations.select { |ar| ar.args == args }
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class MethodCallRecorder
|
58
|
+
|
59
|
+
def event_raises
|
60
|
+
@event_raises ||= {}
|
61
|
+
end
|
62
|
+
|
63
|
+
def record_event_raise(event_name, mode, *args, &handler)
|
64
|
+
en_sym = event_name.to_sym
|
65
|
+
event_raises[mode] ||= {}
|
66
|
+
ev = (event_raises[mode][en_sym] ||= EventRaiseRecording.new(event_name))
|
67
|
+
ev.count += 1
|
68
|
+
ev.add_argument_variation args, handler
|
69
|
+
end
|
70
|
+
|
71
|
+
def event_error
|
72
|
+
@event_error
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns whether the event was actually raised with the specified constraints
|
76
|
+
def event_raised?(event_name, mode = :instance, *args)
|
77
|
+
mc = event_raises[mode][event_name.to_s.to_sym]
|
78
|
+
if mc
|
79
|
+
vari = mc.find_argument_variations(args)
|
80
|
+
result = vari.any? { |agv| agv == args }
|
81
|
+
return result if result
|
82
|
+
if args.size == 1 and args.last.is_a?(Hash)
|
83
|
+
result = vari.any? do |agv|
|
84
|
+
agv.args.last.is_a?(Hash) and args.last.all? { |k, v| agv.args.last[k] == v }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
@event_error = "Event Arguments don't match for #{event_name}.\n\nYou expected:\n#{args.join(", ")}.\n\nI did find the following variations:\n#{mc.args.collect {|ar| ar.args.join(', ') }.join(' and ')}" unless result
|
88
|
+
result
|
89
|
+
else
|
90
|
+
@event_error = "Couldn't find an event with name #{event_name}"
|
91
|
+
return !!mc
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
97
|
end
|
@@ -24,7 +24,7 @@ module Caricature
|
|
24
24
|
def find(method_name, mode=:instance, *args)
|
25
25
|
expectations = mode == :class ? @class_expectations : @instance_expectations
|
26
26
|
|
27
|
-
candidates = expectations.select { |exp| exp.method_name.to_s.
|
27
|
+
candidates = expectations.select { |exp| exp.method_name.to_s.underscore =~ /#{method_name}|#{method_name.to_s.underscore}/ }
|
28
28
|
with_arguments_candidates = candidates.select { |exp| exp.args == args }
|
29
29
|
|
30
30
|
with_arguments_candidates.first || candidates.select { |exp| exp.any_args? }.first
|
@@ -169,8 +169,8 @@ module Caricature
|
|
169
169
|
|
170
170
|
# records a method call or increments the count of how many times this method was called.
|
171
171
|
def record_call(method_name, mode=:instance, expectation=nil, *args, &block)
|
172
|
-
mn_sym = method_name.to_s.to_sym
|
173
|
-
method_calls[mode][mn_sym] ||= MethodCallRecording.new
|
172
|
+
mn_sym = method_name.to_s.underscore.to_sym
|
173
|
+
method_calls[mode][mn_sym] ||= MethodCallRecording.new mn_sym.to_s
|
174
174
|
mc = method_calls[mode][mn_sym]
|
175
175
|
mc.count += 1
|
176
176
|
agc = mc.add_argument_variation args, block
|
@@ -196,7 +196,7 @@ module Caricature
|
|
196
196
|
|
197
197
|
# returns whether the method was actually called with the specified constraints
|
198
198
|
def was_called?(method_name, block_args, mode=:instance, *args)
|
199
|
-
mc = method_calls[mode][method_name.to_s.to_sym]
|
199
|
+
mc = method_calls[mode][method_name.to_s.underscore.to_sym]
|
200
200
|
if mc
|
201
201
|
vari = mc.find_argument_variations(args, block_args)
|
202
202
|
result = vari.any? { |agv| agv == args }
|
@@ -1,118 +1,118 @@
|
|
1
|
-
module Caricature
|
2
|
-
module RSpecAdapter
|
3
|
-
|
4
|
-
def setup_mocks_for_rspec
|
5
|
-
# No setup required
|
6
|
-
end
|
7
|
-
|
8
|
-
def verify_mocks_for_rspec
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown_mocks_for_rspec
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module RSpecMatchers
|
16
|
-
|
17
|
-
class HaveReceived
|
18
|
-
def initialize(expected)
|
19
|
-
@expected = expected
|
20
|
-
@block_args, @error, @args = nil, "", [:any]
|
21
|
-
end
|
22
|
-
|
23
|
-
def matches?(target)
|
24
|
-
@target = target
|
25
|
-
|
26
|
-
veri = @target.did_receive?(@expected).with(*@args)
|
27
|
-
veri.with_block_args(*@block_args) if @block_args
|
28
|
-
result = veri.successful?
|
29
|
-
|
30
|
-
@error = "\n#{veri.error}" unless result
|
31
|
-
|
32
|
-
result
|
33
|
-
end
|
34
|
-
|
35
|
-
def failure_message_for_should
|
36
|
-
"expected #{@target.inspect} to have received #{@expected}" + @error
|
37
|
-
end
|
38
|
-
|
39
|
-
def failure_message_for_should_not
|
40
|
-
"expected #{@target.inspect} not to have received #{@expected}" + @error
|
41
|
-
end
|
42
|
-
|
43
|
-
# constrain this verification to the provided arguments
|
44
|
-
def with(*args)
|
45
|
-
ags = *args
|
46
|
-
@args = args
|
47
|
-
@args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
|
48
|
-
# @callback = b if b
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
def with_block_args(*args)
|
53
|
-
@block_args = args
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
# allow any arguments ignore the argument constraint
|
58
|
-
def allow_any_arguments
|
59
|
-
@args = :any
|
60
|
-
self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class HaveRaised
|
65
|
-
def initialize(expected)
|
66
|
-
@expected = expected
|
67
|
-
@block_args, @error, @args = nil, "", [:any]
|
68
|
-
end
|
69
|
-
|
70
|
-
def matches?(target)
|
71
|
-
@target = target
|
72
|
-
|
73
|
-
veri = @target.did_raise_event?(@expected).with(*@args)
|
74
|
-
result = veri.successful?
|
75
|
-
|
76
|
-
@error = "\n#{veri.error}" unless result
|
77
|
-
|
78
|
-
result
|
79
|
-
end
|
80
|
-
|
81
|
-
def failure_message_for_should
|
82
|
-
"expected #{@target.inspect} to have received #{@expected}" + @error
|
83
|
-
end
|
84
|
-
|
85
|
-
def failure_message_for_should_not
|
86
|
-
"expected #{@target.inspect} not to have received #{@expected}" + @error
|
87
|
-
end
|
88
|
-
|
89
|
-
# constrain this verification to the provided arguments
|
90
|
-
def with(*args)
|
91
|
-
ags = *args
|
92
|
-
@args = args
|
93
|
-
@args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
|
94
|
-
# @callback = b if b
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
# allow any arguments ignore the argument constraint
|
99
|
-
def allow_any_arguments
|
100
|
-
@args = :any
|
101
|
-
self
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def have_received(method_name, *args)
|
106
|
-
HaveReceived.new(method_name).with(*args)
|
107
|
-
end
|
108
|
-
|
109
|
-
def have_raised(event_name, *args)
|
110
|
-
HaveRaised.new(event_name).with(*args)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
#Spec::Runner.configure do |config|
|
116
|
-
# config.mock_with Caricature::RSpecAdapter
|
117
|
-
# config.include Caricature::RSpecMatchers
|
118
|
-
#end
|
1
|
+
module Caricature
|
2
|
+
module RSpecAdapter
|
3
|
+
|
4
|
+
def setup_mocks_for_rspec
|
5
|
+
# No setup required
|
6
|
+
end
|
7
|
+
|
8
|
+
def verify_mocks_for_rspec
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown_mocks_for_rspec
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module RSpecMatchers
|
16
|
+
|
17
|
+
class HaveReceived
|
18
|
+
def initialize(expected)
|
19
|
+
@expected = expected
|
20
|
+
@block_args, @error, @args = nil, "", [:any]
|
21
|
+
end
|
22
|
+
|
23
|
+
def matches?(target)
|
24
|
+
@target = target
|
25
|
+
|
26
|
+
veri = @target.did_receive?(@expected).with(*@args)
|
27
|
+
veri.with_block_args(*@block_args) if @block_args
|
28
|
+
result = veri.successful?
|
29
|
+
|
30
|
+
@error = "\n#{veri.error}" unless result
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def failure_message_for_should
|
36
|
+
"expected #{@target.inspect} to have received #{@expected}" + @error
|
37
|
+
end
|
38
|
+
|
39
|
+
def failure_message_for_should_not
|
40
|
+
"expected #{@target.inspect} not to have received #{@expected}" + @error
|
41
|
+
end
|
42
|
+
|
43
|
+
# constrain this verification to the provided arguments
|
44
|
+
def with(*args)
|
45
|
+
ags = *args
|
46
|
+
@args = args
|
47
|
+
@args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
|
48
|
+
# @callback = b if b
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_block_args(*args)
|
53
|
+
@block_args = args
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
# allow any arguments ignore the argument constraint
|
58
|
+
def allow_any_arguments
|
59
|
+
@args = :any
|
60
|
+
self
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class HaveRaised
|
65
|
+
def initialize(expected)
|
66
|
+
@expected = expected
|
67
|
+
@block_args, @error, @args = nil, "", [:any]
|
68
|
+
end
|
69
|
+
|
70
|
+
def matches?(target)
|
71
|
+
@target = target
|
72
|
+
|
73
|
+
veri = @target.did_raise_event?(@expected).with(*@args)
|
74
|
+
result = veri.successful?
|
75
|
+
|
76
|
+
@error = "\n#{veri.error}" unless result
|
77
|
+
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
def failure_message_for_should
|
82
|
+
"expected #{@target.inspect} to have received #{@expected}" + @error
|
83
|
+
end
|
84
|
+
|
85
|
+
def failure_message_for_should_not
|
86
|
+
"expected #{@target.inspect} not to have received #{@expected}" + @error
|
87
|
+
end
|
88
|
+
|
89
|
+
# constrain this verification to the provided arguments
|
90
|
+
def with(*args)
|
91
|
+
ags = *args
|
92
|
+
@args = args
|
93
|
+
@args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
|
94
|
+
# @callback = b if b
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
# allow any arguments ignore the argument constraint
|
99
|
+
def allow_any_arguments
|
100
|
+
@args = :any
|
101
|
+
self
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def have_received(method_name, *args)
|
106
|
+
HaveReceived.new(method_name).with(*args)
|
107
|
+
end
|
108
|
+
|
109
|
+
def have_raised(event_name, *args)
|
110
|
+
HaveRaised.new(event_name).with(*args)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#Spec::Runner.configure do |config|
|
116
|
+
# config.mock_with Caricature::RSpecAdapter
|
117
|
+
# config.include Caricature::RSpecMatchers
|
118
|
+
#end
|
data/lib/caricature/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
module Caricature
|
2
|
-
|
3
|
-
# The version number of the +Caricature+ library
|
4
|
-
VERSION = '0.7.
|
5
|
-
|
1
|
+
module Caricature
|
2
|
+
|
3
|
+
# The version number of the +Caricature+ library
|
4
|
+
VERSION = '0.7.6'
|
5
|
+
|
6
6
|
end
|
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 isolate(subject, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new)
|
22
|
-
Caricature::Isolation.for(subject, recorder, expectations)
|
23
|
-
end
|
24
|
-
alias :mock :isolate
|
25
|
-
alias :stub :isolate
|
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 isolate(subject, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new)
|
22
|
+
Caricature::Isolation.for(subject, recorder, expectations)
|
23
|
+
end
|
24
|
+
alias :mock :isolate
|
25
|
+
alias :stub :isolate
|