caricature 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.gitignore +4 -0
  2. data/Rakefile +100 -0
  3. data/VERSION +1 -0
  4. data/caricature.gemspec +177 -0
  5. data/doc/Array.html +251 -0
  6. data/doc/Caricature/ArgumentRecording.html +366 -0
  7. data/doc/Caricature/ClrClassDescriptor.html +303 -0
  8. data/doc/Caricature/ClrClassMessenger.html +263 -0
  9. data/doc/Caricature/ClrInterfaceDescriptor.html +295 -0
  10. data/doc/Caricature/ClrInterfaceIsolator.html +365 -0
  11. data/doc/Caricature/ClrInterfaceMessenger.html +260 -0
  12. data/doc/Caricature/ClrIsolator.html +424 -0
  13. data/doc/Caricature/Expectation.html +549 -0
  14. data/doc/Caricature/ExpectationBuilder.html +308 -0
  15. data/doc/Caricature/ExpectationSyntax.html +438 -0
  16. data/doc/Caricature/Expectations.html +344 -0
  17. data/doc/Caricature/Interception/ClassMethods.html +246 -0
  18. data/doc/Caricature/Interception.html +416 -0
  19. data/doc/Caricature/Isolation.html +578 -0
  20. data/doc/Caricature/Isolator.html +519 -0
  21. data/doc/Caricature/MemberDescriptor.html +335 -0
  22. data/doc/Caricature/Messenger.html +335 -0
  23. data/doc/Caricature/MethodCallRecorder.html +440 -0
  24. data/doc/Caricature/MethodCallRecording.html +493 -0
  25. data/doc/Caricature/RubyIsolator.html +416 -0
  26. data/doc/Caricature/RubyMessenger.html +260 -0
  27. data/doc/Caricature/RubyObjectDescriptor.html +289 -0
  28. data/doc/Caricature/TypeDescriptor.html +378 -0
  29. data/doc/Caricature/Verification.html +443 -0
  30. data/doc/Caricature.html +358 -0
  31. data/doc/Class.html +287 -0
  32. data/doc/Hash.html +255 -0
  33. data/doc/Module.html +287 -0
  34. data/doc/Object.html +322 -0
  35. data/doc/README_markdown.html +241 -0
  36. data/doc/String.html +289 -0
  37. data/doc/System/String.html +289 -0
  38. data/doc/System/Type.html +289 -0
  39. data/doc/System.html +207 -0
  40. data/doc/created.rid +1 -0
  41. data/doc/images/brick.png +0 -0
  42. data/doc/images/brick_link.png +0 -0
  43. data/doc/images/bug.png +0 -0
  44. data/doc/images/bullet_black.png +0 -0
  45. data/doc/images/bullet_toggle_minus.png +0 -0
  46. data/doc/images/bullet_toggle_plus.png +0 -0
  47. data/doc/images/date.png +0 -0
  48. data/doc/images/find.png +0 -0
  49. data/doc/images/loadingAnimation.gif +0 -0
  50. data/doc/images/macFFBgHack.png +0 -0
  51. data/doc/images/package.png +0 -0
  52. data/doc/images/page_green.png +0 -0
  53. data/doc/images/page_white_text.png +0 -0
  54. data/doc/images/page_white_width.png +0 -0
  55. data/doc/images/plugin.png +0 -0
  56. data/doc/images/ruby.png +0 -0
  57. data/doc/images/tag_green.png +0 -0
  58. data/doc/images/wrench.png +0 -0
  59. data/doc/images/wrench_orange.png +0 -0
  60. data/doc/images/zoom.png +0 -0
  61. data/doc/index.html +312 -0
  62. data/doc/js/darkfish.js +116 -0
  63. data/doc/js/jquery.js +32 -0
  64. data/doc/js/quicksearch.js +114 -0
  65. data/doc/js/thickbox-compressed.js +10 -0
  66. data/doc/lib/caricature/clr/descriptor_rb.html +52 -0
  67. data/doc/lib/caricature/clr/isolation_rb.html +52 -0
  68. data/doc/lib/caricature/clr/isolator_rb.html +52 -0
  69. data/doc/lib/caricature/clr/messenger_rb.html +52 -0
  70. data/doc/lib/caricature/clr_rb.html +52 -0
  71. data/doc/lib/caricature/descriptor_rb.html +52 -0
  72. data/doc/lib/caricature/expectation_rb.html +52 -0
  73. data/doc/lib/caricature/isolation_rb.html +52 -0
  74. data/doc/lib/caricature/isolator_rb.html +52 -0
  75. data/doc/lib/caricature/messaging_rb.html +52 -0
  76. data/doc/lib/caricature/method_call_recorder_rb.html +52 -0
  77. data/doc/lib/caricature/verification_rb.html +52 -0
  78. data/doc/lib/caricature_rb.html +52 -0
  79. data/doc/lib/core_ext/array_rb.html +52 -0
  80. data/doc/lib/core_ext/class_rb.html +52 -0
  81. data/doc/lib/core_ext/core_ext_rb.html +52 -0
  82. data/doc/lib/core_ext/hash_rb.html +52 -0
  83. data/doc/lib/core_ext/module_rb.html +52 -0
  84. data/doc/lib/core_ext/object_rb.html +52 -0
  85. data/doc/lib/core_ext/string_rb.html +52 -0
  86. data/doc/lib/core_ext/system/string_rb.html +52 -0
  87. data/doc/lib/core_ext/system/type_rb.html +52 -0
  88. data/doc/rdoc.css +696 -0
  89. data/irb_init.rb +9 -0
  90. data/lib/bin/Workarounds.dll +0 -0
  91. data/lib/bin/Workarounds.pdb +0 -0
  92. data/lib/caricature/clr/descriptor.rb +55 -0
  93. data/lib/caricature/clr/isolation.rb +33 -0
  94. data/lib/caricature/clr/isolator.rb +112 -0
  95. data/lib/caricature/clr/messenger.rb +46 -0
  96. data/lib/caricature/clr.rb +6 -0
  97. data/lib/caricature/descriptor.rb +74 -0
  98. data/lib/caricature/expectation.rb +159 -0
  99. data/lib/caricature/isolation.rb +146 -0
  100. data/lib/caricature/isolator.rb +287 -0
  101. data/lib/caricature/messenger.rb +57 -0
  102. data/lib/caricature/method_call_recorder.rb +130 -0
  103. data/lib/caricature/verification.rb +43 -0
  104. data/lib/caricature.rb +11 -0
  105. data/lib/core_ext/array.rb +10 -0
  106. data/lib/core_ext/class.rb +15 -0
  107. data/lib/core_ext/core_ext.rb +8 -0
  108. data/lib/core_ext/hash.rb +13 -0
  109. data/lib/core_ext/module.rb +15 -0
  110. data/lib/core_ext/object.rb +19 -0
  111. data/lib/core_ext/string.rb +17 -0
  112. data/lib/core_ext/system/string.rb +21 -0
  113. data/lib/core_ext/system/type.rb +21 -0
  114. data/pkg/.gitignore +0 -0
  115. data/pkg/caricature-0.1.0.gem +0 -0
  116. data/spec/bacon_helper.rb +49 -3
  117. data/spec/bin/.gitignore +0 -0
  118. data/spec/core_ext_spec.rb +9 -0
  119. data/spec/descriptor_spec.rb +142 -0
  120. data/spec/expectation_spec.rb +11 -7
  121. data/spec/integration_spec.rb +94 -2
  122. data/spec/isolation_spec.rb +0 -42
  123. data/spec/isolator_spec.rb +72 -66
  124. data/spec/messaging_spec.rb +172 -0
  125. data/spec/method_call_spec.rb +21 -21
  126. data/spec/models/ClrModels.cs +185 -0
  127. data/spec/verification_spec.rb +1 -1
  128. data/workarounds/ReflectionHelper.cs +30 -0
  129. metadata +133 -2
