caricature 0.7.5 → 0.7.6

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.
Files changed (74) hide show
  1. data/README.rdoc +97 -97
  2. data/Rakefile +309 -310
  3. data/caricature.gemspec +123 -110
  4. data/lib/caricature/bacon/integration.rb +75 -75
  5. data/lib/caricature/bacon.rb +2 -2
  6. data/lib/caricature/clr/descriptor.rb +159 -159
  7. data/lib/caricature/clr/event_verification.rb +56 -56
  8. data/lib/caricature/clr/expectation.rb +100 -100
  9. data/lib/caricature/clr/isolation.rb +78 -78
  10. data/lib/caricature/clr/isolator.rb +252 -252
  11. data/lib/caricature/clr/messenger.rb +51 -49
  12. data/lib/caricature/clr/method_call_recorder.rb +96 -96
  13. data/lib/caricature/expectation.rb +1 -1
  14. data/lib/caricature/method_call_recorder.rb +3 -3
  15. data/lib/caricature/rspec/integration.rb +118 -118
  16. data/lib/caricature/version.rb +5 -5
  17. data/lib/caricature.rb +25 -25
  18. data/spec/bacon/integration/callback_spec.rb +156 -156
  19. data/spec/bacon/integration/clr_to_clr_spec.rb +325 -253
  20. data/spec/bacon/integration/event_spec.rb +97 -97
  21. data/spec/bacon/integration/indexer_spec.rb +27 -27
  22. data/spec/bacon/spec_helper.rb +4 -4
  23. data/spec/bacon/unit/descriptor_spec.rb +212 -212
  24. data/spec/bacon/unit/sword_spec.rb +39 -39
  25. data/spec/bacon/unit/verification_spec.rb +103 -103
  26. data/spec/bin/ClrModels.dll +0 -0
  27. data/spec/bin/ClrModels.dll.mdb +0 -0
  28. data/spec/fixtures/ExplodingCar.cs +56 -0
  29. data/spec/fixtures/ExposedChangedSubscriber.cs +26 -0
  30. data/spec/fixtures/ExposingWarrior.cs +58 -0
  31. data/spec/fixtures/IExplodingWarrior.cs +10 -0
  32. data/spec/fixtures/IExposing.cs +9 -0
  33. data/spec/fixtures/IExposingBridge.cs +9 -0
  34. data/spec/fixtures/IExposingWarrior.cs +8 -0
  35. data/spec/fixtures/IHaveAnIndexer.cs +8 -0
  36. data/spec/fixtures/IWarrior.cs +13 -0
  37. data/spec/fixtures/IWeapon.cs +9 -0
  38. data/spec/fixtures/IndexerCaller.cs +17 -0
  39. data/spec/fixtures/IndexerContained.cs +20 -0
  40. data/spec/fixtures/MyClassWithAStatic.cs +16 -0
  41. data/spec/fixtures/Ninja.cs +34 -0
  42. data/spec/fixtures/Samurai.cs +29 -0
  43. data/spec/fixtures/StaticCaller.cs +12 -0
  44. data/spec/fixtures/Sword.cs +16 -0
  45. data/spec/fixtures/SwordWithStatics.cs +19 -0
  46. data/spec/fixtures/clr_interaction.rb +61 -0
  47. data/spec/fixtures/dagger.rb +11 -0
  48. data/spec/fixtures/dagger_with_class_members.rb +11 -0
  49. data/spec/fixtures/sheath.rb +19 -0
  50. data/spec/fixtures/soldier.rb +29 -0
  51. data/spec/fixtures/soldier_with_class_members.rb +7 -0
  52. data/spec/fixtures/swift_cleanup_crew.rb +21 -0
  53. data/spec/fixtures/with_class_methods.rb +11 -0
  54. data/spec/{models → models.notused}/ClrModels.cs +241 -241
  55. data/spec/{models → models.notused}/ruby_models.rb +150 -150
  56. data/spec/rspec/integration/callback_spec.rb +156 -156
  57. data/spec/rspec/integration/clr_to_clr_spec.rb +254 -254
  58. data/spec/rspec/integration/clr_to_ruby_spec.rb +227 -227
  59. data/spec/rspec/integration/indexer_spec.rb +27 -27
  60. data/spec/rspec/integration/ruby_to_ruby_spec.rb +271 -271
  61. data/spec/rspec/spec_helper.rb +12 -12
  62. data/spec/rspec/unit/core_ext_spec.rb +87 -87
  63. data/spec/rspec/unit/descriptor_spec.rb +210 -210
  64. data/spec/rspec/unit/event_spec.rb +16 -16
  65. data/spec/rspec/unit/expectation_spec.rb +300 -300
  66. data/spec/rspec/unit/interop_spec.rb +29 -29
  67. data/spec/rspec/unit/isolation_spec.rb +86 -86
  68. data/spec/rspec/unit/isolator_spec.rb +219 -219
  69. data/spec/rspec/unit/messaging_spec.rb +310 -310
  70. data/spec/rspec/unit/method_call_spec.rb +342 -342
  71. data/spec/rspec/unit/sword_spec.rb +39 -39
  72. data/spec/rspec/unit/verification_spec.rb +103 -103
  73. data/spec/spec_helper.rb +16 -15
  74. metadata +42 -11
