mocha 0.12.8 → 0.13.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.
- data/.yardopts +22 -0
- data/COPYING.md +3 -0
- data/README.md +230 -0
- data/{RELEASE.rdoc → RELEASE.md} +61 -50
- data/Rakefile +45 -37
- data/build-matrix.rb +16 -4
- data/lib/mocha/api.rb +13 -16
- data/lib/mocha/class_method.rb +7 -3
- data/lib/mocha/class_methods.rb +63 -0
- data/lib/mocha/debug.rb +11 -0
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation_error.rb +5 -0
- data/lib/mocha/expectation_error_factory.rb +19 -0
- data/lib/mocha/hooks.rb +43 -0
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test/adapter.rb +54 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +0 -6
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +32 -25
- data/lib/mocha/integration/mini_test/version_140.rb +32 -26
- data/lib/mocha/integration/mini_test/version_141.rb +40 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +40 -34
- data/lib/mocha/integration/mini_test/version_200.rb +41 -35
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +41 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +49 -43
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +53 -47
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +43 -37
- data/lib/mocha/integration/mini_test.rb +42 -57
- data/lib/mocha/integration/monkey_patcher.rb +18 -0
- data/lib/mocha/integration/test_unit/adapter.rb +51 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +65 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +36 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +37 -30
- data/lib/mocha/integration/test_unit.rb +38 -45
- data/lib/mocha/integration.rb +6 -38
- data/lib/mocha/method_matcher.rb +1 -1
- data/lib/mocha/module_methods.rb +14 -0
- data/lib/mocha/{object.rb → object_methods.rb} +0 -83
- data/lib/mocha/setup.rb +10 -0
- data/lib/mocha/standalone.rb +3 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha.rb +6 -2
- data/lib/mocha_standalone.rb +3 -1
- data/mocha.gemspec +16 -9
- data/test/acceptance/bug_18914_test.rb +1 -1
- data/test/acceptance/bug_21465_test.rb +1 -1
- data/test/acceptance/bug_21563_test.rb +1 -1
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expectations_on_multiple_methods_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/issue_65_test.rb +1 -1
- data/test/acceptance/issue_70_test.rb +1 -1
- data/test/acceptance/mocha_example_test.rb +1 -1
- data/test/acceptance/mocha_test_result_test.rb +1 -1
- data/test/acceptance/mock_test.rb +1 -1
- data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
- data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +1 -1
- data/test/acceptance/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +1 -1
- data/test/acceptance/partial_mocks_test.rb +1 -1
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +1 -1
- data/test/acceptance/sequence_test.rb +1 -1
- data/test/acceptance/states_test.rb +1 -1
- data/test/acceptance/stub_any_instance_method_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +1 -1
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_test_result_test.rb +1 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
- data/test/acceptance/stubbing_frozen_object_test.rb +1 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +1 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_nil_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +1 -1
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -3
- data/test/acceptance/throw_test.rb +1 -1
- data/test/acceptance/unstubbing_test.rb +1 -1
- data/test/integration/mini_test_test.rb +9 -0
- data/test/integration/shared_tests.rb +174 -0
- data/test/integration/test_unit_test.rb +9 -0
- data/test/mini_test_result.rb +0 -1
- data/test/test_runner.rb +14 -14
- data/test/unit/class_methods_test.rb +40 -0
- data/test/unit/method_matcher_test.rb +5 -0
- data/test/unit/mock_test.rb +6 -0
- data/test/unit/module_methods_test.rb +19 -0
- data/test/unit/object_methods_test.rb +45 -0
- metadata +44 -72
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -56
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.3.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.4.2.0 +0 -7
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_330_to_410.rb +0 -65
- data/lib/mocha/integration/mini_test/version_420_to_433.rb +0 -70
- data/lib/mocha/integration/mini_test/version_440.rb +0 -70
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_253.rb +0 -58
- data/lib/mocha/options.rb +0 -1
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/unit/object_test.rb +0 -92
- /data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +0 -0
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'mocha/integration/mini_test/assertion_counter'
|
|
2
|
-
require 'mocha/expectation_error'
|
|
3
|
-
|
|
4
|
-
module Mocha
|
|
5
|
-
|
|
6
|
-
module Integration
|
|
7
|
-
|
|
8
|
-
module MiniTest
|
|
9
|
-
|
|
10
|
-
module Version420To433
|
|
11
|
-
def self.included(mod)
|
|
12
|
-
$stderr.puts "Monkey patching MiniTest >= v4.2.0 <= v4.3.3" if $mocha_options['debug']
|
|
13
|
-
end
|
|
14
|
-
def run runner
|
|
15
|
-
trap "INFO" do
|
|
16
|
-
runner.report.each_with_index do |msg, i|
|
|
17
|
-
warn "\n%3d) %s" % [i + 1, msg]
|
|
18
|
-
end
|
|
19
|
-
warn ''
|
|
20
|
-
time = runner.start_time ? Time.now - runner.start_time : 0
|
|
21
|
-
warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
|
|
22
|
-
runner.status $stderr
|
|
23
|
-
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
|
24
|
-
start_time = Time.now
|
|
25
|
-
assertion_counter = AssertionCounter.new(self)
|
|
26
|
-
result = ""
|
|
27
|
-
begin
|
|
28
|
-
begin
|
|
29
|
-
@passed = nil
|
|
30
|
-
self.before_setup
|
|
31
|
-
self.setup
|
|
32
|
-
self.after_setup
|
|
33
|
-
self.run_test self.__name__
|
|
34
|
-
mocha_verify(assertion_counter)
|
|
35
|
-
result = "." unless io?
|
|
36
|
-
time = Time.now - start_time
|
|
37
|
-
runner.record self.class, self.__name__, self._assertions, time, nil
|
|
38
|
-
@passed = true
|
|
39
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
|
40
|
-
raise
|
|
41
|
-
rescue Exception => e
|
|
42
|
-
@passed = false
|
|
43
|
-
time = Time.now - start_time
|
|
44
|
-
runner.record self.class, self.__name__, self._assertions, time, e
|
|
45
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
|
46
|
-
ensure
|
|
47
|
-
%w{ before_teardown teardown after_teardown }.each do |hook|
|
|
48
|
-
begin
|
|
49
|
-
self.send hook
|
|
50
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
|
51
|
-
raise
|
|
52
|
-
rescue Exception => e
|
|
53
|
-
@passed = false
|
|
54
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
|
58
|
-
end
|
|
59
|
-
ensure
|
|
60
|
-
mocha_teardown
|
|
61
|
-
end
|
|
62
|
-
result
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'mocha/integration/mini_test/assertion_counter'
|
|
2
|
-
require 'mocha/expectation_error'
|
|
3
|
-
|
|
4
|
-
module Mocha
|
|
5
|
-
|
|
6
|
-
module Integration
|
|
7
|
-
|
|
8
|
-
module MiniTest
|
|
9
|
-
|
|
10
|
-
module Version440
|
|
11
|
-
def self.included(mod)
|
|
12
|
-
$stderr.puts "Monkey patching MiniTest >= v4.4.0 <= v4.4.0" if $mocha_options['debug']
|
|
13
|
-
end
|
|
14
|
-
def run runner
|
|
15
|
-
trap "INFO" do
|
|
16
|
-
runner.report.each_with_index do |msg, i|
|
|
17
|
-
warn "\n%3d) %s" % [i + 1, msg]
|
|
18
|
-
end
|
|
19
|
-
warn ''
|
|
20
|
-
time = runner.start_time ? Time.now - runner.start_time : 0
|
|
21
|
-
warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
|
|
22
|
-
runner.status $stderr
|
|
23
|
-
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
|
24
|
-
start_time = Time.now
|
|
25
|
-
assertion_counter = AssertionCounter.new(self)
|
|
26
|
-
result = ""
|
|
27
|
-
begin
|
|
28
|
-
begin
|
|
29
|
-
@passed = nil
|
|
30
|
-
self.before_setup
|
|
31
|
-
self.setup
|
|
32
|
-
self.after_setup
|
|
33
|
-
self.run_test self.__name__
|
|
34
|
-
mocha_verify(assertion_counter)
|
|
35
|
-
result = "." unless io?
|
|
36
|
-
time = Time.now - start_time
|
|
37
|
-
runner.record self.class, self.__name__, self._assertions, time, nil
|
|
38
|
-
@passed = true
|
|
39
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
|
40
|
-
raise
|
|
41
|
-
rescue Exception => e
|
|
42
|
-
@passed = ::MiniTest::Skip === e
|
|
43
|
-
time = Time.now - start_time
|
|
44
|
-
runner.record self.class, self.__name__, self._assertions, time, e
|
|
45
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
|
46
|
-
ensure
|
|
47
|
-
%w{ before_teardown teardown after_teardown }.each do |hook|
|
|
48
|
-
begin
|
|
49
|
-
self.send hook
|
|
50
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
|
51
|
-
raise
|
|
52
|
-
rescue Exception => e
|
|
53
|
-
@passed = false
|
|
54
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
|
58
|
-
end
|
|
59
|
-
ensure
|
|
60
|
-
mocha_teardown
|
|
61
|
-
end
|
|
62
|
-
result
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module Mocha
|
|
2
|
-
|
|
3
|
-
module Integration
|
|
4
|
-
|
|
5
|
-
module TestUnit
|
|
6
|
-
|
|
7
|
-
class AssertionCounter
|
|
8
|
-
|
|
9
|
-
def initialize(test_result)
|
|
10
|
-
@test_result = test_result
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def increment
|
|
14
|
-
@test_result.add_assertion
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'test/unit/testcase'
|
|
2
|
-
require 'mocha/integration/test_unit/assertion_counter'
|
|
3
|
-
require 'mocha/expectation_error'
|
|
4
|
-
|
|
5
|
-
module Mocha
|
|
6
|
-
|
|
7
|
-
module Integration
|
|
8
|
-
|
|
9
|
-
module TestUnit
|
|
10
|
-
|
|
11
|
-
module GemVersion230To253
|
|
12
|
-
def self.included(mod)
|
|
13
|
-
$stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.5.3" if $mocha_options['debug']
|
|
14
|
-
end
|
|
15
|
-
def run(result)
|
|
16
|
-
assertion_counter = AssertionCounter.new(result)
|
|
17
|
-
begin
|
|
18
|
-
@internal_data.test_started
|
|
19
|
-
@_result = result
|
|
20
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
|
21
|
-
yield(Test::Unit::TestCase::STARTED_OBJECT, self)
|
|
22
|
-
begin
|
|
23
|
-
begin
|
|
24
|
-
run_setup
|
|
25
|
-
run_test
|
|
26
|
-
run_cleanup
|
|
27
|
-
mocha_verify(assertion_counter)
|
|
28
|
-
add_pass
|
|
29
|
-
rescue Mocha::ExpectationError => e
|
|
30
|
-
add_failure(e.message, e.backtrace)
|
|
31
|
-
rescue Exception
|
|
32
|
-
@internal_data.interrupted
|
|
33
|
-
raise unless handle_exception($!)
|
|
34
|
-
ensure
|
|
35
|
-
begin
|
|
36
|
-
run_teardown
|
|
37
|
-
rescue Exception
|
|
38
|
-
raise unless handle_exception($!)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
ensure
|
|
42
|
-
mocha_teardown
|
|
43
|
-
end
|
|
44
|
-
@internal_data.test_finished
|
|
45
|
-
result.add_run
|
|
46
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
|
47
|
-
yield(Test::Unit::TestCase::FINISHED_OBJECT, self)
|
|
48
|
-
ensure
|
|
49
|
-
# @_result = nil # For test-spec's after_all :<
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
data/lib/mocha/options.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$mocha_options = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) { |hash, key| hash[key] = true; hash }
|
data/test/acceptance/api_test.rb
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
|
-
require 'mocha_standalone'
|
|
3
|
-
require 'simple_counter'
|
|
4
|
-
|
|
5
|
-
class NotATestUnitAssertionFailedError < StandardError
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
class NotATestUnitTestCase
|
|
9
|
-
|
|
10
|
-
include Mocha::API
|
|
11
|
-
|
|
12
|
-
attr_reader :assertion_counter
|
|
13
|
-
|
|
14
|
-
def initialize
|
|
15
|
-
@assertion_counter = SimpleCounter.new
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def run(test_method)
|
|
19
|
-
mocha_setup
|
|
20
|
-
begin
|
|
21
|
-
prepare
|
|
22
|
-
begin
|
|
23
|
-
send(test_method)
|
|
24
|
-
mocha_verify(@assertion_counter)
|
|
25
|
-
rescue Mocha::ExpectationError => e
|
|
26
|
-
new_error = NotATestUnitAssertionFailedError.new(e.message)
|
|
27
|
-
new_error.set_backtrace(e.backtrace)
|
|
28
|
-
raise new_error
|
|
29
|
-
ensure
|
|
30
|
-
cleanup
|
|
31
|
-
end
|
|
32
|
-
ensure
|
|
33
|
-
mocha_teardown
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def prepare
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def cleanup
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
class SampleTest < NotATestUnitTestCase
|
|
46
|
-
|
|
47
|
-
def mock_object_with_fulfilled_expectation
|
|
48
|
-
mockee = mock()
|
|
49
|
-
mockee.expects(:blah)
|
|
50
|
-
mockee.blah
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def mock_object_with_unfulfilled_expectation
|
|
54
|
-
mockee = mock()
|
|
55
|
-
mockee.expects(:blah)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def mock_object_with_unexpected_invocation
|
|
59
|
-
mockee = mock()
|
|
60
|
-
mockee.blah
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def real_object_with_fulfilled_expectation
|
|
64
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
65
|
-
stubbee.expects(:blah)
|
|
66
|
-
stubbee.blah
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def real_object_with_unfulfilled_expectation
|
|
70
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
71
|
-
stubbee.expects(:blah)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def mock_object_with_matching_parameter
|
|
75
|
-
mockee = mock()
|
|
76
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
77
|
-
mockee.blah(:wibble => 1)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def mock_object_with_non_matching_parameter
|
|
81
|
-
mockee = mock()
|
|
82
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
83
|
-
mockee.blah(:wobble => 2)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
require 'test/unit'
|
|
89
|
-
|
|
90
|
-
class APITest < Test::Unit::TestCase
|
|
91
|
-
|
|
92
|
-
attr_reader :sample_test
|
|
93
|
-
|
|
94
|
-
include AcceptanceTest
|
|
95
|
-
|
|
96
|
-
def setup
|
|
97
|
-
@sample_test = SampleTest.new
|
|
98
|
-
setup_acceptance_test
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def teardown
|
|
102
|
-
teardown_acceptance_test
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_should_pass_mock_object_test
|
|
106
|
-
assert_nothing_raised { sample_test.run(:mock_object_with_fulfilled_expectation) }
|
|
107
|
-
assert_equal 1, sample_test.assertion_counter.count
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_should_fail_mock_object_test_due_to_unfulfilled_exception
|
|
111
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_unfulfilled_expectation) }
|
|
112
|
-
assert_equal 1, sample_test.assertion_counter.count
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_should_fail_mock_object_test_due_to_unexpected_invocation
|
|
116
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_unexpected_invocation) }
|
|
117
|
-
assert_equal 0, sample_test.assertion_counter.count
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_should_pass_real_object_test
|
|
121
|
-
assert_nothing_raised { sample_test.run(:real_object_with_fulfilled_expectation) }
|
|
122
|
-
assert_equal 1, sample_test.assertion_counter.count
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_should_fail_real_object_test
|
|
126
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:real_object_with_unfulfilled_expectation) }
|
|
127
|
-
assert_equal 1, sample_test.assertion_counter.count
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def test_should_pass_mock_object_test_with_matching_parameter
|
|
131
|
-
assert_nothing_raised { sample_test.run(:mock_object_with_matching_parameter) }
|
|
132
|
-
assert_equal 1, sample_test.assertion_counter.count
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def test_should_fail_mock_object_test_with_non_matching_parameter
|
|
136
|
-
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mock_object_with_non_matching_parameter) }
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
end
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
if defined?(MiniTest)
|
|
4
|
-
$stderr.puts "TODO: Running suite with MiniTest, running the MiniTestAdapterTest results in an error so skipping it for now."
|
|
5
|
-
else
|
|
6
|
-
begin
|
|
7
|
-
require 'rubygems'
|
|
8
|
-
gem 'minitest'
|
|
9
|
-
rescue Gem::LoadError
|
|
10
|
-
# MiniTest gem not available
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
begin
|
|
14
|
-
require 'minitest/unit'
|
|
15
|
-
rescue LoadError
|
|
16
|
-
# MiniTest not available
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
if defined?(MiniTest)
|
|
20
|
-
|
|
21
|
-
# monkey-patch MiniTest now that it has hopefully been loaded
|
|
22
|
-
require 'mocha/integration/mini_test'
|
|
23
|
-
|
|
24
|
-
class MiniTestSampleTest < MiniTest::Unit::TestCase
|
|
25
|
-
|
|
26
|
-
def test_mocha_with_fulfilled_expectation
|
|
27
|
-
mockee = mock()
|
|
28
|
-
mockee.expects(:blah)
|
|
29
|
-
mockee.blah
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_mocha_with_unfulfilled_expectation
|
|
33
|
-
mockee = mock()
|
|
34
|
-
mockee.expects(:blah)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_mocha_with_unexpected_invocation
|
|
38
|
-
mockee = mock()
|
|
39
|
-
mockee.blah
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_stubba_with_fulfilled_expectation
|
|
43
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
44
|
-
stubbee.expects(:blah)
|
|
45
|
-
stubbee.blah
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_stubba_with_unfulfilled_expectation
|
|
49
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
|
50
|
-
stubbee.expects(:blah)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_mocha_with_matching_parameter
|
|
54
|
-
mockee = mock()
|
|
55
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
56
|
-
mockee.blah(:wibble => 1)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_mocha_with_non_matching_parameter
|
|
60
|
-
mockee = mock()
|
|
61
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
|
62
|
-
mockee.blah(:wobble => 2)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
class MiniTestTest < Test::Unit::TestCase
|
|
68
|
-
|
|
69
|
-
def setup
|
|
70
|
-
@output = StringIO.new
|
|
71
|
-
MiniTest::Unit.output = @output
|
|
72
|
-
@runner = MiniTest::Unit.new
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
attr_reader :runner
|
|
76
|
-
|
|
77
|
-
def test_should_pass_mocha_test
|
|
78
|
-
run_test_method :test_mocha_with_fulfilled_expectation
|
|
79
|
-
|
|
80
|
-
assert_equal 0, runner.failures
|
|
81
|
-
assert_equal 0, runner.errors
|
|
82
|
-
assert_equal 1, runner.assertion_count
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
|
86
|
-
run_test_method :test_mocha_with_unfulfilled_expectation
|
|
87
|
-
|
|
88
|
-
assert_equal 1, runner.failures
|
|
89
|
-
assert_equal 0, runner.errors
|
|
90
|
-
assert_equal 1, runner.assertion_count
|
|
91
|
-
assert_not_all_expectation_were_satisfied
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
|
95
|
-
run_test_method :test_mocha_with_unexpected_invocation
|
|
96
|
-
|
|
97
|
-
assert_equal 1, runner.failures
|
|
98
|
-
assert_equal 0, runner.errors
|
|
99
|
-
assert_equal 0, runner.assertion_count
|
|
100
|
-
assert_unexpected_invocation
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_should_pass_stubba_test
|
|
104
|
-
run_test_method :test_stubba_with_fulfilled_expectation
|
|
105
|
-
|
|
106
|
-
assert_equal 0, runner.failures
|
|
107
|
-
assert_equal 0, runner.errors
|
|
108
|
-
assert_equal 1, runner.assertion_count
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
|
112
|
-
run_test_method :test_stubba_with_unfulfilled_expectation
|
|
113
|
-
|
|
114
|
-
assert_equal 1, runner.failures
|
|
115
|
-
assert_equal 0, runner.errors
|
|
116
|
-
assert_equal 1, runner.assertion_count
|
|
117
|
-
assert_not_all_expectation_were_satisfied
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_should_pass_mocha_test_with_matching_parameter
|
|
121
|
-
run_test_method :test_mocha_with_matching_parameter
|
|
122
|
-
|
|
123
|
-
assert_equal 0, runner.failures
|
|
124
|
-
assert_equal 0, runner.errors
|
|
125
|
-
assert_equal 1, runner.assertion_count
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def test_should_fail_mocha_test_with_non_matching_parameter
|
|
129
|
-
run_test_method :test_mocha_with_non_matching_parameter
|
|
130
|
-
|
|
131
|
-
assert_equal 1, runner.failures
|
|
132
|
-
assert_equal 0, runner.errors
|
|
133
|
-
assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified
|
|
134
|
-
assert_unexpected_invocation
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
private
|
|
138
|
-
|
|
139
|
-
def run_test_method(method_name)
|
|
140
|
-
run_method = (MiniTest::Unit::VERSION >= "2.1.0") ? :_run : :run
|
|
141
|
-
runner.send(run_method, ["-n", method_name.to_s])
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def output
|
|
145
|
-
@output.rewind
|
|
146
|
-
@output.read
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def assert_unexpected_invocation
|
|
150
|
-
assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def assert_not_all_expectation_were_satisfied
|
|
154
|
-
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
else
|
|
160
|
-
$stderr.puts "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
|
161
|
-
end
|
|
162
|
-
end
|
data/test/unit/object_test.rb
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
|
2
|
-
require 'mocha/object'
|
|
3
|
-
require 'mocha/mockery'
|
|
4
|
-
require 'mocha/mock'
|
|
5
|
-
require 'method_definer'
|
|
6
|
-
|
|
7
|
-
class ObjectTest < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
include Mocha
|
|
10
|
-
|
|
11
|
-
def test_should_build_mocha_referring_to_self
|
|
12
|
-
instance = Object.new
|
|
13
|
-
mocha = instance.mocha
|
|
14
|
-
assert_not_nil mocha
|
|
15
|
-
assert mocha.is_a?(Mock)
|
|
16
|
-
assert_equal instance.mocha_inspect, mocha.mocha_inspect
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_should_reuse_existing_mocha
|
|
20
|
-
instance = Object.new
|
|
21
|
-
mocha_1 = instance.mocha
|
|
22
|
-
mocha_2 = instance.mocha
|
|
23
|
-
assert_equal mocha_1, mocha_2
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_should_reset_mocha
|
|
27
|
-
instance = Object.new
|
|
28
|
-
assert_nil instance.reset_mocha
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_should_build_any_instance_object
|
|
32
|
-
klass = Class.new
|
|
33
|
-
any_instance = klass.any_instance
|
|
34
|
-
assert_not_nil any_instance
|
|
35
|
-
assert any_instance.is_a?(Class::AnyInstance)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_should_return_same_any_instance_object
|
|
39
|
-
klass = Class.new
|
|
40
|
-
any_instance_1 = klass.any_instance
|
|
41
|
-
any_instance_2 = klass.any_instance
|
|
42
|
-
assert_equal any_instance_1, any_instance_2
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_should_use_stubba_instance_method_for_object
|
|
46
|
-
assert_equal Mocha::InstanceMethod, Object.new.stubba_method
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_use_stubba_module_method_for_module
|
|
50
|
-
assert_equal Mocha::ModuleMethod, Module.new.stubba_method
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_should_use_stubba_class_method_for_class
|
|
54
|
-
assert_equal Mocha::ClassMethod, Class.new.stubba_method
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_should_use_stubba_class_method_for_any_instance
|
|
58
|
-
assert_equal Mocha::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_should_stub_self_for_object
|
|
62
|
-
object = Object.new
|
|
63
|
-
assert_equal object, object.stubba_object
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_should_stub_self_for_module
|
|
67
|
-
mod = Module.new
|
|
68
|
-
assert_equal mod, mod.stubba_object
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_should_stub_self_for_class
|
|
72
|
-
klass = Class.new
|
|
73
|
-
assert_equal klass, klass.stubba_object
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_should_stub_relevant_class_for_any_instance
|
|
77
|
-
klass = Class.new
|
|
78
|
-
any_instance = Class::AnyInstance.new(klass)
|
|
79
|
-
assert_equal klass, any_instance.stubba_object
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_nobody_expects_the_spanish_inquisition
|
|
83
|
-
object = Object.new
|
|
84
|
-
assert_raise(Mocha::ExpectationError) { object.expects(:the_spanish_inquisition) }
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_should_alias_object_method
|
|
88
|
-
klass = Class.new { def self.method_x; end }
|
|
89
|
-
assert_equal klass._method(:method_x), klass.method(:method_x)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
end
|
|
File without changes
|