data/spec/bacon_helper.rb CHANGED
@@ -2,12 +2,10 @@ $: << File.dirname(__FILE__) + "/bin"
2
2
  $: << File.dirname(__FILE__) + "/../lib"
3
3
 
4
4
  require "caricature"
5
+ require 'caricature/clr'
5
6
  require 'bacon'
6
7
  require 'mscorlib'
7
8
 
8
-
9
-
10
-
11
9
  load_assembly 'ClrModels'
12
10
 
13
11
  class Soldier
@@ -38,6 +36,30 @@ class Soldier
38
36
 
39
37
  end
40
38
 
39
+ class SoldierWithClassMembers
40
+ def initialize
41
+ @life = 10
42
+ end
43
+ def name
44
+ "Tommy Boy"
45
+ end
46
+ def to_s
47
+ "I'm a soldier"
48
+ end
49
+ def attack(target, weapon)
50
+ weapon.attack(target)
51
+ end
52
+ def is_killed_by?(weapon)
53
+ weapon.damage > 3
54
+ end
55
+ def survive_attack_with(weapon)
56
+ @life - weapon.damage
57
+ end
58
+ def self.class_name
59
+ "DaggerWithClassMembers"
60
+ end
61
+ end
62
+
41
63
  class Dagger
42
64
 
