rr 0.10.4 → 0.10.5
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/CHANGES +7 -1
- data/README.rdoc +11 -0
- data/VERSION.yml +3 -2
- data/lib/rr/adapters/rspec.rb +3 -1
- data/lib/rr/adapters/test_unit.rb +13 -11
- data/lib/rr/double_definitions/double_definition.rb +3 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +0 -1
- data/lib/rr/errors/rr_error.rb +2 -2
- data/lib/rr/injections/double_injection.rb +2 -0
- data/lib/rr/injections/method_missing_injection.rb +3 -3
- data/lib/rr/injections/singleton_method_added_injection.rb +3 -3
- data/ruby_19_spec.rb +12 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +5 -2
- data/spec/rr/double_injection/double_injection_spec.rb +4 -12
- data/spec/rr/double_spec.rb +5 -2
- data/spec/rr/test_unit/test_unit_integration_test.rb +2 -0
- data/spec/spec_suite.rb +20 -3
- metadata +3 -2
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.10.5
|
2
|
+
- Fixed issues with Ruby 1.9
|
3
|
+
- Fixed stack overflow caused by double include in Test::Unit adapter [http://github.com/btakita/rr/issues#issue/16]. Identified by Dave Myron (http://github.com/contentfree)
|
4
|
+
- Fixed warnings (Patch by Bryan Helmkamp)
|
5
|
+
|
6
|
+
0.10.4
|
1
7
|
- Handle lazily defined methods (where respond_to? returns true yet the method is not yet defined and the first call to method_missing defines the method). This pattern is used in ActiveRecord and ActionMailer.
|
2
8
|
- Fixed warning about aliasing #instance_exec in jruby. http://github.com/btakita/rr/issues#issue/9 (Patch by Nathan Sobo)
|
3
9
|
|
@@ -218,4 +224,4 @@
|
|
218
224
|
- Rspec and Test::Unit integration fixes
|
219
225
|
|
220
226
|
* 0.1.0
|
221
|
-
- Initial Release
|
227
|
+
- Initial Release
|
data/README.rdoc
CHANGED
@@ -140,6 +140,15 @@ When the method is called "Information" is returned.
|
|
140
140
|
view = controller.template
|
141
141
|
mock(view).render(:partial => "user_info") {"Information"}
|
142
142
|
|
143
|
+
You can also allow any number of arguments to be passed into the mock by using:
|
144
|
+
mock(view).render.with_any_args.twice do |*args|
|
145
|
+
if args.first == {:partial => "user_info}
|
146
|
+
"User Info"
|
147
|
+
else
|
148
|
+
"Stuff in the view #{args.inspect}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
143
152
|
=== stub
|
144
153
|
stub replaces the method on the object with only an implementation. You
|
145
154
|
can still use arguments to differentiate which stub gets invoked.
|
@@ -322,9 +331,11 @@ With any development effort, there are countless people who have contributed
|
|
322
331
|
to making it possible. We all are standing on the shoulders of giants.
|
323
332
|
* Andreas Haller for patches
|
324
333
|
* Aslak Hellesoy for Developing Rspec
|
334
|
+
* Bryan Helmkamp for patches
|
325
335
|
* Christopher Redinger for patches
|
326
336
|
* Dan North for syntax ideas
|
327
337
|
* Dave Astels for some BDD inspiration
|
338
|
+
* Dave Myron for a bug report
|
328
339
|
* David Chelimsky for encouragement to make the RR framework, for developing the Rspec mock framework, syntax ideas, and patches
|
329
340
|
* Daniel Sudol for identifing performance issues with RR
|
330
341
|
* Felix Morio for pairing with me
|
data/VERSION.yml
CHANGED
data/lib/rr/adapters/rspec.rb
CHANGED
@@ -24,9 +24,11 @@ module RR
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class InvocationMatcher < SpyVerificationProxy
|
27
|
-
attr_reader :failure_message
|
27
|
+
attr_reader :failure_message, :spy_verification_proxy
|
28
28
|
|
29
29
|
def initialize(method = nil)
|
30
|
+
@verification = nil
|
31
|
+
@subject = nil
|
30
32
|
method_missing(method) if method
|
31
33
|
end
|
32
34
|
|
@@ -5,19 +5,21 @@ module RR
|
|
5
5
|
def self.included(mod)
|
6
6
|
RR.trim_backtrace = true
|
7
7
|
mod.class_eval do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
unless instance_methods.include?('setup_with_rr')
|
9
|
+
alias_method :setup_without_rr, :setup
|
10
|
+
def setup_with_rr
|
11
|
+
setup_without_rr
|
12
|
+
RR.reset
|
13
|
+
end
|
14
|
+
alias_method :setup, :setup_with_rr
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
alias_method :teardown_without_rr, :teardown
|
17
|
+
def teardown_with_rr
|
18
|
+
RR.verify
|
19
|
+
teardown_without_rr
|
20
|
+
end
|
21
|
+
alias_method :teardown, :teardown_with_rr
|
19
22
|
end
|
20
|
-
alias_method :teardown, :teardown_with_rr
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
data/lib/rr/errors/rr_error.rb
CHANGED
@@ -5,9 +5,9 @@ module RR
|
|
5
5
|
class RRError < RuntimeError
|
6
6
|
attr_writer :backtrace
|
7
7
|
def backtrace
|
8
|
-
|
8
|
+
@backtrace ||= super
|
9
|
+
original_backtrace = @backtrace
|
9
10
|
return original_backtrace unless RR.trim_backtrace
|
10
|
-
|
11
11
|
return original_backtrace unless original_backtrace.respond_to?(:each)
|
12
12
|
new_backtrace = []
|
13
13
|
original_backtrace.each do |line|
|
@@ -13,6 +13,7 @@ module RR
|
|
13
13
|
@subject_class = subject_class
|
14
14
|
@method_name = method_name.to_sym
|
15
15
|
@doubles = []
|
16
|
+
@bypass_bound_method = nil
|
16
17
|
end
|
17
18
|
|
18
19
|
# RR::DoubleInjection#register_double adds the passed in Double
|
@@ -51,6 +52,7 @@ module RR
|
|
51
52
|
# if one exists.
|
52
53
|
def reset
|
53
54
|
if subject_has_original_method?
|
55
|
+
subject_class.__send__(:remove_method, method_name)
|
54
56
|
subject_class.__send__(:alias_method, method_name, original_method_alias_name)
|
55
57
|
subject_class.__send__(:remove_method, original_method_alias_name)
|
56
58
|
else
|
@@ -3,6 +3,7 @@ module RR
|
|
3
3
|
class MethodMissingInjection < Injection
|
4
4
|
def initialize(subject)
|
5
5
|
@subject = subject
|
6
|
+
@placeholder_method_defined = false
|
6
7
|
end
|
7
8
|
|
8
9
|
def bind
|
@@ -26,9 +27,8 @@ module RR
|
|
26
27
|
memoized_original_method_alias_name = original_method_alias_name
|
27
28
|
placeholder_method_defined = @placeholder_method_defined
|
28
29
|
subject_class.class_eval do
|
29
|
-
|
30
|
-
|
31
|
-
else
|
30
|
+
remove_method :method_missing
|
31
|
+
unless placeholder_method_defined
|
32
32
|
alias_method :method_missing, memoized_original_method_alias_name
|
33
33
|
end
|
34
34
|
remove_method memoized_original_method_alias_name
|
@@ -3,6 +3,7 @@ module RR
|
|
3
3
|
class SingletonMethodAddedInjection < Injection
|
4
4
|
def initialize(subject)
|
5
5
|
@subject = subject
|
6
|
+
@placeholder_method_defined = false
|
6
7
|
end
|
7
8
|
|
8
9
|
def bind
|
@@ -35,9 +36,8 @@ module RR
|
|
35
36
|
memoized_original_method_alias_name = original_method_alias_name
|
36
37
|
placeholder_method_defined = @placeholder_method_defined
|
37
38
|
subject_class.class_eval do
|
38
|
-
|
39
|
-
|
40
|
-
else
|
39
|
+
remove_method :singleton_method_added
|
40
|
+
unless placeholder_method_defined
|
41
41
|
alias_method :singleton_method_added, memoized_original_method_alias_name
|
42
42
|
end
|
43
43
|
remove_method memoized_original_method_alias_name
|
data/ruby_19_spec.rb
ADDED
@@ -885,8 +885,11 @@ module RR
|
|
885
885
|
|
886
886
|
context "when passed a Method" do
|
887
887
|
it "sets the implementation to the passed in method" do
|
888
|
-
|
889
|
-
|
888
|
+
class << subject
|
889
|
+
remove_method :foobar
|
890
|
+
def foobar(a, b)
|
891
|
+
[b, a]
|
892
|
+
end
|
890
893
|
end
|
891
894
|
definition.implemented_by(subject.method(:foobar))
|
892
895
|
subject.foobar(1, 2).should == [2, 1]
|
@@ -11,10 +11,13 @@ module RR
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
before do
|
15
|
+
@subject = Object.new
|
16
|
+
end
|
17
|
+
|
14
18
|
describe "mock/stub" do
|
15
19
|
context "when the subject responds to the injected method" do
|
16
20
|
before do
|
17
|
-
@subject = Object.new
|
18
21
|
class << subject
|
19
22
|
attr_reader :original_foobar_called
|
20
23
|
|
@@ -24,10 +27,6 @@ module RR
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
def subject.foobar
|
28
|
-
:original_foobar
|
29
|
-
end
|
30
|
-
|
31
30
|
subject.should respond_to(:foobar)
|
32
31
|
subject.methods.should include('foobar')
|
33
32
|
stub(subject).foobar {:new_foobar}
|
@@ -67,7 +66,6 @@ module RR
|
|
67
66
|
|
68
67
|
context "when the subject does not respond to the injected method" do
|
69
68
|
before do
|
70
|
-
@subject = Object.new
|
71
69
|
subject.should_not respond_to(:foobar)
|
72
70
|
subject.methods.should_not include('foobar')
|
73
71
|
stub(subject).foobar {:new_foobar}
|
@@ -113,8 +111,6 @@ module RR
|
|
113
111
|
context "when the subject has the method defined" do
|
114
112
|
describe "being bound" do
|
115
113
|
before do
|
116
|
-
@subject = Object.new
|
117
|
-
|
118
114
|
def subject.foobar
|
119
115
|
:original_foobar
|
120
116
|
end
|
@@ -161,7 +157,6 @@ module RR
|
|
161
157
|
describe "being bound" do
|
162
158
|
context "when the subject has not been previously bound to" do
|
163
159
|
before do
|
164
|
-
@subject = Object.new
|
165
160
|
setup_subject
|
166
161
|
|
167
162
|
subject.should respond_to(:foobar)
|
@@ -313,7 +308,6 @@ module RR
|
|
313
308
|
|
314
309
|
context "when the subject has been previously bound to" do
|
315
310
|
before do
|
316
|
-
@subject = Object.new
|
317
311
|
setup_subject
|
318
312
|
|
319
313
|
subject.should respond_to(:foobar)
|
@@ -471,7 +465,6 @@ module RR
|
|
471
465
|
context "when the subject responds to the method via method_missing" do
|
472
466
|
describe "being bound" do
|
473
467
|
before do
|
474
|
-
@subject = Object.new
|
475
468
|
subject.should_not respond_to(:foobar)
|
476
469
|
subject.methods.should_not include('foobar')
|
477
470
|
class << subject
|
@@ -516,7 +509,6 @@ module RR
|
|
516
509
|
context "when the subject would raise a NoMethodError when the method is called" do
|
517
510
|
describe "being bound" do
|
518
511
|
before do
|
519
|
-
@subject = Object.new
|
520
512
|
subject.should_not respond_to(:foobar)
|
521
513
|
subject.methods.should_not include('foobar')
|
522
514
|
stub.proxy(subject).foobar {:new_foobar}
|
data/spec/rr/double_spec.rb
CHANGED
@@ -160,8 +160,11 @@ module RR
|
|
160
160
|
|
161
161
|
describe "when implemented by a method" do
|
162
162
|
it "sends block to the method" do
|
163
|
-
|
164
|
-
|
163
|
+
class << subject
|
164
|
+
remove_method :foobar
|
165
|
+
def foobar(a, b)
|
166
|
+
yield(a, b)
|
167
|
+
end
|
165
168
|
end
|
166
169
|
|
167
170
|
double.definition.with(1, 2).implemented_by(subject.method(:foobar))
|
data/spec/spec_suite.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "session"
|
3
|
+
|
1
4
|
class ExampleSuite
|
5
|
+
attr_reader :bash
|
6
|
+
def initialize
|
7
|
+
@bash = Session::Bash.new
|
8
|
+
end
|
9
|
+
|
2
10
|
def run
|
3
11
|
run_core_examples
|
4
12
|
run_rspec_examples
|
@@ -6,15 +14,24 @@ class ExampleSuite
|
|
6
14
|
end
|
7
15
|
|
8
16
|
def run_core_examples
|
9
|
-
|
17
|
+
run_suite("#{dir}/core_spec_suite.rb #{spec_opts}") || raise("Core suite Failed")
|
10
18
|
end
|
11
19
|
|
12
20
|
def run_rspec_examples
|
13
|
-
|
21
|
+
run_suite("#{dir}/rspec_spec_suite.rb #{spec_opts}") || raise("Rspec suite Failed")
|
14
22
|
end
|
15
23
|
|
16
24
|
def run_test_unit_examples
|
17
|
-
|
25
|
+
run_suite("#{dir}/test_unit_spec_suite.rb") || raise("Test::Unit suite Failed")
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_suite(path)
|
29
|
+
# From http://www.eglug.org/node/946
|
30
|
+
bash.execute "exec 3>&1", :out => STDOUT, :err => STDERR
|
31
|
+
bash.execute "ruby -W #{path} 2>&1 >&3 3>&- | grep -v 'warning: useless use of' 3>&-; STATUS=${PIPESTATUS[0]}", :out => STDOUT, :err => STDERR
|
32
|
+
status = bash.execute("echo $STATUS")[0].to_s.strip.to_i
|
33
|
+
bash.execute "exec 3>&-", :out => STDOUT, :err => STDERR
|
34
|
+
return status == 0
|
18
35
|
end
|
19
36
|
|
20
37
|
def spec_opts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Takita
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/rr/wildcard_matchers/range.rb
|
96
96
|
- lib/rr/wildcard_matchers/regexp.rb
|
97
97
|
- lib/rr/wildcard_matchers/satisfy.rb
|
98
|
+
- ruby_19_spec.rb
|
98
99
|
- spec/core_spec_suite.rb
|
99
100
|
- spec/environment_fixture_setup.rb
|
100
101
|
- spec/high_level_spec.rb
|