mocha 0.5.6 → 3.1.0
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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +39 -0
- data/.yardopts +25 -0
- data/CONTRIBUTING.md +7 -0
- data/COPYING.md +3 -0
- data/Gemfile +17 -0
- data/{MIT-LICENSE → MIT-LICENSE.md} +2 -2
- data/README.md +361 -0
- data/RELEASE.md +1247 -0
- data/Rakefile +165 -123
- data/gemfiles/Gemfile.minitest.latest +8 -0
- data/gemfiles/Gemfile.rubocop +9 -0
- data/gemfiles/Gemfile.test-unit.latest +8 -0
- data/lib/mocha/any_instance_method.rb +12 -26
- data/lib/mocha/any_instance_receiver.rb +20 -0
- data/lib/mocha/api.rb +213 -0
- data/lib/mocha/argument_iterator.rb +17 -0
- data/lib/mocha/backtrace_filter.rb +25 -0
- data/lib/mocha/block_matchers.rb +33 -0
- data/lib/mocha/cardinality.rb +110 -0
- data/lib/mocha/central.rb +33 -22
- data/lib/mocha/change_state_side_effect.rb +17 -0
- data/lib/mocha/class_methods.rb +67 -0
- data/lib/mocha/configuration.rb +338 -0
- data/lib/mocha/default_name.rb +15 -0
- data/lib/mocha/default_receiver.rb +13 -0
- data/lib/mocha/deprecation.rb +6 -15
- data/lib/mocha/detection/minitest.rb +25 -0
- data/lib/mocha/detection/test_unit.rb +30 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +15 -0
- data/lib/mocha/exception_raiser.rb +11 -10
- data/lib/mocha/expectation.rb +562 -171
- data/lib/mocha/expectation_error.rb +9 -14
- data/lib/mocha/expectation_error_factory.rb +37 -0
- data/lib/mocha/expectation_list.rb +30 -14
- data/lib/mocha/hooks.rb +55 -0
- data/lib/mocha/ignoring_warning.rb +20 -0
- data/lib/mocha/impersonating_any_instance_name.rb +13 -0
- data/lib/mocha/impersonating_name.rb +13 -0
- data/lib/mocha/in_state_ordering_constraint.rb +17 -0
- data/lib/mocha/inspect.rb +54 -30
- data/lib/mocha/instance_method.rb +17 -4
- data/lib/mocha/integration/assertion_counter.rb +15 -0
- data/lib/mocha/integration/minitest/adapter.rb +71 -0
- data/lib/mocha/integration/minitest.rb +29 -0
- data/lib/mocha/integration/monkey_patcher.rb +26 -0
- data/lib/mocha/integration/test_unit/adapter.rb +61 -0
- data/lib/mocha/integration/test_unit.rb +29 -0
- data/lib/mocha/integration.rb +5 -0
- data/lib/mocha/invocation.rb +76 -0
- data/lib/mocha/logger.rb +26 -0
- data/lib/mocha/macos_version.rb +7 -0
- data/lib/mocha/method_matcher.rb +8 -10
- data/lib/mocha/minitest.rb +7 -0
- data/lib/mocha/mock.rb +333 -108
- data/lib/mocha/mockery.rb +192 -0
- data/lib/mocha/name.rb +13 -0
- data/lib/mocha/not_initialized_error.rb +9 -0
- data/lib/mocha/object_methods.rb +183 -0
- data/lib/mocha/object_receiver.rb +20 -0
- data/lib/mocha/parameter_matchers/all_of.rb +38 -28
- data/lib/mocha/parameter_matchers/any_of.rb +44 -33
- data/lib/mocha/parameter_matchers/any_parameters.rb +33 -26
- data/lib/mocha/parameter_matchers/anything.rb +31 -22
- data/lib/mocha/parameter_matchers/base_methods.rb +64 -0
- data/lib/mocha/parameter_matchers/equals.rb +36 -25
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +65 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +48 -29
- data/lib/mocha/parameter_matchers/has_entry.rb +90 -42
- data/lib/mocha/parameter_matchers/has_key.rb +39 -26
- data/lib/mocha/parameter_matchers/has_keys.rb +59 -0
- data/lib/mocha/parameter_matchers/has_value.rb +39 -26
- data/lib/mocha/parameter_matchers/includes.rb +88 -23
- data/lib/mocha/parameter_matchers/instance_methods.rb +28 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +37 -26
- data/lib/mocha/parameter_matchers/is_a.rb +38 -26
- data/lib/mocha/parameter_matchers/kind_of.rb +39 -26
- data/lib/mocha/parameter_matchers/not.rb +37 -26
- data/lib/mocha/parameter_matchers/optionally.rb +52 -17
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +91 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +37 -25
- data/lib/mocha/parameter_matchers/responds_with.rb +82 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +55 -0
- data/lib/mocha/parameter_matchers.rb +12 -5
- data/lib/mocha/parameters_matcher.rb +28 -19
- data/lib/mocha/raised_exception.rb +13 -0
- data/lib/mocha/return_values.rb +13 -18
- data/lib/mocha/ruby_version.rb +7 -0
- data/lib/mocha/sequence.rb +23 -17
- data/lib/mocha/single_return_value.rb +8 -18
- data/lib/mocha/state_machine.rb +95 -0
- data/lib/mocha/stubbed_method.rb +96 -0
- data/lib/mocha/stubbing_error.rb +10 -0
- data/lib/mocha/test_unit.rb +7 -0
- data/lib/mocha/thrower.rb +15 -0
- data/lib/mocha/thrown_object.rb +14 -0
- data/lib/mocha/version.rb +5 -0
- data/lib/mocha/yield_parameters.rb +12 -20
- data/lib/mocha.rb +19 -17
- data/mocha.gemspec +40 -0
- metadata +129 -145
- data/COPYING +0 -3
- data/README +0 -35
- data/RELEASE +0 -188
- data/examples/misc.rb +0 -44
- data/examples/mocha.rb +0 -26
- data/examples/stubba.rb +0 -65
- data/lib/mocha/auto_verify.rb +0 -118
- data/lib/mocha/class_method.rb +0 -66
- data/lib/mocha/infinite_range.rb +0 -25
- data/lib/mocha/is_a.rb +0 -9
- data/lib/mocha/metaclass.rb +0 -7
- data/lib/mocha/missing_expectation.rb +0 -17
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/object.rb +0 -110
- data/lib/mocha/parameter_matchers/base.rb +0 -15
- data/lib/mocha/parameter_matchers/object.rb +0 -9
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/setup_and_teardown.rb +0 -23
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -32
- data/lib/mocha/stub.rb +0 -18
- data/lib/mocha/test_case_adapter.rb +0 -49
- data/lib/mocha_standalone.rb +0 -2
- data/lib/stubba.rb +0 -2
- data/test/acceptance/expected_invocation_count_acceptance_test.rb +0 -187
- data/test/acceptance/mocha_acceptance_test.rb +0 -98
- data/test/acceptance/mock_with_initializer_block_acceptance_test.rb +0 -44
- data/test/acceptance/mocked_methods_dispatch_acceptance_test.rb +0 -71
- data/test/acceptance/optional_parameters_acceptance_test.rb +0 -63
- data/test/acceptance/parameter_matcher_acceptance_test.rb +0 -117
- data/test/acceptance/partial_mocks_acceptance_test.rb +0 -40
- data/test/acceptance/sequence_acceptance_test.rb +0 -179
- data/test/acceptance/standalone_acceptance_test.rb +0 -131
- data/test/acceptance/stubba_acceptance_test.rb +0 -102
- data/test/active_record_test_case.rb +0 -36
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -34
- data/test/integration/mocha_test_result_integration_test.rb +0 -105
- data/test/integration/stubba_integration_test.rb +0 -89
- data/test/integration/stubba_test_result_integration_test.rb +0 -85
- data/test/method_definer.rb +0 -18
- data/test/test_helper.rb +0 -12
- data/test/test_runner.rb +0 -31
- data/test/unit/any_instance_method_test.rb +0 -126
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/auto_verify_test.rb +0 -129
- data/test/unit/central_test.rb +0 -124
- data/test/unit/class_method_test.rb +0 -200
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/expectation_error_test.rb +0 -24
- data/test/unit/expectation_list_test.rb +0 -75
- data/test/unit/expectation_raiser_test.rb +0 -28
- data/test/unit/expectation_test.rb +0 -483
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/infinite_range_test.rb +0 -53
- data/test/unit/metaclass_test.rb +0 -22
- data/test/unit/method_matcher_test.rb +0 -23
- data/test/unit/missing_expectation_test.rb +0 -42
- data/test/unit/mock_test.rb +0 -323
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yield_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -37
- data/test/unit/object_test.rb +0 -165
- data/test/unit/parameter_matchers/all_of_test.rb +0 -26
- data/test/unit/parameter_matchers/any_of_test.rb +0 -26
- data/test/unit/parameter_matchers/anything_test.rb +0 -21
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -30
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -40
- data/test/unit/parameter_matchers/has_key_test.rb +0 -25
- data/test/unit/parameter_matchers/has_value_test.rb +0 -25
- data/test/unit/parameter_matchers/includes_test.rb +0 -25
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
- data/test/unit/parameter_matchers/is_a_test.rb +0 -25
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
- data/test/unit/parameter_matchers/not_test.rb +0 -26
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -25
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -121
- data/test/unit/return_values_test.rb +0 -63
- data/test/unit/sequence_test.rb +0 -104
- data/test/unit/setup_and_teardown_test.rb +0 -76
- data/test/unit/single_return_value_test.rb +0 -33
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/stub_test.rb +0 -24
- data/test/unit/yield_parameters_test.rb +0 -93
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module ActiveRecordTestCase
|
|
2
|
-
|
|
3
|
-
def setup_with_fixtures
|
|
4
|
-
methods_called << :setup_with_fixtures
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
alias_method :setup, :setup_with_fixtures
|
|
8
|
-
|
|
9
|
-
def teardown_with_fixtures
|
|
10
|
-
methods_called << :teardown_with_fixtures
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
alias_method :teardown, :teardown_with_fixtures
|
|
14
|
-
|
|
15
|
-
def self.method_added(method)
|
|
16
|
-
case method.to_s
|
|
17
|
-
when 'setup'
|
|
18
|
-
unless method_defined?(:setup_without_fixtures)
|
|
19
|
-
alias_method :setup_without_fixtures, :setup
|
|
20
|
-
define_method(:setup) do
|
|
21
|
-
setup_with_fixtures
|
|
22
|
-
setup_without_fixtures
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
when 'teardown'
|
|
26
|
-
unless method_defined?(:teardown_without_fixtures)
|
|
27
|
-
alias_method :teardown_without_fixtures, :teardown
|
|
28
|
-
define_method(:teardown) do
|
|
29
|
-
teardown_without_fixtures
|
|
30
|
-
teardown_with_fixtures
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'mocha/deprecation'
|
|
2
|
-
|
|
3
|
-
module DeprecationDisabler
|
|
4
|
-
|
|
5
|
-
def disable_deprecations
|
|
6
|
-
original_mode = Mocha::Deprecation.mode
|
|
7
|
-
Mocha::Deprecation.mode = :disabled
|
|
8
|
-
begin
|
|
9
|
-
yield
|
|
10
|
-
ensure
|
|
11
|
-
Mocha::Deprecation.mode = original_mode
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
data/test/execution_point.rb
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
class ExecutionPoint
|
|
2
|
-
|
|
3
|
-
attr_reader :backtrace
|
|
4
|
-
|
|
5
|
-
def self.current
|
|
6
|
-
new(caller)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def initialize(backtrace)
|
|
10
|
-
@backtrace = backtrace
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def file_name
|
|
14
|
-
/\A(.*?):\d+/.match(@backtrace.first)[1]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def line_number
|
|
18
|
-
Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def ==(other)
|
|
22
|
-
return false unless other.is_a?(ExecutionPoint)
|
|
23
|
-
(file_name == other.file_name) and (line_number == other.line_number)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_s
|
|
27
|
-
"file: #{file_name} line: #{line_number}"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def inspect
|
|
31
|
-
to_s
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/standalone'
|
|
3
|
-
require 'mocha/test_case_adapter'
|
|
4
|
-
require 'execution_point'
|
|
5
|
-
|
|
6
|
-
class MochaTestResultIntegrationTest < Test::Unit::TestCase
|
|
7
|
-
|
|
8
|
-
def test_should_include_expectation_verification_in_assertion_count
|
|
9
|
-
test_result = run_test do
|
|
10
|
-
object = mock()
|
|
11
|
-
object.expects(:message)
|
|
12
|
-
object.message
|
|
13
|
-
end
|
|
14
|
-
assert_equal 1, test_result.assertion_count
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_should_include_assertions_in_assertion_count
|
|
18
|
-
test_result = run_test do
|
|
19
|
-
assert true
|
|
20
|
-
end
|
|
21
|
-
assert_equal 1, test_result.assertion_count
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
|
25
|
-
test_result = run_test do
|
|
26
|
-
object = mock()
|
|
27
|
-
object.stubs(:message)
|
|
28
|
-
object.message
|
|
29
|
-
end
|
|
30
|
-
assert_equal 0, test_result.assertion_count
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_should_include_expectation_verification_failure_in_failure_count
|
|
34
|
-
test_result = run_test do
|
|
35
|
-
object = mock()
|
|
36
|
-
object.expects(:message)
|
|
37
|
-
end
|
|
38
|
-
assert_equal 1, test_result.failure_count
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_should_include_unexpected_verification_failure_in_failure_count
|
|
42
|
-
test_result = run_test do
|
|
43
|
-
object = mock()
|
|
44
|
-
object.message
|
|
45
|
-
end
|
|
46
|
-
assert_equal 1, test_result.failure_count
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_include_assertion_failure_in_failure_count
|
|
50
|
-
test_result = run_test do
|
|
51
|
-
flunk
|
|
52
|
-
end
|
|
53
|
-
assert_equal 1, test_result.failure_count
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_should_display_backtrace_indicating_line_number_where_expects_was_called
|
|
57
|
-
test_result = Test::Unit::TestResult.new
|
|
58
|
-
faults = []
|
|
59
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
|
60
|
-
execution_point = nil
|
|
61
|
-
run_test(test_result) do
|
|
62
|
-
object = mock()
|
|
63
|
-
execution_point = ExecutionPoint.current; object.expects(:message)
|
|
64
|
-
end
|
|
65
|
-
assert_equal 1, faults.length
|
|
66
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
|
|
70
|
-
test_result = Test::Unit::TestResult.new
|
|
71
|
-
faults = []
|
|
72
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
|
73
|
-
execution_point = nil
|
|
74
|
-
run_test(test_result) do
|
|
75
|
-
object = mock()
|
|
76
|
-
execution_point = ExecutionPoint.current; object.message
|
|
77
|
-
end
|
|
78
|
-
assert_equal 1, faults.length
|
|
79
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
|
83
|
-
test_result = Test::Unit::TestResult.new
|
|
84
|
-
faults = []
|
|
85
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
|
86
|
-
execution_point = nil
|
|
87
|
-
run_test(test_result) do
|
|
88
|
-
execution_point = ExecutionPoint.current; flunk
|
|
89
|
-
end
|
|
90
|
-
assert_equal 1, faults.length
|
|
91
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
|
95
|
-
test_class = Class.new(Test::Unit::TestCase) do
|
|
96
|
-
include Mocha::Standalone
|
|
97
|
-
include Mocha::TestCaseAdapter
|
|
98
|
-
define_method(:test_me, &block)
|
|
99
|
-
end
|
|
100
|
-
test = test_class.new(:test_me)
|
|
101
|
-
test.run(test_result) {}
|
|
102
|
-
test_result
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
end
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
|
|
3
|
-
require 'mocha/object'
|
|
4
|
-
require 'mocha/test_case_adapter'
|
|
5
|
-
require 'mocha/standalone'
|
|
6
|
-
|
|
7
|
-
class StubbaIntegrationTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
class DontMessWithMe
|
|
10
|
-
def self.my_class_method
|
|
11
|
-
:original_return_value
|
|
12
|
-
end
|
|
13
|
-
def my_instance_method
|
|
14
|
-
:original_return_value
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_should_stub_class_method_within_test
|
|
19
|
-
test = build_test do
|
|
20
|
-
DontMessWithMe.expects(:my_class_method).returns(:new_return_value)
|
|
21
|
-
assert_equal :new_return_value, DontMessWithMe.my_class_method
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test_result = Test::Unit::TestResult.new
|
|
25
|
-
test.run(test_result) {}
|
|
26
|
-
assert test_result.passed?
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_should_leave_stubbed_class_method_unchanged_after_test
|
|
30
|
-
test = build_test do
|
|
31
|
-
DontMessWithMe.expects(:my_class_method).returns(:new_return_value)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
test.run(Test::Unit::TestResult.new) {}
|
|
35
|
-
assert_equal :original_return_value, DontMessWithMe.my_class_method
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_should_reset_class_expectations_after_test
|
|
39
|
-
test = build_test do
|
|
40
|
-
DontMessWithMe.expects(:my_class_method)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test.run(Test::Unit::TestResult.new) {}
|
|
44
|
-
assert_equal 0, DontMessWithMe.mocha.expectations.length
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_should_stub_instance_method_within_test
|
|
48
|
-
instance = DontMessWithMe.new
|
|
49
|
-
test = build_test do
|
|
50
|
-
instance.expects(:my_instance_method).returns(:new_return_value)
|
|
51
|
-
assert_equal :new_return_value, instance.my_instance_method
|
|
52
|
-
end
|
|
53
|
-
test_result = Test::Unit::TestResult.new
|
|
54
|
-
test.run(test_result) {}
|
|
55
|
-
assert test_result.passed?
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_should_leave_stubbed_instance_method_unchanged_after_test
|
|
59
|
-
instance = DontMessWithMe.new
|
|
60
|
-
test = build_test do
|
|
61
|
-
instance.expects(:my_instance_method).returns(:new_return_value)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
test.run(Test::Unit::TestResult.new) {}
|
|
65
|
-
assert_equal :original_return_value, instance.my_instance_method
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_should_reset_instance_expectations_after_test
|
|
69
|
-
instance = DontMessWithMe.new
|
|
70
|
-
test = build_test do
|
|
71
|
-
instance.expects(:my_instance_method).returns(:new_return_value)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
test.run(Test::Unit::TestResult.new) {}
|
|
75
|
-
assert_equal 0, instance.mocha.expectations.length
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private
|
|
79
|
-
|
|
80
|
-
def build_test(&block)
|
|
81
|
-
test_class = Class.new(Test::Unit::TestCase) do
|
|
82
|
-
include Mocha::Standalone
|
|
83
|
-
include Mocha::TestCaseAdapter
|
|
84
|
-
define_method(:test_me, &block)
|
|
85
|
-
end
|
|
86
|
-
test_class.new(:test_me)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/object'
|
|
3
|
-
require 'mocha/standalone'
|
|
4
|
-
require 'mocha/test_case_adapter'
|
|
5
|
-
require 'execution_point'
|
|
6
|
-
|
|
7
|
-
class StubbaTestResultIntegrationTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
def test_should_include_expectation_verification_in_assertion_count
|
|
10
|
-
test_result = run_test do
|
|
11
|
-
object = Class.new { def message; end }.new
|
|
12
|
-
object.expects(:message)
|
|
13
|
-
object.message
|
|
14
|
-
end
|
|
15
|
-
assert_equal 1, test_result.assertion_count
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_should_include_assertions_in_assertion_count
|
|
19
|
-
test_result = run_test do
|
|
20
|
-
assert true
|
|
21
|
-
end
|
|
22
|
-
assert_equal 1, test_result.assertion_count
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
|
26
|
-
test_result = run_test do
|
|
27
|
-
object = Class.new { def message; end }.new
|
|
28
|
-
object.stubs(:message)
|
|
29
|
-
object.message
|
|
30
|
-
end
|
|
31
|
-
assert_equal 0, test_result.assertion_count
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_should_include_expectation_verification_failure_in_failure_count
|
|
35
|
-
test_result = run_test do
|
|
36
|
-
object = Class.new { def message; end }.new
|
|
37
|
-
object.expects(:message)
|
|
38
|
-
end
|
|
39
|
-
assert_equal 1, test_result.failure_count
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_should_include_assertion_failure_in_failure_count
|
|
43
|
-
test_result = run_test do
|
|
44
|
-
flunk
|
|
45
|
-
end
|
|
46
|
-
assert_equal 1, test_result.failure_count
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_display_backtrace_indicating_line_number_where_expects_was_called
|
|
50
|
-
test_result = Test::Unit::TestResult.new
|
|
51
|
-
faults = []
|
|
52
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
|
53
|
-
execution_point = nil
|
|
54
|
-
run_test(test_result) do
|
|
55
|
-
object = Class.new { def message; end }.new
|
|
56
|
-
execution_point = ExecutionPoint.current; object.expects(:message)
|
|
57
|
-
end
|
|
58
|
-
assert_equal 1, faults.length
|
|
59
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
|
63
|
-
test_result = Test::Unit::TestResult.new
|
|
64
|
-
faults = []
|
|
65
|
-
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
|
66
|
-
execution_point = nil
|
|
67
|
-
run_test(test_result) do
|
|
68
|
-
execution_point = ExecutionPoint.current; flunk
|
|
69
|
-
end
|
|
70
|
-
assert_equal 1, faults.length
|
|
71
|
-
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
|
75
|
-
test_class = Class.new(Test::Unit::TestCase) do
|
|
76
|
-
include Mocha::Standalone
|
|
77
|
-
include Mocha::TestCaseAdapter
|
|
78
|
-
define_method(:test_me, &block)
|
|
79
|
-
end
|
|
80
|
-
test = test_class.new(:test_me)
|
|
81
|
-
test.run(test_result) {}
|
|
82
|
-
test_result
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
end
|
data/test/method_definer.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'mocha/metaclass'
|
|
2
|
-
|
|
3
|
-
class Object
|
|
4
|
-
|
|
5
|
-
def define_instance_method(method_symbol, &block)
|
|
6
|
-
__metaclass__.send(:define_method, method_symbol, block)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def replace_instance_method(method_symbol, &block)
|
|
10
|
-
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol)
|
|
11
|
-
define_instance_method(method_symbol, &block)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def define_instance_accessor(*symbols)
|
|
15
|
-
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS)
|
|
2
|
-
STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.public_instance_methods
|
|
3
|
-
end
|
|
4
|
-
|
|
5
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
6
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
|
7
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
|
8
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
|
9
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'integration'))
|
|
10
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
|
11
|
-
|
|
12
|
-
require 'test/unit'
|
data/test/test_runner.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'test/unit/testresult'
|
|
2
|
-
require 'test/unit/testcase'
|
|
3
|
-
require 'mocha/standalone'
|
|
4
|
-
require 'mocha/test_case_adapter'
|
|
5
|
-
|
|
6
|
-
module TestRunner
|
|
7
|
-
|
|
8
|
-
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
|
9
|
-
test_class = Class.new(Test::Unit::TestCase) do
|
|
10
|
-
include Mocha::Standalone
|
|
11
|
-
include Mocha::TestCaseAdapter
|
|
12
|
-
define_method(:test_me, &block)
|
|
13
|
-
end
|
|
14
|
-
test = test_class.new(:test_me)
|
|
15
|
-
test.run(test_result) {}
|
|
16
|
-
class << test_result
|
|
17
|
-
attr_reader :failures, :errors
|
|
18
|
-
end
|
|
19
|
-
test_result
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def assert_passed(test_result)
|
|
23
|
-
flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
|
|
24
|
-
flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def assert_failed(test_result)
|
|
28
|
-
flunk "Test passed unexpectedly" if test_result.passed?
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'method_definer'
|
|
3
|
-
require 'mocha/mock'
|
|
4
|
-
require 'mocha/any_instance_method'
|
|
5
|
-
|
|
6
|
-
class AnyInstanceMethodTest < Test::Unit::TestCase
|
|
7
|
-
|
|
8
|
-
include Mocha
|
|
9
|
-
|
|
10
|
-
def test_should_hide_original_method
|
|
11
|
-
klass = Class.new { def method_x; end }
|
|
12
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
13
|
-
hidden_method_x = method.hidden_method.to_sym
|
|
14
|
-
|
|
15
|
-
method.hide_original_method
|
|
16
|
-
|
|
17
|
-
assert klass.method_defined?(hidden_method_x)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_should_not_hide_original_method_if_it_is_not_defined
|
|
21
|
-
klass = Class.new
|
|
22
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
23
|
-
hidden_method_x = method.hidden_method.to_sym
|
|
24
|
-
|
|
25
|
-
method.hide_original_method
|
|
26
|
-
|
|
27
|
-
assert_equal false, klass.method_defined?(hidden_method_x)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_should_define_a_new_method
|
|
31
|
-
klass = Class.new { def method_x; end }
|
|
32
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
33
|
-
mocha = Mock.new
|
|
34
|
-
mocha.expects(:method_x).with(:param1, :param2).returns(:result)
|
|
35
|
-
any_instance = Object.new
|
|
36
|
-
any_instance.define_instance_method(:mocha) { mocha }
|
|
37
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
|
38
|
-
|
|
39
|
-
method.hide_original_method
|
|
40
|
-
method.define_new_method
|
|
41
|
-
|
|
42
|
-
instance = klass.new
|
|
43
|
-
result = instance.method_x(:param1, :param2)
|
|
44
|
-
|
|
45
|
-
assert_equal :result, result
|
|
46
|
-
mocha.verify
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_restore_original_method
|
|
50
|
-
klass = Class.new { def method_x; end }
|
|
51
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
52
|
-
hidden_method_x = method.hidden_method.to_sym
|
|
53
|
-
klass.send(:define_method, hidden_method_x, Proc.new { :original_result })
|
|
54
|
-
|
|
55
|
-
method.remove_new_method
|
|
56
|
-
method.restore_original_method
|
|
57
|
-
|
|
58
|
-
instance = klass.new
|
|
59
|
-
assert_equal :original_result, instance.method_x
|
|
60
|
-
assert !klass.method_defined?(hidden_method_x)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_should_not_restore_original_method_if_hidden_method_not_defined
|
|
64
|
-
klass = Class.new { def method_x; :new_result; end }
|
|
65
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
66
|
-
|
|
67
|
-
method.restore_original_method
|
|
68
|
-
|
|
69
|
-
instance = klass.new
|
|
70
|
-
assert_equal :new_result, instance.method_x
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_should_call_remove_new_method
|
|
74
|
-
klass = Class.new { def method_x; end }
|
|
75
|
-
any_instance = Mock.new
|
|
76
|
-
any_instance.stubs(:reset_mocha)
|
|
77
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
|
78
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
79
|
-
method.replace_instance_method(:restore_original_method) { }
|
|
80
|
-
method.define_instance_accessor(:remove_called)
|
|
81
|
-
method.replace_instance_method(:remove_new_method) { self.remove_called = true }
|
|
82
|
-
|
|
83
|
-
method.unstub
|
|
84
|
-
|
|
85
|
-
assert method.remove_called
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_should_call_restore_original_method
|
|
89
|
-
klass = Class.new { def method_x; end }
|
|
90
|
-
any_instance = Mock.new
|
|
91
|
-
any_instance.stubs(:reset_mocha)
|
|
92
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
|
93
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
94
|
-
method.replace_instance_method(:remove_new_method) { }
|
|
95
|
-
method.define_instance_accessor(:restore_called)
|
|
96
|
-
method.replace_instance_method(:restore_original_method) { self.restore_called = true }
|
|
97
|
-
|
|
98
|
-
method.unstub
|
|
99
|
-
|
|
100
|
-
assert method.restore_called
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_should_call_reset_mocha
|
|
104
|
-
klass = Class.new { def method_x; end }
|
|
105
|
-
any_instance = Class.new { attr_accessor :mocha_was_reset; def reset_mocha; self.mocha_was_reset = true; end }.new
|
|
106
|
-
klass.define_instance_method(:any_instance) { any_instance }
|
|
107
|
-
method = AnyInstanceMethod.new(klass, :method_x)
|
|
108
|
-
method.replace_instance_method(:remove_new_method) { }
|
|
109
|
-
method.replace_instance_method(:restore_original_method) { }
|
|
110
|
-
|
|
111
|
-
method.unstub
|
|
112
|
-
|
|
113
|
-
assert any_instance.mocha_was_reset
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def test_should_return_any_instance_mocha_for_stubbee
|
|
117
|
-
mocha = Object.new
|
|
118
|
-
any_instance = Object.new
|
|
119
|
-
any_instance.define_instance_method(:mocha) { mocha }
|
|
120
|
-
stubbee = Class.new
|
|
121
|
-
stubbee.define_instance_method(:any_instance) { any_instance }
|
|
122
|
-
method = AnyInstanceMethod.new(stubbee, :method_name)
|
|
123
|
-
assert_equal stubbee.any_instance.mocha, method.mock
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
|
-
require 'mocha/inspect'
|
|
3
|
-
|
|
4
|
-
class ArrayInstanceTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def test_should_use_inspect
|
|
7
|
-
array = [1, 2]
|
|
8
|
-
assert_equal array.inspect, array.mocha_inspect
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_should_use_mocha_inspect_on_each_item
|
|
12
|
-
array = [1, 2, "chris"]
|
|
13
|
-
assert_equal "[1, 2, 'chris']", array.mocha_inspect
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
end
|