43
65
  def damage
@@ -51,6 +73,30 @@ class Dagger
51
73
 
52
74
  end
53
75
 
76
+ class DaggerWithClassMembers
77
+ def damage
78
+ 2
79
+ end
80
+ def attack(target)
81
+ target.survive_attack_with self
82
+ end
83
+ def self.class_name
84
+ "DaggerWithClassMembers"
85
+ end
86
+ end
87
+
88
+ class WithClassMethods
89
+
90
+ def hello_world
91
+ "Hello World!"
92
+ end
93
+
94
+ def self.good_bye_world
95
+ "Goodbye world!"
96
+ end
97
+
98
+ end
99
+
54
100
  module Caricature
55
101
 
56
102
  module InterfaceIncludingModule
File without changes
@@ -76,3 +76,12 @@ describe "Class" do
76
76
 
77
77
  end
78
78
 
79
+ describe "Array" do
80
+
81
+ it "should convert an array to a hash" do
82
+ expected = { :key1 => "value1", :key2 => "value2"}
83
+ %w(key1 value1 key2 value2).to_h.should.equal expected
84
+ end
85
+
86
+ end
87
+
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + "/bacon_helper"
2
+
3
+ describe "Caricature::TypeDescriptor" do
4
+
5
+ before do
6
+ @des = Caricature::TypeDescriptor.new :in_unit_test_for_class
7
+ end
8
+
9
+ it "should have a class_members method" do
10
+ @des.should.respond_to?(:class_members)
11
+ end
12
+
13
+ it "should return an empty collection for the class members" do
14
+ @des.class_members.should.be.empty
15
+ end
16
+
17
+ it "should have an instance members method" do
18
+ @des.should.respond_to?(:instance_members)
19
+ end
20
+
21
+ it "should return an empty collection for the instance members" do
22
+ @des.instance_members.should.be.empty
23
+ end
24
+
25
+ it "should raise a NotImplementedError for the initialize_instance_members method" do
26
+ lambda { @des.initialize_instance_members_for Soldier }.should.raise NotImplementedError
27
+ end
28
+
29
+ it "should raise a NotImplementedError for the initialize_class_members method" do
30
+ lambda { @des.initialize_class_members_for Soldier }.should.raise NotImplementedError
31
+ end
32
+
33
+ end
34
+
35
+ describe "Caricature::MemberDescriptor" do
36
+
37
+ it "should have a name" do
38
+ des = Caricature::MemberDescriptor.new 'a name', 'a type'
39
+ des.name.should.not.be.nil
40
+ end
41
+
42
+ it "should have the correct name" do
43
+ des = Caricature::MemberDescriptor.new 'a name', 'a type'
44
+ des.name.should.equal 'a name'
45
+ end
46
+
47
+ it "should have a return_type" do
48
+ des = Caricature::MemberDescriptor.new 'a name', 'a type'
49
+ des.return_type.should.not.be.nil
50
+ end
51
+
52
+ it "should have the correct return_type" do
53
+ des = Caricature::MemberDescriptor.new 'a name', 'a type'
54
+ des.return_type.should.equal 'a type'
55
+ end
56
+
57
+ it "should say it's an instance type" do
58
+ des = Caricature::MemberDescriptor.new 'a name', 'a type'
59
+ des.should.be.instance_member
60
+ end
61
+
62
+ it "should say it's not an instance type" do
63
+ des = Caricature::MemberDescriptor.new 'a name', 'a type', false
64
+ des.should.not.be.instance_member
65
+ end
66
+
67
+ end
68
+
69
+ describe "Caricature::ClrInterfaceDescriptor" do
70
+
71
+ before do
72
+ @des = Caricature::ClrInterfaceDescriptor.new ClrModels::IWeapon
73
+ end
74
+
75
+ it "should have 2 instance members" do
76
+ @des.instance_members.size.should.equal 2
77
+ end
78
+
79
+ it "should contain only instance members" do
80
+ result = true
81
+ @des.instance_members.each do |mem|
82
+ result = false unless mem.instance_member?
83
+ end
84
+
85
+ result.should.be.true
86
+ end
87
+
88
+ it "should have a damage instance member" do
89
+ @des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
90
+ end
91
+
92
+ end
93
+
94
+ describe "Caricature::ClrClassDescriptor" do
95
+
96
+ before do
97
+ @des = Caricature::ClrClassDescriptor.new ClrModels::SwordWithStatics
98
+ end
99
+
100
+ it "should have 11 instance members" do
101
+ @des.instance_members.size.should.equal 11
102
+ end
103
+
104
+ it "should have 5 static members" do
105
+ @des.class_members.size.should.equal 5
106
+ end
107
+
108
+ it "should have a damage instance member" do
109
+ @des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
110
+ end
111
+
112
+ it "should have a another method instance member" do
113
+ @des.instance_members.select { |mem| mem.name == "another_method" }.should.not.be.empty
114
+ end
115
+
116
+
117
+
118
+ end
119
+
120
+ describe "Caricature::RubyObjectDescriptor" do
121
+
122
+ before do
123
+ @des = Caricature::RubyObjectDescriptor.new DaggerWithClassMembers
124
+ end
125
+
126
+ it "should have 2 instance members" do
127
+ @des.instance_members.size.should.equal 2
128
+ end
129
+
130
+ it "should have a damage instance member" do
131
+ @des.instance_members.select { |mem| mem.name == "damage" }.should.not.be.empty
132
+ end
133
+
134
+ it "should have 1 class member" do
135
+ @des.class_members.size.should.equal 1
136
+ end
137
+
138
+ it "should have a class_name class member" do
139
+ @des.class_members.select { |mem| mem.name == "class_name" }.should.not.be.empty
140
+ end
141
+
142
+ end
@@ -1,16 +1,20 @@
1
1
  require File.dirname(__FILE__) + "/bacon_helper"
