mocha-macruby 0.9.8.20100129120100 → 0.9.9.20101102121900
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.rdoc +3 -0
- data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
- data/{README → README.rdoc} +7 -7
- data/{RELEASE → RELEASE.rdoc} +18 -0
- data/Rakefile +44 -28
- data/lib/mocha.rb +1 -0
- data/lib/mocha/class_method.rb +1 -3
- data/lib/mocha/expectation.rb +37 -34
- data/lib/mocha/integration/mini_test.rb +32 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
- data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_13.rb} +7 -13
- data/lib/mocha/integration/mini_test/version_140.rb +52 -0
- data/lib/mocha/integration/mini_test/version_141.rb +56 -0
- data/lib/mocha/integration/mini_test/version_142_and_above.rb +47 -0
- data/lib/mocha/integration/test_unit.rb +23 -8
- data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
- data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
- data/lib/mocha/integration/test_unit/gem_version_203_to_209.rb +52 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
- data/lib/mocha/mock.rb +33 -18
- data/lib/mocha/module_method.rb +1 -1
- data/lib/mocha/object.rb +144 -160
- data/lib/mocha/options.rb +1 -0
- data/lib/mocha/parameter_matchers/base.rb +50 -2
- data/test/acceptance/acceptance_test_helper.rb +1 -1
- data/test/acceptance/api_test.rb +1 -1
- 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/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/minitest_test.rb +128 -124
- 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/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +38 -1
- data/test/acceptance/partial_mocks_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 +5 -2
- data/test/acceptance/stub_class_method_test.rb +5 -2
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_test.rb +5 -2
- data/test/acceptance/stub_module_method_test.rb +3 -3
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_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_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/mini_test_result.rb +74 -0
- data/test/test_helper.rb +3 -1
- data/test/test_runner.rb +25 -11
- data/test/unit/any_instance_method_test.rb +1 -1
- data/test/unit/array_inspect_test.rb +1 -1
- data/test/unit/backtrace_filter_test.rb +1 -1
- data/test/unit/cardinality_test.rb +1 -1
- data/test/unit/central_test.rb +1 -1
- data/test/unit/change_state_side_effect_test.rb +1 -1
- data/test/unit/class_method_test.rb +2 -2
- data/test/unit/configuration_test.rb +1 -1
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/exception_raiser_test.rb +1 -1
- data/test/unit/expectation_list_test.rb +1 -1
- data/test/unit/expectation_test.rb +1 -1
- data/test/unit/hash_inspect_test.rb +1 -1
- data/test/unit/in_state_ordering_constraint_test.rb +1 -1
- data/test/unit/metaclass_test.rb +1 -1
- data/test/unit/method_matcher_test.rb +1 -1
- data/test/unit/mock_test.rb +16 -14
- data/test/unit/mockery_test.rb +1 -1
- data/test/unit/multiple_yields_test.rb +1 -1
- data/test/unit/no_yields_test.rb +1 -1
- data/test/unit/object_inspect_test.rb +10 -9
- data/test/unit/object_test.rb +11 -10
- data/test/unit/parameter_matchers/all_of_test.rb +1 -1
- data/test/unit/parameter_matchers/any_of_test.rb +1 -1
- data/test/unit/parameter_matchers/anything_test.rb +1 -1
- data/test/unit/parameter_matchers/equals_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +5 -5
- data/test/unit/parameter_matchers/instance_of_test.rb +2 -2
- data/test/unit/parameter_matchers/is_a_test.rb +1 -1
- data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
- data/test/unit/parameter_matchers/not_test.rb +1 -1
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
- data/test/unit/parameters_matcher_test.rb +1 -1
- data/test/unit/return_values_test.rb +1 -1
- data/test/unit/sequence_test.rb +1 -1
- data/test/unit/single_return_value_test.rb +1 -1
- data/test/unit/single_yield_test.rb +1 -1
- data/test/unit/state_machine_test.rb +1 -1
- data/test/unit/string_inspect_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +1 -1
- metadata +43 -19
- data/COPYING +0 -3
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'test/unit/testcase'
|
3
|
+
require 'minitest/unit'
|
4
|
+
|
5
|
+
class MiniTestResult
|
6
|
+
def self.parse_failure(raw)
|
7
|
+
matches = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m.match(raw)
|
8
|
+
return nil unless matches
|
9
|
+
Failure.new(matches[2], matches[3], [matches[4]], matches[5])
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_error(raw)
|
13
|
+
matches = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n.+ (.*)\n}m.match(raw)
|
14
|
+
return nil unless matches
|
15
|
+
Error.new(matches[2], matches[3], matches[4], [matches[5]])
|
16
|
+
end
|
17
|
+
|
18
|
+
class Failure
|
19
|
+
attr_reader :method, :test_case, :location, :message
|
20
|
+
def initialize(method, test_case, location, message)
|
21
|
+
@method, @test_case, @location, @message = method, test_case, location, message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Error
|
26
|
+
class Exception
|
27
|
+
attr_reader :message, :backtrace
|
28
|
+
def initialize(message, location)
|
29
|
+
@message, @backtrace = message, location
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :method, :test_case, :exception
|
34
|
+
def initialize(method, test_case, message, backtrace)
|
35
|
+
@method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(runner, test)
|
40
|
+
@runner, @test = runner, test
|
41
|
+
end
|
42
|
+
|
43
|
+
def failure_count
|
44
|
+
@runner.failures
|
45
|
+
end
|
46
|
+
|
47
|
+
def assertion_count
|
48
|
+
@test._assertions
|
49
|
+
end
|
50
|
+
|
51
|
+
def error_count
|
52
|
+
@runner.errors
|
53
|
+
end
|
54
|
+
|
55
|
+
def passed?
|
56
|
+
@test.passed?
|
57
|
+
end
|
58
|
+
|
59
|
+
def failures
|
60
|
+
@runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
|
61
|
+
end
|
62
|
+
|
63
|
+
def errors
|
64
|
+
@runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
|
65
|
+
end
|
66
|
+
|
67
|
+
def failure_messages
|
68
|
+
failures.map(&:message)
|
69
|
+
end
|
70
|
+
|
71
|
+
def error_messages
|
72
|
+
errors.map { |e| e.exception.message }
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,7 +8,9 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
|
8
8
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
9
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
10
10
|
|
11
|
-
|
11
|
+
require 'mocha/options'
|
12
|
+
if $options['use_test_unit_gem']
|
13
|
+
require 'rubygems'
|
12
14
|
gem 'test-unit'
|
13
15
|
end
|
14
16
|
|
data/test/test_runner.rb
CHANGED
@@ -1,23 +1,37 @@
|
|
1
|
-
require 'test/unit/testresult'
|
2
1
|
require 'test/unit/testcase'
|
3
2
|
|
3
|
+
if defined?(MiniTest)
|
4
|
+
require 'mocha/integration/mini_test'
|
5
|
+
require File.expand_path('../mini_test_result', __FILE__)
|
6
|
+
else
|
7
|
+
require 'test/unit/testresult'
|
8
|
+
end
|
9
|
+
|
4
10
|
module TestRunner
|
5
|
-
|
6
|
-
def run_as_test(test_result = Test::Unit::TestResult.new, &block)
|
11
|
+
def run_as_test(test_result = nil, &block)
|
7
12
|
test_class = Class.new(Test::Unit::TestCase) do
|
8
13
|
define_method(:test_me, &block)
|
9
14
|
end
|
10
15
|
test = test_class.new(:test_me)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
if defined?(Test::Unit::TestResult)
|
18
|
+
test_result ||= Test::Unit::TestResult.new
|
19
|
+
test.run(test_result) {}
|
20
|
+
class << test_result
|
21
|
+
attr_reader :failures, :errors
|
22
|
+
def failure_messages
|
23
|
+
failures.map { |failure| failure.message }
|
24
|
+
end
|
25
|
+
def error_messages
|
26
|
+
errors.map { |error| error.message }
|
27
|
+
end
|
19
28
|
end
|
29
|
+
else
|
30
|
+
runner = MiniTest::Unit.new
|
31
|
+
test.run(runner)
|
32
|
+
test_result = MiniTestResult.new(runner, test)
|
20
33
|
end
|
34
|
+
|
21
35
|
test_result
|
22
36
|
end
|
23
37
|
|
data/test/unit/central_test.rb
CHANGED
data/test/unit/metaclass_test.rb
CHANGED
data/test/unit/mock_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.
|
2
|
-
require 'mocha/mock'
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require 'mocha/mockery' # requires 'mock'
|
3
3
|
require 'mocha/expectation_error'
|
4
4
|
require 'set'
|
5
5
|
require 'simple_counter'
|
@@ -50,18 +50,20 @@ class MockTest < Test::Unit::TestCase
|
|
50
50
|
OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || m == :object_id }
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
# MacRuby bug: https://www.macruby.org/trac/ticket/716
|
54
|
+
# def test_should_be_able_to_mock_standard_object_methods
|
55
|
+
# mock = Mock.new
|
56
|
+
# OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) }
|
57
|
+
# OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
|
58
|
+
# assert mock.__verified__?
|
59
|
+
# end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
# MacRuby bug: https://www.macruby.org/trac/ticket/716
|
62
|
+
# def test_should_be_able_to_stub_standard_object_methods
|
63
|
+
# mock = Mock.new
|
64
|
+
# OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) }
|
65
|
+
# OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) }
|
66
|
+
# end
|
65
67
|
|
66
68
|
def test_should_create_and_add_expectations
|
67
69
|
mock = Mock.new
|
@@ -299,4 +301,4 @@ class MockTest < Test::Unit::TestCase
|
|
299
301
|
assert mock.respond_to?(:xyz)
|
300
302
|
end
|
301
303
|
|
302
|
-
end
|
304
|
+
end
|
data/test/unit/mockery_test.rb
CHANGED
data/test/unit/no_yields_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/inspect'
|
3
3
|
require 'method_definer'
|
4
4
|
|
@@ -10,7 +10,7 @@ class ObjectInspectTest < Test::Unit::TestCase
|
|
10
10
|
attr_accessor :attribute
|
11
11
|
end
|
12
12
|
object.attribute = 'instance_variable'
|
13
|
-
assert_match Regexp.new("
|
13
|
+
assert_match Regexp.new("^#<#{object.class}:0x[0-9A-Fa-f]{1,8}.*>$"), object.mocha_inspect
|
14
14
|
assert_no_match(/instance_variable/, object.mocha_inspect)
|
15
15
|
end
|
16
16
|
|
@@ -23,15 +23,16 @@ class ObjectInspectTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
|
26
|
+
calls = []
|
26
27
|
object = Object.new
|
27
|
-
object.
|
28
|
-
object.
|
29
|
-
object.replace_instance_method(:
|
30
|
-
|
31
|
-
|
32
|
-
end
|
28
|
+
object.replace_instance_method(:id) { calls << :id; return 1 } if RUBY_VERSION < '1.9'
|
29
|
+
object.replace_instance_method(:object_id) { calls << :object_id; return 1 }
|
30
|
+
object.replace_instance_method(:__id__) { calls << :__id__; return 1 }
|
31
|
+
object.replace_instance_method(:inspect) { "object-description" }
|
32
|
+
|
33
33
|
object.mocha_inspect
|
34
|
-
|
34
|
+
|
35
|
+
assert_equal [:__id__], calls.uniq
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
data/test/unit/object_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/object'
|
3
3
|
require 'mocha/mockery'
|
4
4
|
require 'mocha/mock'
|
@@ -7,7 +7,7 @@ require 'method_definer'
|
|
7
7
|
class ObjectTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
include Mocha
|
10
|
-
|
10
|
+
|
11
11
|
def test_should_build_mocha_referring_to_self
|
12
12
|
instance = Object.new
|
13
13
|
mocha = instance.mocha
|
@@ -45,11 +45,12 @@ class ObjectTest < Test::Unit::TestCase
|
|
45
45
|
def test_should_use_stubba_instance_method_for_object
|
46
46
|
assert_equal Mocha::InstanceMethod, Object.new.stubba_method
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
|
49
|
+
# MacRuby bug https://www.macruby.org/trac/ticket/718
|
50
|
+
# def test_should_use_stubba_module_method_for_module
|
51
|
+
# assert_equal Mocha::ModuleMethod, Module.new.stubba_method
|
52
|
+
# end
|
53
|
+
|
53
54
|
def test_should_use_stubba_class_method_for_class
|
54
55
|
assert_equal Mocha::ClassMethod, Class.new.stubba_method
|
55
56
|
end
|
@@ -62,17 +63,17 @@ class ObjectTest < Test::Unit::TestCase
|
|
62
63
|
object = Object.new
|
63
64
|
assert_equal object, object.stubba_object
|
64
65
|
end
|
65
|
-
|
66
|
+
|
66
67
|
def test_should_stub_self_for_module
|
67
68
|
mod = Module.new
|
68
69
|
assert_equal mod, mod.stubba_object
|
69
70
|
end
|
70
|
-
|
71
|
+
|
71
72
|
def test_should_stub_self_for_class
|
72
73
|
klass = Class.new
|
73
74
|
assert_equal klass, klass.stubba_object
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
def test_should_stub_relevant_class_for_any_instance
|
77
78
|
klass = Class.new
|
78
79
|
any_instance = Class::AnyInstance.new(klass)
|