rr 1.0.5 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/CHANGES.md +24 -0
- data/LICENSE +2 -2
- data/README.md +124 -741
- data/VERSION +1 -1
- data/lib/rr.rb +2 -103
- data/lib/rr/adapters/minitest.rb +21 -13
- data/lib/rr/adapters/minitest_active_support.rb +34 -0
- data/lib/rr/adapters/none.rb +17 -0
- data/lib/rr/adapters/{rspec.rb → rspec/invocation_matcher.rb} +2 -27
- data/lib/rr/adapters/rspec_1.rb +42 -0
- data/lib/rr/adapters/rspec_2.rb +24 -0
- data/lib/rr/adapters/test_unit_1.rb +54 -0
- data/lib/rr/adapters/test_unit_2.rb +13 -0
- data/lib/rr/adapters/test_unit_2_active_support.rb +35 -0
- data/lib/rr/autohook.rb +43 -0
- data/lib/rr/core_ext/array.rb +12 -0
- data/lib/rr/core_ext/enumerable.rb +16 -0
- data/lib/rr/core_ext/hash.rb +20 -0
- data/lib/rr/core_ext/range.rb +8 -0
- data/lib/rr/core_ext/regexp.rb +8 -0
- data/lib/rr/double.rb +4 -4
- data/lib/rr/double_definitions/double_definition.rb +9 -3
- data/lib/rr/errors.rb +21 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +10 -7
- data/lib/rr/expectations/times_called_expectation.rb +2 -8
- data/lib/rr/injections/double_injection.rb +1 -1
- data/lib/rr/method_dispatches/base_method_dispatch.rb +1 -1
- data/lib/rr/recorded_calls.rb +12 -12
- data/lib/rr/space.rb +5 -3
- data/lib/rr/times_called_matchers/never_matcher.rb +2 -2
- data/lib/rr/wildcard_matchers/anything.rb +2 -2
- data/lib/rr/wildcard_matchers/boolean.rb +3 -7
- data/lib/rr/wildcard_matchers/duck_type.rb +11 -15
- data/lib/rr/wildcard_matchers/hash_including.rb +14 -13
- data/lib/rr/wildcard_matchers/is_a.rb +6 -7
- data/lib/rr/wildcard_matchers/satisfy.rb +8 -8
- data/lib/rr/without_autohook.rb +112 -0
- data/rr.gemspec +28 -0
- data/spec/global_helper.rb +12 -0
- data/spec/suite.rb +93 -0
- data/spec/suites/common/adapter_tests.rb +37 -0
- data/spec/suites/common/rails_integration_test.rb +175 -0
- data/spec/suites/common/test_unit_tests.rb +25 -0
- data/spec/suites/minitest/integration/minitest_test.rb +13 -0
- data/spec/suites/minitest/test_helper.rb +3 -0
- data/spec/suites/rspec_1/integration/rspec_1_spec.rb +20 -0
- data/spec/suites/rspec_1/integration/test_unit_1_rails_spec.rb +19 -0
- data/spec/suites/rspec_1/integration/test_unit_2_rails_spec.rb +18 -0
- data/spec/suites/rspec_1/spec_helper.rb +24 -0
- data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +47 -0
- data/spec/suites/rspec_2/functional/dont_allow_spec.rb +12 -0
- data/spec/suites/rspec_2/functional/dsl_spec.rb +13 -0
- data/spec/suites/rspec_2/functional/instance_of_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_spec.rb +241 -0
- data/spec/suites/rspec_2/functional/proxy_spec.rb +136 -0
- data/spec/suites/rspec_2/functional/spy_spec.rb +41 -0
- data/spec/suites/rspec_2/functional/strong_spec.rb +79 -0
- data/spec/suites/rspec_2/functional/stub_spec.rb +190 -0
- data/spec/suites/rspec_2/functional/wildcard_matchers_spec.rb +128 -0
- data/spec/suites/rspec_2/integration/minitest_rails_spec.rb +15 -0
- data/spec/suites/rspec_2/integration/rspec_2_spec.rb +20 -0
- data/spec/suites/rspec_2/integration/test_unit_rails_spec.rb +14 -0
- data/spec/suites/rspec_2/spec_helper.rb +27 -0
- data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +32 -0
- data/spec/suites/rspec_2/support/shared_examples/space.rb +13 -0
- data/spec/suites/rspec_2/support/shared_examples/times_called_expectation.rb +9 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +135 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +101 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/adapters/rspec/invocation_matcher_spec.rb +297 -0
- data/spec/suites/rspec_2/unit/adapters/rspec_spec.rb +85 -0
- data/spec/suites/rspec_2/unit/core_ext/array_spec.rb +39 -0
- data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +81 -0
- data/spec/suites/rspec_2/unit/core_ext/hash_spec.rb +55 -0
- data/spec/suites/rspec_2/unit/core_ext/range_spec.rb +41 -0
- data/spec/suites/rspec_2/unit/core_ext/regexp_spec.rb +41 -0
- data/spec/suites/rspec_2/unit/double_definitions/child_double_definition_create_spec.rb +114 -0
- data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_blank_slate_spec.rb +93 -0
- data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +446 -0
- data/spec/suites/rspec_2/unit/errors/rr_error_spec.rb +67 -0
- data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +48 -0
- data/spec/suites/rspec_2/unit/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +30 -0
- data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/suites/rspec_2/unit/expectations/satisfy_argument_equality_expectation_spec.rb +61 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/any_times_matcher_spec.rb +22 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_least_matcher_spec.rb +37 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_most_matcher_spec.rb +43 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb +58 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/proc_matcher_spec.rb +35 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/range_matcher_spec.rb +39 -0
- data/spec/suites/rspec_2/unit/hash_with_object_id_key_spec.rb +88 -0
- data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +545 -0
- data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_verify_spec.rb +32 -0
- data/spec/suites/rspec_2/unit/proc_from_block_spec.rb +14 -0
- data/spec/suites/rspec_2/unit/rr_spec.rb +28 -0
- data/spec/suites/rspec_2/unit/space_spec.rb +595 -0
- data/spec/suites/rspec_2/unit/spy_verification_spec.rb +133 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/any_times_matcher_spec.rb +46 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/at_least_matcher_spec.rb +54 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/at_most_matcher_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/integer_matcher_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/proc_matcher_spec.rb +54 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/range_matcher_spec.rb +75 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/times_called_matcher_spec.rb +117 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/anything_spec.rb +33 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/boolean_spec.rb +45 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/duck_type_spec.rb +64 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/hash_including_spec.rb +64 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/is_a_spec.rb +55 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/numeric_spec.rb +46 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/satisfy_spec.rb +57 -0
- data/spec/suites/test_unit_1/integration/test_unit_1_test.rb +6 -0
- data/spec/suites/test_unit_1/test_helper.rb +7 -0
- data/spec/suites/test_unit_2/integration/test_unit_2_test.rb +6 -0
- data/spec/suites/test_unit_2/test_helper.rb +3 -0
- metadata +183 -19
- data/Gemfile +0 -9
- data/Rakefile +0 -34
- data/lib/rr/adapters/rspec2.rb +0 -30
- data/lib/rr/adapters/test_unit.rb +0 -33
- data/lib/rr/errors/argument_equality_error.rb +0 -6
- data/lib/rr/wildcard_matchers/range.rb +0 -7
- data/lib/rr/wildcard_matchers/regexp.rb +0 -7
- data/spec/runner.rb +0 -41
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.1.0.rc1
|
data/lib/rr.rb
CHANGED
@@ -1,103 +1,2 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
require "#{dir}/rr/class_instance_method_defined"
|
5
|
-
require "#{dir}/rr/blank_slate"
|
6
|
-
|
7
|
-
require "#{dir}/rr/errors/rr_error"
|
8
|
-
require "#{dir}/rr/errors/subject_does_not_implement_method_error"
|
9
|
-
require "#{dir}/rr/errors/subject_has_different_arity_error"
|
10
|
-
require "#{dir}/rr/errors/double_definition_error"
|
11
|
-
require "#{dir}/rr/errors/double_not_found_error"
|
12
|
-
require "#{dir}/rr/errors/double_order_error"
|
13
|
-
require "#{dir}/rr/errors/argument_equality_error"
|
14
|
-
require "#{dir}/rr/errors/times_called_error"
|
15
|
-
require "#{dir}/rr/errors/spy_verification_errors/spy_verification_error"
|
16
|
-
require "#{dir}/rr/errors/spy_verification_errors/double_injection_not_found_error"
|
17
|
-
require "#{dir}/rr/errors/spy_verification_errors/invocation_count_error"
|
18
|
-
|
19
|
-
require "#{dir}/rr/space"
|
20
|
-
|
21
|
-
require "#{dir}/rr/double_definitions/strategies/strategy"
|
22
|
-
require "#{dir}/rr/double_definitions/strategies/strategy_methods"
|
23
|
-
require "#{dir}/rr/double_definitions/strategies/verification/verification_strategy"
|
24
|
-
require "#{dir}/rr/double_definitions/strategies/verification/mock"
|
25
|
-
require "#{dir}/rr/double_definitions/strategies/verification/stub"
|
26
|
-
require "#{dir}/rr/double_definitions/strategies/verification/dont_allow"
|
27
|
-
require "#{dir}/rr/double_definitions/strategies/implementation/implementation_strategy"
|
28
|
-
require "#{dir}/rr/double_definitions/strategies/implementation/reimplementation"
|
29
|
-
require "#{dir}/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation"
|
30
|
-
require "#{dir}/rr/double_definitions/strategies/implementation/proxy"
|
31
|
-
require "#{dir}/rr/double_definitions/strategies/double_injection/double_injection_strategy"
|
32
|
-
require "#{dir}/rr/double_definitions/strategies/double_injection/instance"
|
33
|
-
require "#{dir}/rr/double_definitions/strategies/double_injection/any_instance_of"
|
34
|
-
require "#{dir}/rr/adapters/rr_methods"
|
35
|
-
require "#{dir}/rr/double_definitions/double_injections/instance"
|
36
|
-
require "#{dir}/rr/double_definitions/double_injections/any_instance_of"
|
37
|
-
require "#{dir}/rr/double_definitions/double_definition"
|
38
|
-
|
39
|
-
require "#{dir}/rr/injections/injection"
|
40
|
-
require "#{dir}/rr/injections/double_injection"
|
41
|
-
require "#{dir}/rr/injections/method_missing_injection"
|
42
|
-
require "#{dir}/rr/injections/singleton_method_added_injection"
|
43
|
-
require "#{dir}/rr/method_dispatches/base_method_dispatch"
|
44
|
-
require "#{dir}/rr/method_dispatches/method_dispatch"
|
45
|
-
require "#{dir}/rr/method_dispatches/method_missing_dispatch"
|
46
|
-
require "#{dir}/rr/hash_with_object_id_key"
|
47
|
-
require "#{dir}/rr/recorded_calls"
|
48
|
-
require "#{dir}/rr/proc_from_block"
|
49
|
-
|
50
|
-
require "#{dir}/rr/double_definitions/double_definition_create_blank_slate"
|
51
|
-
require "#{dir}/rr/double_definitions/double_definition_create"
|
52
|
-
require "#{dir}/rr/double_definitions/child_double_definition_create"
|
53
|
-
|
54
|
-
require "#{dir}/rr/double"
|
55
|
-
require "#{dir}/rr/double_matches"
|
56
|
-
|
57
|
-
require "#{dir}/rr/expectations/argument_equality_expectation"
|
58
|
-
require "#{dir}/rr/expectations/any_argument_expectation"
|
59
|
-
require "#{dir}/rr/expectations/times_called_expectation"
|
60
|
-
|
61
|
-
require "#{dir}/rr/wildcard_matchers/anything"
|
62
|
-
require "#{dir}/rr/wildcard_matchers/is_a"
|
63
|
-
require "#{dir}/rr/wildcard_matchers/numeric"
|
64
|
-
require "#{dir}/rr/wildcard_matchers/boolean"
|
65
|
-
require "#{dir}/rr/wildcard_matchers/duck_type"
|
66
|
-
require "#{dir}/rr/wildcard_matchers/regexp"
|
67
|
-
require "#{dir}/rr/wildcard_matchers/range"
|
68
|
-
require "#{dir}/rr/wildcard_matchers/satisfy"
|
69
|
-
require "#{dir}/rr/wildcard_matchers/hash_including"
|
70
|
-
|
71
|
-
require "#{dir}/rr/times_called_matchers/terminal"
|
72
|
-
require "#{dir}/rr/times_called_matchers/non_terminal"
|
73
|
-
require "#{dir}/rr/times_called_matchers/times_called_matcher"
|
74
|
-
require "#{dir}/rr/times_called_matchers/never_matcher"
|
75
|
-
require "#{dir}/rr/times_called_matchers/any_times_matcher"
|
76
|
-
require "#{dir}/rr/times_called_matchers/integer_matcher"
|
77
|
-
require "#{dir}/rr/times_called_matchers/range_matcher"
|
78
|
-
require "#{dir}/rr/times_called_matchers/proc_matcher"
|
79
|
-
require "#{dir}/rr/times_called_matchers/at_least_matcher"
|
80
|
-
require "#{dir}/rr/times_called_matchers/at_most_matcher"
|
81
|
-
|
82
|
-
require "#{dir}/rr/spy_verification_proxy"
|
83
|
-
require "#{dir}/rr/spy_verification"
|
84
|
-
|
85
|
-
require "#{dir}/rr/adapters/rspec"
|
86
|
-
require "#{dir}/rr/adapters/rspec2"
|
87
|
-
require "#{dir}/rr/adapters/test_unit"
|
88
|
-
require "#{dir}/rr/adapters/minitest"
|
89
|
-
|
90
|
-
require "#{dir}/rr/version"
|
91
|
-
|
92
|
-
module RR
|
93
|
-
class << self
|
94
|
-
include Adapters::RRMethods
|
95
|
-
(RR::Space.instance_methods - Object.instance_methods).each do |method_name|
|
96
|
-
class_eval((<<-METHOD), __FILE__, __LINE__ + 1)
|
97
|
-
def #{method_name}(*args, &block)
|
98
|
-
RR::Space.instance.__send__(:#{method_name}, *args, &block)
|
99
|
-
end
|
100
|
-
METHOD
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
1
|
+
require 'rr/without_autohook'
|
2
|
+
require 'rr/autohook'
|
data/lib/rr/adapters/minitest.rb
CHANGED
@@ -1,26 +1,38 @@
|
|
1
1
|
module RR
|
2
2
|
module Adapters
|
3
|
-
|
4
|
-
|
3
|
+
class MiniTest
|
4
|
+
module AdapterMethods
|
5
|
+
def assert_received(subject, &block)
|
6
|
+
block.call(received(subject)).call
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
'MiniTest'
|
12
|
+
end
|
13
|
+
|
14
|
+
def applies?
|
15
|
+
defined?(::MiniTest)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hook
|
19
|
+
::MiniTest::Unit::TestCase.class_eval do
|
20
|
+
include RRMethods
|
21
|
+
include AdapterMethods
|
5
22
|
|
6
|
-
def self.included(mod)
|
7
|
-
RR.trim_backtrace = true
|
8
|
-
mod.class_eval do
|
9
23
|
unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
|
10
24
|
alias_method :setup_without_rr, :setup
|
11
25
|
def setup_with_rr
|
12
26
|
setup_without_rr
|
13
27
|
RR.reset
|
28
|
+
RR.trim_backtrace = true
|
29
|
+
RR.overridden_error_class = ::MiniTest::Assertion
|
14
30
|
end
|
15
31
|
alias_method :setup, :setup_with_rr
|
16
32
|
|
17
33
|
alias_method :teardown_without_rr, :teardown
|
18
34
|
def teardown_with_rr
|
19
35
|
RR.verify
|
20
|
-
rescue RR::Errors::RRError => rr_error
|
21
|
-
assertion = ::MiniTest::Assertion.new(rr_error.message)
|
22
|
-
assertion.set_backtrace(rr_error.backtrace)
|
23
|
-
raise assertion
|
24
36
|
ensure
|
25
37
|
teardown_without_rr
|
26
38
|
end
|
@@ -28,10 +40,6 @@ module RR
|
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
31
|
-
|
32
|
-
def assert_received(subject, &block)
|
33
|
-
block.call(received(subject)).call
|
34
|
-
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RR
|
2
|
+
module Adapters
|
3
|
+
class MiniTestActiveSupport
|
4
|
+
def initialize
|
5
|
+
@mt_adapter = MiniTest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
'MiniTest w/ ActiveSupport'
|
10
|
+
end
|
11
|
+
|
12
|
+
def applies?
|
13
|
+
@mt_adapter.applies? && defined?(::ActiveSupport::TestCase)
|
14
|
+
end
|
15
|
+
|
16
|
+
def hook
|
17
|
+
::ActiveSupport::TestCase.class_eval do
|
18
|
+
include RRMethods
|
19
|
+
include MiniTest::AdapterMethods
|
20
|
+
|
21
|
+
setup do
|
22
|
+
RR.reset
|
23
|
+
RR.trim_backtrace = true
|
24
|
+
RR.overridden_error_class = ::ActiveSupport::TestCase::Assertion
|
25
|
+
end
|
26
|
+
|
27
|
+
teardown do
|
28
|
+
RR.verify
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,34 +1,9 @@
|
|
1
1
|
module RR
|
2
2
|
module Adapters
|
3
|
-
module
|
4
|
-
def self.included(mod)
|
5
|
-
patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
|
6
|
-
unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
|
7
|
-
patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
include RRMethods
|
12
|
-
|
13
|
-
def setup_mocks_for_rspec
|
14
|
-
RR.reset
|
15
|
-
end
|
16
|
-
|
17
|
-
def verify_mocks_for_rspec
|
18
|
-
RR.verify
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown_mocks_for_rspec
|
22
|
-
RR.reset
|
23
|
-
end
|
24
|
-
|
25
|
-
def have_received(method = nil)
|
26
|
-
InvocationMatcher.new(method)
|
27
|
-
end
|
28
|
-
|
3
|
+
module RSpec
|
29
4
|
class InvocationMatcher < SpyVerificationProxy
|
30
5
|
attr_reader :failure_message, :spy_verification_proxy
|
31
|
-
|
6
|
+
|
32
7
|
def initialize(method = nil)
|
33
8
|
@verification = nil
|
34
9
|
@subject = nil
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RR
|
2
|
+
module Adapters
|
3
|
+
class RSpec1
|
4
|
+
module AdapterMethods
|
5
|
+
def setup_mocks_for_rspec
|
6
|
+
RR.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_mocks_for_rspec
|
10
|
+
RR.verify
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown_mocks_for_rspec
|
14
|
+
RR.reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def have_received(method = nil)
|
18
|
+
RSpec::InvocationMatcher.new(method)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
'RSpec 1'
|
24
|
+
end
|
25
|
+
|
26
|
+
def applies?
|
27
|
+
defined?(::Spec)
|
28
|
+
end
|
29
|
+
|
30
|
+
def hook
|
31
|
+
::Spec::Runner.configure do |config|
|
32
|
+
config.mock_with AdapterMethods
|
33
|
+
config.include RRMethods
|
34
|
+
end
|
35
|
+
patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
|
36
|
+
unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
|
37
|
+
patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RR
|
2
|
+
module Adapters
|
3
|
+
class RSpec2 < RSpec1
|
4
|
+
def name
|
5
|
+
'RSpec 2'
|
6
|
+
end
|
7
|
+
|
8
|
+
def applies?
|
9
|
+
defined?(::RSpec)
|
10
|
+
end
|
11
|
+
|
12
|
+
def hook
|
13
|
+
::RSpec.configure do |config|
|
14
|
+
config.mock_with AdapterMethods
|
15
|
+
config.include RRMethods
|
16
|
+
end
|
17
|
+
patterns = ::RSpec.configuration.backtrace_clean_patterns
|
18
|
+
unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
|
19
|
+
patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RR
|
2
|
+
module Adapters
|
3
|
+
class TestUnit1
|
4
|
+
module AdapterMethods
|
5
|
+
def assert_received(subject, &block)
|
6
|
+
block.call(received(subject)).call
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
'Test::Unit 1'
|
12
|
+
end
|
13
|
+
|
14
|
+
def applies?
|
15
|
+
defined?(::Test::Unit) && !has_test_unit_version?
|
16
|
+
end
|
17
|
+
|
18
|
+
def hook(test_case_class = ::Test::Unit::TestCase)
|
19
|
+
test_case_class.class_eval do
|
20
|
+
include RRMethods
|
21
|
+
include AdapterMethods
|
22
|
+
|
23
|
+
unless instance_methods.detect {|method_name| method_name.to_sym == :setup_with_rr }
|
24
|
+
alias_method :setup_without_rr, :setup
|
25
|
+
def setup_with_rr
|
26
|
+
setup_without_rr
|
27
|
+
RR.reset
|
28
|
+
RR.trim_backtrace = true
|
29
|
+
RR.overridden_error_class = ::Test::Unit::AssertionFailedError
|
30
|
+
end
|
31
|
+
alias_method :setup, :setup_with_rr
|
32
|
+
|
33
|
+
alias_method :teardown_without_rr, :teardown
|
34
|
+
def teardown_with_rr
|
35
|
+
RR.verify
|
36
|
+
ensure
|
37
|
+
teardown_without_rr
|
38
|
+
end
|
39
|
+
alias_method :teardown, :teardown_with_rr
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def has_test_unit_version?
|
47
|
+
require 'test/unit/version'
|
48
|
+
true
|
49
|
+
rescue LoadError
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RR
|
2
|
+
module Adapters
|
3
|
+
class TestUnit2ActiveSupport
|
4
|
+
def initialize
|
5
|
+
@tu2_adapter = TestUnit2.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
'Test::Unit 2 w/ ActiveSupport'
|
10
|
+
end
|
11
|
+
|
12
|
+
def applies?
|
13
|
+
@tu2_adapter.applies? && defined?(::ActiveSupport::TestCase)
|
14
|
+
end
|
15
|
+
|
16
|
+
def hook
|
17
|
+
RR.trim_backtrace = true
|
18
|
+
RR.overridden_error_class = ::Test::Unit::AssertionFailedError
|
19
|
+
|
20
|
+
::ActiveSupport::TestCase.class_eval do
|
21
|
+
include RRMethods
|
22
|
+
include TestUnit1::AdapterMethods
|
23
|
+
|
24
|
+
setup do
|
25
|
+
RR.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
teardown do
|
29
|
+
RR.verify
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rr/autohook.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module RR
|
2
|
+
class << self
|
3
|
+
ADAPTER_NAMES = [
|
4
|
+
:RSpec1,
|
5
|
+
:RSpec2,
|
6
|
+
:TestUnit1,
|
7
|
+
:TestUnit2ActiveSupport,
|
8
|
+
:TestUnit2,
|
9
|
+
:MiniTestActiveSupport,
|
10
|
+
:MiniTest
|
11
|
+
]
|
12
|
+
|
13
|
+
def autohook
|
14
|
+
find_applicable_adapters.each do |adapter|
|
15
|
+
#puts "Using adapter: #{adapter.name}"
|
16
|
+
adapter.hook
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def adapters
|
23
|
+
@adapters ||= ADAPTER_NAMES.map { |adapter_name|
|
24
|
+
[adapter_name, RR::Adapters.const_get(adapter_name).new]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_applicable_adapters
|
29
|
+
@applicable_adapters ||= begin
|
30
|
+
applicable_adapters = adapters.inject([]) { |arr, (_, adapter)|
|
31
|
+
arr << adapter if adapter.applies?
|
32
|
+
arr
|
33
|
+
}
|
34
|
+
if applicable_adapters.empty?
|
35
|
+
applicable_adapters << adapters.index(:None)
|
36
|
+
end
|
37
|
+
applicable_adapters
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RR.autohook
|