2
2
 
3
+ describe "Caricature::Expectations" do
4
+
5
+ end
6
+
3
7
  describe "Caricature::ExpectationBuilder" do
4
8
 
5
9
  it "should create an expectation builder" do
6
- builder = Caricature::ExpectationBuilder.new :some_method, nil
10
+ builder = Caricature::ExpectationBuilder.new :some_method
7
11
  builder.should.not.equal nil
8
12
  end
9
13
 
10
14
  describe "when using all defaults" do
11
15
 
12
16
  before do
13
- builder = Caricature::ExpectationBuilder.new :some_method, nil
17
+ builder = Caricature::ExpectationBuilder.new :some_method
14
18
  @expectation = builder.build
15
19
  end
16
20
 
@@ -39,7 +43,7 @@ describe "Caricature::ExpectationBuilder" do
39
43
  describe "when specifying only arguments" do
40
44
 
41
45
  before do
42
- builder = Caricature::ExpectationBuilder.new :some_method,nil
46
+ builder = Caricature::ExpectationBuilder.new :some_method
43
47
  builder.with(1, 2, 3)
44
48
  @expectation = builder.build
45
49
  end
@@ -69,7 +73,7 @@ describe "Caricature::ExpectationBuilder" do
69
73
  describe "when specifying only a block for the return value" do