@@ -1,104 +1,104 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe "Caricature::Verification" do
4
-
5
- describe "Matching" do
6
-
7
- before do
8
- @rec = Caricature::MethodCallRecorder.new
9
- @ver = Caricature::Verification.new(:my_method, @rec)
10
- end
11
-
12
- describe "Default initialisation" do
13
-
14
- it "should allow any arguments" do
15
- @ver.any_args?.should.be.true?
16
- end
17
-
18
- it "should match the provided method name when no arguments have been given" do
19
- @ver.matches?(:my_method).should.be.true?
20
- end
21
-
22
- it "should match the method name when arguments have been given" do
23
- @ver.matches?(:my_method, 1, 3, 4).should.be.true?
24
- end
25
-
26
- end
27
-
28
- describe "when initialized with and constrained by arguments" do
29
-
30
- before do
31
- @ver.with(1, 3, 6)
32
- end
33
-
34
- it "should match the provided method name when the correct arguments are given" do
35
- @ver.matches?(:my_method, 1, 3, 6).should.be.true?
36
- end
37
-
38
- it "should not match the method name when the arguments are not correct" do
39
- @ver.matches?(:my_method, 1, 3, 3).should.be.false?
40
- end
41
-
42
- it "should not match the method name when no arguments have been given" do
43
- @ver.matches?(:my_method).should.be.false?
44
- end
45
-
46
- end
47
-
48
- describe "when initialized with and not constrained by arguments" do
49
-
50
- before do
51
- @ver.with(1, 3, 6).allow_any_arguments
52
- end
53
-
54
- it "should match the provided method name when the correct arguments are given" do
55
- @ver.matches?(:my_method, 1, 3, 6).should.be.true?
56
- end
57
-
58
- it "should match the method name when the arguments are not correct" do
59
- @ver.matches?(:my_method, 1, 3, 3).should.be.true?
60
- end
61
-
62
- it "should match the method name when no arguments have been given" do
63
- @ver.matches?(:my_method).should.be.true?
64
- end
65
-
66
- end
67
-
68
- end
69
-
70
- describe "Verifying" do
71
-
72
- before do
73
- @rec = Caricature::MethodCallRecorder.new
74
- @rec.record_call :my_method
75
- @rec.record_call :my_method, :instance, nil, 1, 2, 3
76
- @rec.record_call :another_method
77
-
78
- end
79
-
80
- it "should be successful with any arguments allowed" do
81
- ver = Caricature::Verification.new(:my_method, @rec)
82
- ver.should.be.successful
83
- end
84
-
85
- it "should be successful with a correct set of arguments provided for my_method" do
86
- ver = Caricature::Verification.new(:my_method, @rec)
87
- ver.with 1, 2, 3
88
- ver.should.be.successful
89
- end
90
-
91
- it "should be unsuccessful when a wrong set of arguments is provided" do
92
- ver = Caricature::Verification.new(:my_method, @rec)
93
- ver.with 1, 5, 7
94
- ver.should.not.be.successful
95
- end
96
-
97
- it "should be unsuccessful when the wrong method name is provided" do
98
- ver = Caricature::Verification.new(:some_method, @rec)
99
- ver.should.not.be.successful
100
- end
101
-
102
- end
103
-
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "Caricature::Verification" do
4
+
5
+ describe "Matching" do
6
+
7
+ before do
8
+ @rec = Caricature::MethodCallRecorder.new
9
+ @ver = Caricature::Verification.new(:my_method, @rec)
10
+ end
11
+
12
+ describe "Default initialisation" do
13
+
14
+ it "should allow any arguments" do
15
+ @ver.any_args?.should.be.true?
16
+ end
17
+
18
+ it "should match the provided method name when no arguments have been given" do
19
+ @ver.matches?(:my_method).should.be.true?
20
+ end
21
+
22
+ it "should match the method name when arguments have been given" do
23
+ @ver.matches?(:my_method, 1, 3, 4).should.be.true?
24
+ end
25
+
26
+ end
27
+
28
+ describe "when initialized with and constrained by arguments" do
29
+
30
+ before do
31
+ @ver.with(1, 3, 6)
32
+ end
33
+
34
+ it "should match the provided method name when the correct arguments are given" do
35
+ @ver.matches?(:my_method, 1, 3, 6).should.be.true?
36
+ end
37
+
38
+ it "should not match the method name when the arguments are not correct" do
39
+ @ver.matches?(:my_method, 1, 3, 3).should.be.false?
40
+ end
41
+
42
+ it "should not match the method name when no arguments have been given" do
43
+ @ver.matches?(:my_method).should.be.false?
44
+ end
45
+
46
+ end
47
+
48
+ describe "when initialized with and not constrained by arguments" do
49
+
50
+ before do
51
+ @ver.with(1, 3, 6).allow_any_arguments
52
+ end
53
+
54
+ it "should match the provided method name when the correct arguments are given" do
55
+ @ver.matches?(:my_method, 1, 3, 6).should.be.true?
56
+ end
57
+
58
+ it "should match the method name when the arguments are not correct" do
59
+ @ver.matches?(:my_method, 1, 3, 3).should.be.true?
60
+ end
61
+
62
+ it "should match the method name when no arguments have been given" do
63
+ @ver.matches?(:my_method).should.be.true?
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ describe "Verifying" do
71
+
72
+ before do
73
+ @rec = Caricature::MethodCallRecorder.new
74
+ @rec.record_call :my_method
75
+ @rec.record_call :my_method, :instance, nil, 1, 2, 3
76
+ @rec.record_call :another_method
77
+
78
+ end
79
+
80
+ it "should be successful with any arguments allowed" do
81
+ ver = Caricature::Verification.new(:my_method, @rec)
82
+ ver.should.be.successful
83
+ end
84
+
85
+ it "should be successful with a correct set of arguments provided for my_method" do
86
+ ver = Caricature::Verification.new(:my_method, @rec)
87
+ ver.with 1, 2, 3
88
+ ver.should.be.successful
89
+ end
90
+
91
+ it "should be unsuccessful when a wrong set of arguments is provided" do
92
+ ver = Caricature::Verification.new(:my_method, @rec)
93
+ ver.with 1, 5, 7
94
+ ver.should.not.be.successful
95
+ end
96
+
97
+ it "should be unsuccessful when the wrong method name is provided" do
98
+ ver = Caricature::Verification.new(:some_method, @rec)
99
+ ver.should.not.be.successful
100
+ end
101
+
102
+ end
103
+
104
104
  end
