rr 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ * 0.1.12
2
+ - Fixed bug where Creators methods are not removed when methods are defined on Object
3
+ - Fixed [#12289] Creators methods are not removed in Rails environment
4
+
1
5
  * 0.1.11
2
6
  - Fixed [#12287] AtLeastMatcher does not cause Scenario to be called
3
7
 
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ def run_suite
21
21
  end
22
22
 
23
23
  PKG_NAME = "rr"
24
- PKG_VERSION = "0.1.11"
24
+ PKG_VERSION = "0.1.12"
25
25
  PKG_FILES = FileList[
26
26
  '[A-Z]*',
27
27
  '*.rb',
@@ -21,6 +21,17 @@ describe DoNotAllowCreator, ".new" do
21
21
  before do
22
22
  @creator = DoNotAllowCreator.new(@space, @subject)
23
23
  end
24
+
25
+ it "clears out all methods from creator" do
26
+ creator_subclass = Class.new(DoNotAllowCreator) do
27
+ def i_should_be_a_scenario
28
+ end
29
+ end
30
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
+
32
+ creator = creator_subclass.new(@space, @subject)
33
+ creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
+ end
24
35
  end
25
36
 
26
37
  describe DoNotAllowCreator, ".new with block" do
@@ -57,6 +68,17 @@ describe DoNotAllowCreator, ".new with block" do
57
68
  it "raises TimesCalledError when any_args is called with arguments" do
58
69
  proc {@subject.any_args(1, 2)}.should raise_error(Errors::TimesCalledError)
59
70
  end
71
+
72
+ it "clears out all methods from creator" do
73
+ creator_subclass = Class.new(DoNotAllowCreator) do
74
+ def i_should_be_a_scenario
75
+ end
76
+ end
77
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
78
+
79
+ creator = creator_subclass.new(@space, @subject)
80
+ creator.i_should_be_a_scenario.should be_instance_of(Scenario)
81
+ end
60
82
  end
61
83
 
62
84
  describe DoNotAllowCreator, "#method_missing" do
@@ -21,6 +21,17 @@ describe MockCreator, ".new without block" do
21
21
  before do
22
22
  @creator = MockCreator.new(@space, @subject)
23
23
  end
24
+
25
+ it "clears out all methods from creator" do
26
+ creator_subclass = Class.new(MockCreator) do
27
+ def i_should_be_a_scenario
28
+ end
29
+ end
30
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
+
32
+ creator = creator_subclass.new(@space, @subject)
33
+ creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
+ end
24
35
  end
25
36
 
26
37
  describe MockCreator, ".new with block" do
@@ -41,6 +52,18 @@ describe MockCreator, ".new with block" do
41
52
  @subject.foobar(:something).should == :default
42
53
  @subject.baz.should == :baz_result
43
54
  end
55
+
56
+ it "clears out all methods from creator" do
57
+ creator_subclass = Class.new(MockCreator) do
58
+ def i_should_be_a_scenario
59
+ end
60
+ end
61
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
62
+
63
+ creator_subclass.new(@space, @subject) do |m|
64
+ m.i_should_be_a_scenario.should be_instance_of(Scenario)
65
+ end
66
+ end
44
67
  end
45
68
 
46
69
 
@@ -21,6 +21,17 @@ describe ProbeCreator, ".new without block" do
21
21
  before do
22
22
  @creator = ProbeCreator.new(@space, @subject)
23
23
  end
24
+
25
+ it "clears out all methods from creator" do
26
+ creator_subclass = Class.new(ProbeCreator) do
27
+ def i_should_be_a_scenario
28
+ end
29
+ end
30
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
+
32
+ creator = creator_subclass.new(@space, @subject)
33
+ creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
+ end
24
35
  end
25
36
 
26
37
  describe ProbeCreator, ".new with block" do
@@ -43,6 +54,18 @@ describe ProbeCreator, ".new with block" do
43
54
  @subject.foobar(:something).should == :original_foobar
44
55
  proc {@subject.foobar(:nasty)}.should raise_error
45
56
  end
57
+
58
+ it "clears out all methods from creator" do
59
+ creator_subclass = Class.new(ProbeCreator) do
60
+ def i_should_be_a_scenario
61
+ end
62
+ end
63
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
64
+
65
+ creator_subclass.new(@space, @subject) do |m|
66
+ m.i_should_be_a_scenario.should be_instance_of(Scenario)
67
+ end
68
+ end
46
69
  end
47
70
 
48
71
  describe ProbeCreator, ".new where method takes a block" do
@@ -21,6 +21,17 @@ describe StubCreator, ".new without block" do
21
21
  before do
22
22
  @creator = StubCreator.new(@space, @subject)
23
23
  end
24
+
25
+ it "clears out all methods from creator" do
26
+ creator_subclass = Class.new(StubCreator) do
27
+ def i_should_be_a_scenario
28
+ end
29
+ end
30
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
+
32
+ creator = creator_subclass.new(@space, @subject)
33
+ creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
+ end
24
35
  end
25
36
 
26
37
  describe StubCreator, ".new with block" do
@@ -45,6 +56,18 @@ describe StubCreator, ".new with block" do
45
56
  @subject.baz.should == :baz_result
46
57
  @subject.baz.should == :baz_result
47
58
  end
59
+
60
+ it "clears out all methods from creator" do
61
+ creator_subclass = Class.new(StubCreator) do
62
+ def i_should_be_a_scenario
63
+ end
64
+ end
65
+ creator_subclass.instance_methods.should include('i_should_be_a_scenario')
66
+
67
+ creator_subclass.new(@space, @subject) do |m|
68
+ m.i_should_be_a_scenario.should be_instance_of(Scenario)
69
+ end
70
+ end
48
71
  end
49
72
 
50
73
  describe StubCreator, "#method_missing" do
data/lib/rr/creator.rb ADDED
@@ -0,0 +1,16 @@
1
+ module RR
2
+ # RR::Creator is the superclass for all creators.
3
+ class Creator
4
+ def initialize(space, subject)
5
+ @space = space
6
+ @subject = subject
7
+ class << self
8
+ instance_methods.each do |m|
9
+ undef_method m unless m =~ /^__/
10
+ end
11
+ include self::InstanceMethods
12
+ end
13
+ yield(self) if block_given?
14
+ end
15
+ end
16
+ end
@@ -14,26 +14,20 @@ module RR
14
14
  # m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
15
15
  # m.method3.with_no_args # Do not allow method3 with no arguments
16
16
  # end
17
- class DoNotAllowCreator
18
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
19
-
20
- def initialize(space, subject)
21
- @space = space
22
- @subject = subject
23
- yield(self) if block_given?
24
- end
25
-
26
- protected
27
- def method_missing(method_name, *args, &returns)
28
- double = @space.create_double(@subject, method_name)
29
- scenario = @space.create_scenario(double)
30
- if args.empty?
31
- scenario.with_any_args
32
- else
33
- scenario.with(*args)
17
+ class DoNotAllowCreator < Creator
18
+ module InstanceMethods
19
+ protected
20
+ def method_missing(method_name, *args, &returns)
21
+ double = @space.create_double(@subject, method_name)
22
+ scenario = @space.create_scenario(double)
23
+ if args.empty?
24
+ scenario.with_any_args
25
+ else
26
+ scenario.with(*args)
27
+ end
28
+ scenario.never.returns(&returns)
29
+ scenario
34
30
  end
35
- scenario.never.returns(&returns)
36
- scenario
37
31
  end
38
32
  end
39
33
  end
@@ -12,21 +12,15 @@ module RR
12
12
  # mock(subject) do |m|
13
13
  # m.method_name(arg1, arg2) { return_value }
14
14
  # end
15
- class MockCreator
16
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
17
-
18
- def initialize(space, subject)
19
- @space = space
20
- @subject = subject
21
- yield(self) if block_given?
22
- end
23
-
24
- protected
25
- def method_missing(method_name, *args, &returns)
26
- double = @space.create_double(@subject, method_name)
27
- scenario = @space.create_scenario(double)
28
- scenario.with(*args).once.returns(&returns)
29
- scenario
15
+ class MockCreator < Creator
16
+ module InstanceMethods
17
+ protected
18
+ def method_missing(method_name, *args, &returns)
19
+ double = @space.create_double(@subject, method_name)
20
+ scenario = @space.create_scenario(double)
21
+ scenario.with(*args).once.returns(&returns)
22
+ scenario
23
+ end
30
24
  end
31
25
  end
32
26
  end
@@ -21,22 +21,16 @@ module RR
21
21
  #
22
22
  # user = User.find('4')
23
23
  # user.valid? # false
24
- class ProbeCreator
25
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
26
-
27
- def initialize(space, subject)
28
- @space = space
29
- @subject = subject
30
- yield(self) if block_given?
31
- end
32
-
33
- protected
34
- def method_missing(method_name, *args, &after_call)
35
- double = @space.create_double(@subject, method_name)
36
- scenario = @space.create_scenario(double)
37
- scenario.with(*args).once.implemented_by(double.original_method)
38
- scenario.after_call(&after_call) if after_call
39
- scenario
24
+ class ProbeCreator < Creator
25
+ module InstanceMethods
26
+ protected
27
+ def method_missing(method_name, *args, &after_call)
28
+ double = @space.create_double(@subject, method_name)
29
+ scenario = @space.create_scenario(double)
30
+ scenario.with(*args).once.implemented_by(double.original_method)
31
+ scenario.after_call(&after_call) if after_call
32
+ scenario
33
+ end
40
34
  end
41
35
  end
42
36
  end
@@ -12,24 +12,18 @@ module RR
12
12
  # stub(subject) do |m|
13
13
  # m.method_name(arg1, arg2) { return_value }
14
14
  # end
15
- class StubCreator
16
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
17
-
18
- def initialize(space, subject)
19
- @space = space
20
- @subject = subject
21
- yield(self) if block_given?
22
- end
23
-
24
- protected
25
- def method_missing(method_name, *args, &returns)
26
- double = @space.create_double(@subject, method_name)
27
- scenario = @space.create_scenario(double)
28
- scenario.returns(&returns).any_number_of_times
29
- if args.empty?
30
- scenario.with_any_args
31
- else
32
- scenario.with(*args)
15
+ class StubCreator < Creator
16
+ module InstanceMethods
17
+ protected
18
+ def method_missing(method_name, *args, &returns)
19
+ double = @space.create_double(@subject, method_name)
20
+ scenario = @space.create_scenario(double)
21
+ scenario.returns(&returns).any_number_of_times
22
+ if args.empty?
23
+ scenario.with_any_args
24
+ else
25
+ scenario.with(*args)
26
+ end
33
27
  end
34
28
  end
35
29
  end
data/lib/rr.rb CHANGED
@@ -2,6 +2,7 @@ dir = File.dirname(__FILE__)
2
2
 
3
3
  require "rr/double"
4
4
 
5
+ require "rr/creator"
5
6
  require "rr/mock_creator"
6
7
  require "rr/stub_creator"
7
8
  require "rr/probe_creator"
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.11
6
+ version: 0.1.12
7
7
  date: 2007-07-14 00:00:00 -07:00
8
8
  summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
9
9
  require_paths:
@@ -34,6 +34,7 @@ files:
34
34
  - README
35
35
  - lib/rr.rb
36
36
  - lib/rr/scenario.rb
37
+ - lib/rr/creator.rb
37
38
  - lib/rr/stub_creator.rb
38
39
  - lib/rr/space.rb
39
40
  - lib/rr/double.rb