70
74
 
71
75
  before do
72
- builder = Caricature::ExpectationBuilder.new :some_method, nil
76
+ builder = Caricature::ExpectationBuilder.new :some_method
73
77
  builder.return { 5 }
74
78
  @expectation = builder.build
75
79
  end
@@ -99,7 +103,7 @@ describe "Caricature::ExpectationBuilder" do
99
103
  describe "when specifying a return value" do
100
104
 
101
105
  before do
102
- builder = Caricature::ExpectationBuilder.new :some_method, nil
106
+ builder = Caricature::ExpectationBuilder.new :some_method
103
107
  builder.return 5
104
108
  @expectation = builder.build
105
109
  end
@@ -130,7 +134,7 @@ describe "Caricature::ExpectationBuilder" do
130
134
 
131
135
  before do
132
136
  @msg = "Hold on, that wasn't supposed to happen"
133
- builder = Caricature::ExpectationBuilder.new :some_method, nil
137
+ builder = Caricature::ExpectationBuilder.new :some_method
134
138
  builder.raise @msg
135
139
  @expectation = builder.build
136
140
  end
@@ -160,7 +164,7 @@ describe "Caricature::ExpectationBuilder" do
160
164
  describe "when specifying a return value and telling you want a call to super before" do
161
165
 
162
166
  before do
163
- builder = Caricature::ExpectationBuilder.new :some_method, nil
167
+ builder = Caricature::ExpectationBuilder.new :some_method
164
168
  builder.return(5).super_before
165
169
  @expectation = builder.build
166
170
  end
@@ -458,12 +458,12 @@ describe "Full scenarios" do
458
458
  var = @ninja.did_receive?(:survive_attack_with).with(:any)
459
459
  @ninja.did_receive?(:survive_attack_with).with(@weapon).should.be.successful
460
460
  end
461
-
461
+
462
462
 
463
463
  end
464
464
 
465
465
  end
466
-
466
+
467
467
  describe "Ruby to Ruby interactions" do
468
468
 
469
469
  describe "when isolating Ruby classes" do
@@ -550,6 +550,98 @@ describe "Full scenarios" do
550
550
 
551
551
  end
552
552
 