Binary file
Binary file
@@ -0,0 +1,56 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class ExplodingCar {
6
+
7
+ public virtual event EventHandler<EventArgs> OnExploded;
8
+
9
+ public void Explode(){
10
+ // do logic here to make car explode
11
+ TriggerOnExploded();
12
+ }
13
+
14
+ protected virtual void TriggerOnExploded(){
15
+ var handler = OnExploded;
16
+ if(handler != null){
17
+ handler.Invoke(this, EventArgs.Empty);
18
+ }
19
+ }
20
+ }
21
+
22
+ public class CleanupCrew : IDisposable{
23
+ private bool _isDisposed = false;
24
+ private ExplodingCar _car;
25
+
26
+ public CleanupCrew(ExplodingCar car){
27
+ _car = car;
28
+ //don't use anonymous delegates or lambda's
29
+ _car.OnExploded += Handle_carOnExploded;
30
+ }
31
+
32
+ void Handle_carOnExploded (object sender, EventArgs e)
33
+ {
34
+ // Do logic here when car exploded. Clean street, repair buildings etc.
35
+ }
36
+
37
+ public void Dispose(){
38
+ Dispose(true);
39
+ // Keep this here for subclasses that may use unmanaged resources
40
+ GC.SuppressFinalize(this);
41
+ }
42
+
43
+ protected virtual void Dispose(bool isDisposing){
44
+ if(!_isDisposed){
45
+ if(isDisposing){
46
+ // detach event handlers here etc.
47
+ _car.OnExploded -= Handle_carOnExploded;
48
+
49
+ }
50
+ _isDisposed = true;
51
+ // unmanaged resources here.
52
+ }
53
+ }
54
+
55
+ }
56
+ }
@@ -0,0 +1,26 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class ExposedChangedSubscriber{
6
+
7
+ private readonly IExposingBridge _warrior;
8
+
9
+ public ExposedChangedSubscriber(IExposingBridge warrior){
10
+ _warrior = warrior;
11
+ _warrior.OnIsExposedChanged += OnExposedChanged;
12
+ }
13
+
14
+ public int Counter { get; set; }
15
+ public object Sender {get; set; }
16
+ public EventArgs Args { get; set; }
17
+
18
+ private void OnExposedChanged(object sender, EventArgs args){
19
+ Counter++;
20
+ Sender = sender;
21
+ Args = args;
22
+ }
23
+
24
+ }
25
+
26
+ }
@@ -0,0 +1,58 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class ExposingWarrior : IExposingWarrior{
6
+ private readonly int _id;
7
+
8
+ public string Name { get; set; }
9
+ public int Id { get { return _id; } }
10
+
11
+ public int Attack(IWarrior target, IWeapon weapon){
12
+ return weapon.Attack(target);
13
+ }
14
+
15
+ public bool IsKilledBy(IWeapon weapon)
16
+ {
17
+ return weapon.Damage() > 3;
18
+ }
19
+
20
+ public virtual event EventHandler<EventArgs> OnIsExposedChanged;
21
+ public bool IsExposed {get; set; }
22
+
23
+
24
+ public event EventHandler<EventArgs> OnIsAliveChanged;
25
+
26
+ public void Die(){
27
+ OnIsAliveChanged(this, EventArgs.Empty);
28
+ }
29
+
30
+ public static event EventHandler<EventArgs> OnCountChanged;
31
+
32
+ public static void ChangeCount(){
33
+ OnCountChanged(null, EventArgs.Empty);
34
+ }
35
+
36
+
37
+ public void SomeMethod(){}
38
+ public void OwnMethod(){
39
+
40
+ }
41
+
42
+ private int _life = 10;
43
+ public int SurviveAttackWith(IWeapon weapon){
44
+ return _life - weapon.Damage();
45
+ }
46
+
47
+ public void Explode(){
48
+ IsExposed = !IsExposed;
49
+ var handler = OnIsExposedChanged;
50
+ if(handler != null){
51
+ handler(this, EventArgs.Empty);
52
+ }
53
+ }
54
+
55
+ public bool HasEventSubscriptions{ get { return OnIsExposedChanged != null; } }
56
+ }
57
+
58
+ }
@@ -0,0 +1,10 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IExplodingWarrior : IExposingBridge{
6
+ event EventHandler<EventArgs> OnExploding;
7
+ void Explode();
8
+
9
+ }
10
+ }
@@ -0,0 +1,9 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IExposing {
6
+ event EventHandler<EventArgs> OnIsExposedChanged;
7
+ bool IsExposed {get; set; }
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IExposingBridge : IWarrior, IExposing {
6
+ void SomeMethod();
7
+ }
8
+
9
+ }
@@ -0,0 +1,8 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IExposingWarrior : IExposingBridge {
6
+ void OwnMethod();
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IHaveAnIndexer{
6
+ string this[string name]{ get; set; }
7
+ }
8
+ }
@@ -0,0 +1,13 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IWarrior
6
+ {
7
+ int Id { get; }
8
+ string Name { get; set; }
9
+ bool IsKilledBy(IWeapon weapon);
10
+ int Attack(IWarrior target, IWeapon weapon);
11
+ int SurviveAttackWith(IWeapon weapon);
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public interface IWeapon{
6
+ int Attack(IWarrior warrior);
7
+ int Damage();
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class IndexerCaller{
6
+
7
+ public string CallIndexOnClass(IndexerContained klass, string name){
8
+ return klass[name];
9
+ }
10
+
11
+ public string CallIndexOnInterface(IHaveAnIndexer klass, string name){
12
+ return klass[name];
13
+ }
14
+
15
+ }
16
+
17
+ }
@@ -0,0 +1,20 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class IndexerContained{
6
+
7
+ private Dictionary<string, string> _inner = new Dictionary<string, string>{
8
+ { "key1", "value1" },
9
+ { "key2", "value2" },
10
+ { "key3", "value3" },
11
+ { "key4", "value4" }
12
+ };
13
+
14
+ public virtual string this[string name]{
15
+ get { return _inner[name]; }
16
+ set { _inner[name] = value; }
17
+ }
18
+ }
19
+
20
+ }
@@ -0,0 +1,16 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class MyClassWithAStatic{
6
+
7
+ public string HelloWorld(){
8
+ return "Hello World!";
9
+ }
10
+
11
+ public static string GoodByeWorld(){
12
+ return "Goodbye world!";
13
+ }
14
+ }
15
+
16
+ }
@@ -0,0 +1,34 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class Ninja : IWarrior{
6
+
7
+ public Ninja(){
8
+ Name = "Tony the Ninja";
9
+ _id = 1;
10
+ }
11
+
12
+ private readonly int _id;
13
+
14
+ public string Name { get; set; }
15
+ public int Id { get { return _id; } }
16
+
17
+ public int Attack(IWarrior target, IWeapon weapon){
18
+ return weapon.Attack(target);
19
+ }
20
+
21
+ public bool IsKilledBy(IWeapon weapon)
22
+ {
23
+ return weapon.Damage() > 3;
24
+ }
25
+
26
+ private int _life = 10;
27
+ public virtual int SurviveAttackWith(IWeapon weapon){
28
+ return _life - weapon.Damage();
29
+ }
30
+
31
+
32
+ }
33
+
34
+ }
@@ -0,0 +1,29 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public sealed class Samurai : IWarrior{
6
+
7
+ private readonly int _id;
8
+
9
+ public string Name { get; set; }
10
+ public int Id { get { return _id; } }
11
+
12
+ public int Attack(IWarrior target, IWeapon weapon){
13
+ return weapon.Attack(target);
14
+ }
15
+
16
+ public bool IsKilledBy(IWeapon weapon)
17
+ {
18
+ return weapon.Damage() > 5;
19
+ }
20
+
21
+ private int _life = 10;
22
+ public int SurviveAttackWith(IWeapon weapon){
23
+ return _life - weapon.Damage();
24
+ }
25
+
26
+
27
+ }
28
+
29
+ }
@@ -0,0 +1,12 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class StaticCaller{
6
+
7
+ public string CallsStatic(){
8
+ return MyClassWithAStatic.GoodByeWorld();
9
+ }
10
+ }
11
+
12
+ }
@@ -0,0 +1,16 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class Sword : IWeapon {
6
+
7
+ public virtual int Attack(IWarrior warrior){
8
+ return warrior.SurviveAttackWith(this);
9
+ }
10
+
11
+ public int Damage(){
12
+ return 4;
13
+ }
14
+ }
15
+
16
+ }
@@ -0,0 +1,19 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ClrModels {
5
+ public class SwordWithStatics : Sword{
6
+
7
+ static SwordWithStatics(){
8
+ ClassNaming = "Sword with statics";
9
+ }
10
+
11
+ public SwordWithStatics(){ SwordName = "Sword name for statics"; }
12
+
13
+ public void AnotherMethod(){}
14
+ public static void AStaticMethod(){}
15
+ public static string ClassNaming { get; set; }
16
+ public string SwordName{get; set;}
17
+ }
18
+
19
+ }
@@ -0,0 +1,61 @@
1
+ module PureRubyModule
2
+
3
+ end
4
+
5
+ module RubyModuleIncludingModule
6
+ include PureRubyModule
7
+ end
8
+
9
+ class SubclassingRubyClass < Soldier
10
+
11
+ end
12
+
13
+ class ModuleIncludingClass
14
+ include RubyModuleIncludingModule
15
+ end
16
+
17
+ if defined? IRONRUBY_VERSION
18
+
19
+ module Caricature
20
+
21
+ module InterfaceIncludingModule
22
+ include ClrModels::IWarrior
23
+ end
24
+
25
+
26
+ module InterfaceUpTheWazoo
27
+ include InterfaceIncludingModule
28
+ end
29
+
30
+ class InterfaceIncludingClass
31
+ include ClrModels::IWarrior
32
+
33
+ attr_reader :id
34
+ attr_accessor :name
35
+
36
+ def is_killed_by(weapon)
37
+
38
+ end
39
+
40
+ def attack(target, weapon)
41
+
42
+ end
43
+
44
+ def survive_attack_with(weapon)
45
+
46
+ end
47
+
48
+ end
49
+
50
+ class SubClassingClrClass < ClrModels::Ninja
51
+
52
+ end
53
+
54
+ class InterfaceUpTheWazooClass
55
+ include InterfaceUpTheWazoo
56
+ end
57
+
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,11 @@
1
+ class Dagger
2
+
3
+ def damage
4
+ 2
5
+ end
6
+
7
+ def attack(target)
8
+ target.survive_attack_with self
9
+ end
10
+
11
+ end