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
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
describe "String" do
|
4
4
|
|
@@ -19,23 +19,23 @@ describe "Module" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should identify it's not a CLR type for a Ruby defined module" do
|
22
|
-
Caricature.
|
22
|
+
Caricature.clr_type?.should.be.false?
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should identify it's a CLR type for a CLR defined interface" do
|
26
|
-
ClrModels::IExposingWarrior.
|
26
|
+
ClrModels::IExposingWarrior.clr_type?.should.be.true?
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should identify it's a CLR type for a Ruby defined module that includes a CLR interface" do
|
30
|
-
Caricature::InterfaceIncludingModule.
|
30
|
+
Caricature::InterfaceIncludingModule.clr_type?.should.be.true?
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should identify it's not a CLR type for a Ruby defined module that includes a Ruby module" do
|
34
|
-
Caricature::RubyModuleIncludingModule.
|
34
|
+
Caricature::RubyModuleIncludingModule.clr_type?.should.be.false?
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should identify it's a CLR type when an ancestor includes a CLR interface" do
|
38
|
-
Caricature::InterfaceUpTheWazoo.
|
38
|
+
Caricature::InterfaceUpTheWazoo.clr_type?.should.be.true?
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -47,31 +47,31 @@ describe "Class" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should identify it's not a CLR type for a ruby defined type" do
|
50
|
-
Soldier.
|
50
|
+
Soldier.clr_type?.should.be.false?
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should identify it's not a CLR type for a ruby defined type that subclasses a Ruby class" do
|
54
|
-
Caricature::SubclassingRubyClass.
|
54
|
+
Caricature::SubclassingRubyClass.clr_type?.should.be.false?
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should identify it's not a CLR type for a ruby defined type that includes only ruby modueles in its hierarchy" do
|
58
|
-
Caricature::ModuleIncludingClass.
|
58
|
+
Caricature::ModuleIncludingClass.clr_type?.should.be.false?
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should identify it's a CLR type for a type defined in C#" do
|
62
|
-
ClrModels::Ninja.
|
62
|
+
ClrModels::Ninja.clr_type?.should.be.true?
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface" do
|
66
|
-
Caricature::InterfaceIncludingClass.
|
66
|
+
Caricature::InterfaceIncludingClass.clr_type?.should.be.true?
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should identify it's a CLR type for a type defined in Ruby that subclasses a CLR class" do
|
70
|
-
Caricature::SubClassingClrClass.
|
70
|
+
Caricature::SubClassingClrClass.clr_type?.should.be.true?
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should identify it's a CLR type for a type defined in Ruby that includes a CLR interface in its hierarchy" do
|
74
|
-
Caricature::InterfaceUpTheWazooClass.
|
74
|
+
Caricature::InterfaceUpTheWazooClass.clr_type?.should.be.true?
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
describe "Event handling" do
|
4
4
|
|
@@ -30,12 +30,12 @@ describe "Event handling" do
|
|
30
30
|
describe "for an IR generated interface proxy" do
|
31
31
|
|
32
32
|
before do
|
33
|
-
@proxy =
|
33
|
+
@proxy = isolate ClrModels::IExposingWarrior
|
34
34
|
end
|
35
35
|
|
36
36
|
# apparently events don't work yet in IronRuby.. keeping this spec here to find out when it does
|
37
37
|
# it "should not raise an error when subcribing to an event" do
|
38
|
-
# lambda { ClrModels::ExposedChangedSubscriber.new(@proxy
|
38
|
+
# lambda { ClrModels::ExposedChangedSubscriber.new(@proxy) }.should.not.raise
|
39
39
|
# end
|
40
40
|
|
41
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
describe "MethodCallRecorder" do
|
4
4
|
|
@@ -305,7 +305,7 @@ describe "MethodCallRecorder" do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
it "should be negative when we provide the wrong arguments" do
|
308
|
-
|
308
|
+
@recorder.was_called?(:my_method, nil, :instance, 1, 2, 5).should.be.false?
|
309
309
|
end
|
310
310
|
|
311
311
|
it "should be positive when we provide the correct arguments" do
|
data/spec/bin/ClrModels.dll
CHANGED
Binary file
|
Binary file
|
@@ -1,20 +1,3 @@
|
|
1
|
-
# add some search paths to ironruby
|
2
|
-
# this first one adds the path with the assemblies
|
3
|
-
# this enables us not to have to specify a path to the assemblies everywhere.
|
4
|
-
$: << File.dirname(__FILE__) + "/bin"
|
5
|
-
# adds the path to the caricature library.
|
6
|
-
$: << File.dirname(__FILE__) + "/../lib"
|
7
|
-
|
8
|
-
# load the caricature library
|
9
|
-
require "caricature"
|
10
|
-
|
11
|
-
require 'rubygems'
|
12
|
-
# load the bacon library
|
13
|
-
require 'bacon'
|
14
|
-
|
15
|
-
# load the assembly with the C# code
|
16
|
-
require 'ClrModels.dll' if defined? IRONRUBY_VERSION
|
17
|
-
|
18
1
|
class Soldier
|
19
2
|
|
20
3
|
def initialize
|
@@ -74,7 +57,7 @@ class Dagger
|
|
74
57
|
end
|
75
58
|
|
76
59
|
def attack(target)
|
77
|
-
target.survive_attack_with self
|
60
|
+
target.survive_attack_with self
|
78
61
|
end
|
79
62
|
|
80
63
|
|
@@ -102,21 +85,21 @@ class WithClassMethods
|
|
102
85
|
"Goodbye world!"
|
103
86
|
end
|
104
87
|
|
105
|
-
end
|
88
|
+
end
|
106
89
|
|
107
90
|
class Sheath
|
108
91
|
attr_reader :dagger
|
109
|
-
|
92
|
+
|
110
93
|
def initialize(dagger)
|
111
94
|
@dagger = dagger
|
112
|
-
end
|
113
|
-
|
95
|
+
end
|
96
|
+
|
114
97
|
def insert(dagger)
|
115
98
|
raise "There is already a dagger in here" if @dagger
|
116
99
|
@dagger = dagger
|
117
|
-
end
|
118
|
-
|
119
|
-
def draw
|
100
|
+
end
|
101
|
+
|
102
|
+
def draw
|
120
103
|
raise "Dagger is nowhere to be found" unless @dagger
|
121
104
|
d = @dagger
|
122
105
|
@dagger = nil
|
@@ -133,7 +116,7 @@ if defined? IRONRUBY_VERSION
|
|
133
116
|
end
|
134
117
|
|
135
118
|
module PureRubyModule
|
136
|
-
|
119
|
+
|
137
120
|
end
|
138
121
|
|
139
122
|
module RubyModuleIncludingModule
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "Callbacks on expectations" do
|
4
|
+
|
5
|
+
describe "CLR to CLR interactions" do
|
6
|
+
|
7
|
+
describe "when isolating CLR interfaces" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@ninja = ClrModels::Ninja.new
|
11
|
+
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should execute the callback when the expectation is invoked" do
|
15
|
+
ninja = ClrModels::Ninja.new
|
16
|
+
cnt = 0
|
17
|
+
@weapon.when_receiving(:attack).with(:any) do |*args|
|
18
|
+
cnt += 1
|
19
|
+
end
|
20
|
+
@ninja.attack ninja, @weapon
|
21
|
+
|
22
|
+
cnt.should == 1
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when isolating CLR classes" do
|
28
|
+
|
29
|
+
before do
|
30
|
+
@ninja = ClrModels::Ninja.new
|
31
|
+
@weapon = Caricature::Isolation.for(ClrModels::Sword)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should execute the callback when the expectation is invoked" do
|
35
|
+
ninja = ClrModels::Ninja.new
|
36
|
+
cnt = 0
|
37
|
+
@weapon.when_receiving(:attack).with(:any) do |*args|
|
38
|
+
cnt += 1
|
39
|
+
end
|
40
|
+
@ninja.attack ninja, @weapon
|
41
|
+
|
42
|
+
cnt.should == 1
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when isolating CLR instances" do
|
48
|
+
before do
|
49
|
+
@ninja = ClrModels::Ninja.new
|
50
|
+
@weapon = Caricature::Isolation.for(ClrModels::Sword.new)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should execute the callback when the expectation is invoked" do
|
54
|
+
ninja = ClrModels::Ninja.new
|
55
|
+
cnt = 0
|
56
|
+
@weapon.when_receiving(:attack).with(ninja) do |*args|
|
57
|
+
cnt += 1
|
58
|
+
end
|
59
|
+
@ninja.attack ninja, @weapon
|
60
|
+
|
61
|
+
cnt.should == 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "CLR to ruby interactions" do
|
68
|
+
|
69
|
+
describe "when isolating CLR interfaces" do
|
70
|
+
|
71
|
+
before do
|
72
|
+
@ninja = Soldier.new
|
73
|
+
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should execute the callback when the expectation is invoked" do
|
77
|
+
ninja = Soldier.new
|
78
|
+
cnt = 0
|
79
|
+
@weapon.when_receiving(:attack).with(:any) do |*args|
|
80
|
+
cnt += 1
|
81
|
+
end
|
82
|
+
@ninja.attack ninja, @weapon
|
83
|
+
|
84
|
+
cnt.should == 1
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "when isolating CLR classes" do
|
90
|
+
|
91
|
+
before do
|
92
|
+
@ninja = Soldier.new
|
93
|
+
@weapon = Caricature::Isolation.for(ClrModels::Sword)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should execute the callback when the expectation is invoked" do
|
97
|
+
ninja = Soldier.new
|
98
|
+
cnt = 0
|
99
|
+
@weapon.when_receiving(:attack).with(:any) do |*args|
|
100
|
+
cnt += 1
|
101
|
+
end
|
102
|
+
@ninja.attack ninja, @weapon
|
103
|
+
|
104
|
+
cnt.should == 1
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "when isolating CLR instances" do
|
110
|
+
before do
|
111
|
+
@ninja = Soldier.new
|
112
|
+
@weapon = Caricature::Isolation.for(ClrModels::Sword.new)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should execute the callback when the expectation is invoked" do
|
116
|
+
ninja = Soldier.new
|
117
|
+
cnt = 0
|
118
|
+
@weapon.when_receiving(:attack).with(ninja) do |*args|
|
119
|
+
cnt += 1
|
120
|
+
end
|
121
|
+
@ninja.attack ninja, @weapon
|
122
|
+
|
123
|
+
cnt.should == 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "Ruby to Ruby interactions" do
|
131
|
+
|
132
|
+
it "should execute a callback when an expectation is being invoked and with is not defined in a block" do
|
133
|
+
iso = Caricature::Isolation.for(Dagger)
|
134
|
+
cnt = 0
|
135
|
+
iso.when_receiving(:damage).with(:any) do |*args|
|
136
|
+
cnt += 1
|
137
|
+
end
|
138
|
+
iso.damage
|
139
|
+
cnt.should == 1
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should execute a callback when an expectation is being invoked and with is defined in a block" do
|
143
|
+
cnt = 0
|
144
|
+
iso = Caricature::Isolation.for(Dagger)
|
145
|
+
iso.when_receiving(:damage) do |exp|
|
146
|
+
exp.with(:any) do |*args|
|
147
|
+
cnt += 1
|
148
|
+
end
|
149
|
+
end
|
150
|
+
iso.damage
|
151
|
+
cnt.should == 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "CLR to CLR interactions" do
|
4
|
+
|
5
|
+
describe "when isolating CLR interfaces" do
|
6
|
+
before do
|
7
|
+
@ninja = ClrModels::Ninja.new
|
8
|
+
@weapon = Caricature::Isolation.for(ClrModels::IWeapon)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should work without expectations" do
|
12
|
+
@ninja.attack ClrModels::Ninja.new, @weapon
|
13
|
+
|
14
|
+
@weapon.did_receive?(:attack).should be_successful
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work for expectations with an argument constraint" do
|
18
|
+
ninja = ClrModels::Ninja.new
|
19
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
20
|
+
|
21
|
+
@ninja.attack(ninja, @weapon).should == 5
|
22
|
+
|
23
|
+
@weapon.did_receive?(:attack).with(:any).should be_successful
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
27
|
+
@weapon.when_receiving(:attack).with(ClrModels::Ninja.new).return(5)
|
28
|
+
|
29
|
+
@ninja.attack(ClrModels::Ninja.new, @weapon).should == 0
|
30
|
+
#@ninja.attack(ClrModels::Ninja.new, ClrModels::Sword.new).should == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
34
|
+
ninja = ClrModels::Ninja.new
|
35
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
36
|
+
|
37
|
+
@ninja.attack(ninja, @weapon).should == 5
|
38
|
+
|
39
|
+
@weapon.did_receive?(:attack).with(ninja).should be_successful
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
43
|
+
ninja = ClrModels::Ninja.new
|
44
|
+
@weapon.when_receiving(:attack).with(ninja).return(5)
|
45
|
+
|
46
|
+
@ninja.attack(ninja, @weapon).should == 5
|
47
|
+
|
48
|
+
@weapon.did_receive?(:attack).with(ClrModels::Ninja.new).should_not be_successful
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should work with an expectation with any arguments" do
|
52
|
+
@weapon.when_receiving(:damage).return(5)
|
53
|
+
|
54
|
+
@ninja.is_killed_by(@weapon).should be_true
|
55
|
+
@weapon.did_receive?(:damage).should be_successful
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should work with an expectation getting different method call result" do
|
59
|
+
@weapon.when_receiving(:damage).return(2)
|
60
|
+
|
61
|
+
@ninja.is_killed_by(@weapon).should be_false
|
62
|
+
@weapon.did_receive?(:damage).should be_successful
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should work for an assertion on a specific argument" do
|
66
|
+
@weapon.when_receiving(:damage).return(2)
|
67
|
+
|
68
|
+
@ninja.is_killed_by(@weapon).should be_false
|
69
|
+
@weapon.did_receive?(:damage).should be_successful
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "when isolating CLR classes" do
|
75
|
+
|
76
|
+
describe "plain vanilla CLR classes" do
|
77
|
+
before do
|
78
|
+
@weapon = ClrModels::Sword.new
|
79
|
+
@ninja = Caricature::Isolation.for(ClrModels::Ninja)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should work without expectations" do
|
83
|
+
result = @weapon.attack @ninja
|
84
|
+
result.should == 0
|
85
|
+
|
86
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should work for expectations with an argument constraint" do
|
90
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
91
|
+
|
92
|
+
@weapon.attack(@ninja).should == 5
|
93
|
+
|
94
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
98
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
99
|
+
|
100
|
+
@weapon.attack(ClrModels::Ninja.new).should == 6
|
101
|
+
|
102
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should_not be_successful
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
106
|
+
ninja = ClrModels::Ninja.new
|
107
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
108
|
+
|
109
|
+
@weapon.attack(@ninja).should == 5
|
110
|
+
|
111
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
115
|
+
ninja = ClrModels::Ninja.new
|
116
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
117
|
+
|
118
|
+
@weapon.attack(@ninja).should == 5
|
119
|
+
|
120
|
+
@ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should_not be_successful
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should work with an expectation for any arguments" do
|
124
|
+
@ninja.when_receiving(:survive_attack_with).return(5)
|
125
|
+
|
126
|
+
result = @weapon.attack @ninja
|
127
|
+
result.should == 5
|
128
|
+
|
129
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should work with an assertion for specific arguments" do
|
133
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
134
|
+
method_should.return(5)
|
135
|
+
end
|
136
|
+
|
137
|
+
result = @weapon.attack @ninja
|
138
|
+
result.should == 5
|
139
|
+
|
140
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should fail for an assertion with wrong arguments" do
|
144
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
145
|
+
method_should.return(5)
|
146
|
+
end
|
147
|
+
|
148
|
+
result = @weapon.attack @ninja
|
149
|
+
result.should == 5
|
150
|
+
|
151
|
+
@ninja.
|
152
|
+
did_receive?(:survive_attack_with).
|
153
|
+
with(Caricature::Isolation.for(ClrModels::IWeapon)).
|
154
|
+
should_not be_successful
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "that have an indexer" do
|
160
|
+
before do
|
161
|
+
@cons = ClrModels::IndexerCaller.new
|
162
|
+
@ind = Caricature::Isolation.for(ClrModels::IndexerContained)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should work without expectations" do
|
166
|
+
@cons.call_index_on_class(@ind, "key1").should be_nil
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "when isolating CLR instances" do
|
175
|
+
|
176
|
+
before do
|
177
|
+
@weapon = ClrModels::Sword.new
|
178
|
+
@ninja = Caricature::Isolation.for(ClrModels::Ninja.new)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should work without expectations" do
|
182
|
+
result = @weapon.attack @ninja
|
183
|
+
result.should == 0
|
184
|
+
|
185
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should work for expectations with an argument constraint" do
|
189
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
190
|
+
|
191
|
+
@weapon.attack(@ninja).should == 5
|
192
|
+
|
193
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should work for expectations with an argument constraint when a wrong argument is passed in" do
|
197
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
198
|
+
|
199
|
+
@weapon.attack(ClrModels::Ninja.new).should == 6
|
200
|
+
|
201
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should_not be_successful
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should work for expectations with an argument constraint and an assertion argument constraint" do
|
205
|
+
ninja = ClrModels::Ninja.new
|
206
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
207
|
+
|
208
|
+
@weapon.attack(@ninja).should == 5
|
209
|
+
|
210
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should fail for expectations with an argument constraint and an assertion argument constraint" do
|
214
|
+
ninja = ClrModels::Ninja.new
|
215
|
+
@ninja.when_receiving(:survive_attack_with).with(@weapon).return(5)
|
216
|
+
|
217
|
+
@weapon.attack(@ninja).should == 5
|
218
|
+
|
219
|
+
@ninja.did_receive?(:survive_attack_with).with(ClrModels::Sword.new).should_not be_successful
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should work with an expectation for any arguments" do
|
223
|
+
@ninja.when_receiving(:survive_attack_with).return(5)
|
224
|
+
|
225
|
+
result = @weapon.attack @ninja
|
226
|
+
result.should == 5
|
227
|
+
|
228
|
+
@ninja.did_receive?(:survive_attack_with).with(:any).should be_successful
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should fail for an assertion for specific arguments" do
|
232
|
+
@ninja.when_receiving(:survive_attack_with) do |method_should|
|
233
|
+
method_should.return(5)
|
234
|
+
end
|
235
|
+
|
236
|
+
result = @weapon.attack @ninja
|
237
|
+
result.should == 5
|
238
|
+
var = @ninja.did_receive?(:survive_attack_with).with(:any)
|
239
|
+
@ninja.did_receive?(:survive_attack_with).with(@weapon).should be_successful
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should allow to delegate the method call to the real instance (partial mock)" do
|
243
|
+
@ninja.when_receiving(:survive_attack_with).super_after
|
244
|
+
|
245
|
+
result = @weapon.attack @ninja
|
246
|
+
result.should == 6
|
247
|
+
|
248
|
+
@ninja.did_receive?(:survive_attack_with).should be_successful
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|