553
+ describe "when isolating Ruby classes with class members" do
554
+
555
+ before do
556
+ @dagger = Dagger.new
557
+ @soldier = Caricature::Isolation.for(SoldierWithClassMembers)
558
+ end
559
+
560
+ it "should work without expectations" do
561
+ result = @dagger.attack @soldier
562
+ result.should.equal nil
563
+
564
+ @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
565
+ end
566
+
567
+ it "should work for expectations with an argument constraint" do
568
+ @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
569
+
570
+ @dagger.attack(@soldier).should.equal 5
571
+
572
+ @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
573
+ end
574
+
575
+ it "should work for an expctation on a class method without an argument constraint" do
576
+ @soldier.when_class_receives(:class_name).return(5)
577
+
578
+ @soldier.class.class_name.should.equal 5
579
+
580
+ @soldier.did_class_receive?(:class_name).should.be.successful
581
+ end
582
+
583
+ it "should work for expectations with an argument constraint when a wrong argument is passed in" do
584
+ @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
585
+
586
+ @dagger.attack(Soldier.new).should.equal 8
587
+
588
+ @soldier.did_receive?(:survive_attack_with).with(@dagger).should.not.be.successful
589
+ end
590
+
591
+ it "should work for expectations with an argument constraint and an assertion argument constraint" do
592
+ soldier = Soldier.new
593
+ @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
594
+
595
+ @dagger.attack(@soldier).should.equal 5
596
+
597
+ @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
598
+ end
599
+
600
+ it "should fail for expectations with an argument constraint and an assertion argument constraint" do
601
+ soldier = Soldier.new
602
+ @soldier.when_receiving(:survive_attack_with).with(@dagger).return(5)
603
+
604
+ @dagger.attack(@soldier).should.equal 5
605
+
606
+ @soldier.did_receive?(:survive_attack_with).with(Dagger.new).should.not.be.successful
607
+ end
608
+
609
+ it "should work with an expectation for any arguments" do
610
+ @soldier.when_receiving(:survive_attack_with).return(5)
611
+
612
+ result = @dagger.attack @soldier
613
+ result.should.equal 5
614
+
615
+ @soldier.did_receive?(:survive_attack_with).with(:any).should.be.successful
616
+ end
617
+
618
+ it "should work with an assertion for specific arguments" do
619
+ @soldier.when_receiving(:survive_attack_with) do |method_should|
620
+ method_should.return(5)
621
+ end
622
+
623
+ result = @dagger.attack @soldier
624
+ result.should.equal 5
625
+
626
+ @soldier.did_receive?(:survive_attack_with).with(@dagger).should.be.successful
627
+ end
628
+
629
+ it "should fail for an assertion with wrong arguments" do
630
+ @soldier.when_receiving(:survive_attack_with) do |method_should|
631
+ method_should.return(5)
632
+ end
633
+
634
+ result = @dagger.attack @soldier
635
+ result.should.equal 5
636
+
637
+ @soldier.
638
+ did_receive?(:survive_attack_with).
639
+ with(Caricature::Isolation.for(Dagger)).
640
+ should.not.be.successful
641
+ end
642
+
643
+ end
644
+
553
645
  describe "when isolating Ruby instances" do
554
646
 
555
647
  before do
@@ -1,45 +1,3 @@
1
- # Caricature -- A simple mocking framework for IronRuby
2
- #
3
- # Copyright (c) 2009, Caricature Team
4
- # http://github.com/casualjim/caricature
5
- # All rights reserved.
6
- #
7
- # Redistribution and use in source and binary forms,
8
- # with or without modification, are permitted provided
9
- # that the following conditions are met:
10
- #
11
- # * Redistributions of source code must retain the
12
- # above copyright notice, this list of conditions and
13
- # the following disclaimer.
14
- #
15
- # * Redistributions in binary form must reproduce
16
- # the above copyright notice, this list of conditions
17
- # and the following disclaimer in the documentation
18
- # and/or other materials provided with the distribution.
19
- #
20
- # * Neither the name of the Caricature Team nor the
21
- # names of its contributors may be used to endorse
22
- # or promote products derived from this software
23
- # without specific prior written permission.
24
- #
25
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26
- # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27
- # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32
- # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
- # SUCH DAMAGE.
39
- #
40
- # [This is the BSD license, see
41
- # http://www.opensource.org/licenses/bsd-license.php]
42
-
43
1
  require File.dirname(__FILE__) + "/bacon_helper"
44
2
 
45
3
  describe "Caricature::Isolation" do
@@ -1,11 +1,34 @@
1
1
  require File.dirname(__FILE__) + "/bacon_helper"
2
2
 
3
+ class TestIsolation
4
+ attr_accessor :instance, :expectations
5
+ def initialize(instance, expectations)
6
+ @instance, @expectations = instance, expectations
7
+ end
8
+ def send_message(method_name, return_type, *args, &b)
9
+ exp = expectations.find(method_name, *args)
10
+ if exp
11
+ res = instance.__send__(method_name, *args, &b) if exp.super_before?
12
+ res = exp.execute(*args)
13
+ res = instance.__send__(method_name, *args, &b) if !exp.super_before? and exp.call_super?
14
+ res
15
+ else
16
+ rt = nil
17
+ is_value_type = return_type && return_type != System::Void.to_clr_type && return_type.is_value_type
18
+ rt = System::Activator.create_instance(return_type) if is_value_type
19
+ rt
20
+ end
21
+ end
22
+ end
23
+
3
24
  describe "Caricature::RubyIsolator" do
4
25
 
5
26
  before do
6
27
  @subj = Soldier.new
7
- @recorder = Caricature::MethodCallRecorder.new
8
- @proxy = Caricature::RubyIsolator.for(@subj, @recorder)
28
+ res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(@subj)
29
+ iso = TestIsolation.new res.subject, Caricature::Expectations.new
30
+ @proxy = res.isolation
31
+ @proxy.class.instance_variable_set("@___context___", iso)
9
32
  end
10
33
 
11
34
 
@@ -19,15 +42,21 @@ describe "Caricature::RubyIsolator" do
19
42
  @proxy.name.should.be.nil
20
43
  end
21
44
 
22
- it "should record a call" do
23
- @recorder.size.should.equal 1
45
+ end
46
+
47
+ describe "when isolating a class with class members" do
48
+
49
+ before do
50
+ res = Caricature::RubyIsolator.for Caricature::IsolatorContext.new(DaggerWithClassMembers)
51
+ iso = TestIsolation.new res.subject, Caricature::Expectations.new
52
+ @proxy = res.isolation
53
+ @proxy.class.instance_variable_set("@___context___", iso)
24
54
  end
25
55
 
26
- it "should record the correct call" do
27
- mc = @recorder[:name]
28
- mc.method_name.should.equal :name
29
- mc.args.should.equal [Caricature::ArgumentRecording.new]
30
- mc.block.should.equal nil
56
+ it "should return nil for the class method" do
57
+
58
+ @proxy.class.class_name.should.be.nil
59
+
31
60
  end
32
61
 
33
62
  end
@@ -38,16 +67,19 @@ describe "Caricature::RecordingClrProxy" do
38
67
  describe "for an instance of a CLR class" do
39
68
 
40
69
  before do
41
- @samurai = ClrModels::Samurai.new
42
- @samurai.name = "Nakiro"
43
- @recorder = Caricature::MethodCallRecorder.new
44
- @proxy = Caricature::ClrIsolator.for(@samurai, @recorder)
70
+ @ninja = ClrModels::Ninja.new
71
+ @ninja.name = "Nakiro"
72
+ context = Caricature::IsolatorContext.new(@ninja)
73
+ res = Caricature::ClrIsolator.for context
74
+ iso = TestIsolation.new res.subject, Caricature::Expectations.new
75
+ @proxy = res.isolation
76
+ @proxy.class.instance_variable_set("@___context___", iso)
45
77
  end
46
78
 
47
79
  it "should create a proxy" do
48
80
 
49
- @proxy.___super___.name.should.equal @samurai.name
50
- @proxy.___super___.id.should.equal 0
81
+ @proxy.___super___.name.should.equal @ninja.name
82
+ @proxy.___super___.id.should.equal 1
51
83
  end
52
84
 
53
85
  describe "when invoking a method" do
@@ -60,15 +92,21 @@ describe "Caricature::RecordingClrProxy" do
60
92
  @proxy.name.should.be.nil
61
93
  end
62
94
 
63
- it "should record a call" do
64
- @recorder.size.should.equal 1
95
+ end
96
+
97
+ describe "when isolating a class with class members" do
98
+
99
+ before do
100
+ res = Caricature::ClrIsolator.for Caricature::IsolatorContext.new(ClrModels::SwordWithStatics)
101
+ iso = TestIsolation.new res.subject, Caricature::Expectations.new
102
+ @proxy = res.isolation
103
+ @proxy.class.instance_variable_set("@___context___", iso)
65
104
  end
66
105
 
67
- it "should record the correct call" do
68
- mc = @recorder[:name]
69
- mc.method_name.should.equal :name
70
- mc.args.should.equal [Caricature::ArgumentRecording.new]
71
- mc.block.should.equal nil
106
+ it "should return nil for the class method" do
107
+
108
+ @proxy.class.class_naming.should.be.nil
109
+
72
110
  end
73
111
 
74
112
  end
@@ -79,41 +117,27 @@ describe "Caricature::RecordingClrProxy" do
79
117
 
80
118
  before do
81
119
  @recorder = Caricature::MethodCallRecorder.new
82
- @proxy = Caricature::ClrIsolator.for(ClrModels::Ninja, @recorder)
120
+ context = Caricature::IsolatorContext.new(ClrModels::Ninja, @recorder)
121
+ res = Caricature::ClrIsolator.for context
122
+ iso = TestIsolation.new res.subject, Caricature::Expectations.new
123
+ @proxy = res.isolation
124
+ @proxy.class.instance_variable_set("@___context___", iso)
83
125
  end
84
126
 
85
127
  it "should create a proxy" do
86
128
 
87
- @proxy.___super___.class.superclass.should.equal ClrModels::Ninja
129
+ @proxy.class.superclass.should.equal ClrModels::Ninja
88
130
 
89
131
  end
90
132
 
91
133
 
92
- describe "when invoking a method" do
93
-
94
- before do
95
- @proxy.name
96
- end
97
-
98
- it "should record a call" do
99
- @recorder.size.should.equal 1
100
- end
101
-
102
- it "should record the correct call" do
103
- mc = @recorder[:name]
104
- mc.method_name.should.equal :name
105
- mc.args.should.equal [Caricature::ArgumentRecording.new]
106
- mc.block.should.equal nil
107
- end
108
-
109
- end
110
134
  end
111
135
 
112
136
  describe "for a CLR interface" do
113
137
 
114
138
  before do
115
- @recorder = Caricature::MethodCallRecorder.new
116
- @proxy = Caricature::ClrInterfaceIsolator.for(ClrModels::IWarrior, @recorder)
139
+ res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IWarrior)
140
+ @proxy = res.isolation
117
141
  end
118
142
 
119
143
  it "should create a proxy" do
@@ -132,32 +156,13 @@ describe "Caricature::RecordingClrProxy" do
132
156
  @proxy.should.respond_to?(:name=)
133
157
  end
134
158
 
135
- describe "when invoking a method" do
136
-
137
- before do
138
- @proxy.name
139
- end
140
-
141
- it "should record a call" do
142
- @recorder.size.should.equal 1
143
- end
144
-
145
- it "should record the correct call" do
146
- mc = @recorder[:name]
147
- mc.method_name.should.equal :name
148
- mc.args.should.equal [Caricature::ArgumentRecording.new]
149
- mc.block.should.equal nil
150
- end
151
-
152
- end
153
-
154
159
  end
155
160
 
156
161
  describe "for a CLR Interface with an event" do
157
162
 
158
163
  before do
159
- @recorder = Caricature::MethodCallRecorder.new
160
- @proxy = Caricature::ClrInterfaceIsolator.for(ClrModels::IExposing, @recorder)
164
+ res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposing)
165
+ @proxy = res.isolation
161
166
  end
162
167
 
163
168
  it "should create an add method for the event" do
@@ -173,7 +178,8 @@ describe "Caricature::RecordingClrProxy" do
173
178
  describe "for CLR interface recursion" do
174
179
 
175
180
  before do
176
- @proxy = Caricature::ClrInterfaceIsolator.for(ClrModels::IExposingWarrior, Caricature::MethodCallRecorder.new)
181
+ res = Caricature::ClrInterfaceIsolator.for Caricature::IsolatorContext.new(ClrModels::IExposingWarrior)
182
+ @proxy = res.isolation
177
183
  end
178
184
 
179
185
  it "should create a method defined on the CLR interface" do