mocha 0.10.5 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +24 -0
- data/CONTRIBUTING.md +7 -0
- data/COPYING.md +3 -0
- data/Gemfile +2 -2
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +1 -1
- data/README.md +363 -0
- data/{RELEASE.rdoc → RELEASE.md} +436 -35
- data/Rakefile +87 -87
- data/gemfiles/Gemfile.minitest.latest +2 -2
- data/gemfiles/Gemfile.test-unit.latest +6 -2
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +12 -45
- data/lib/mocha/api.rb +199 -131
- data/lib/mocha/argument_iterator.rb +6 -10
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +77 -66
- data/lib/mocha/central.rb +27 -18
- data/lib/mocha/change_state_side_effect.rb +3 -7
- data/lib/mocha/class_methods.rb +62 -0
- data/lib/mocha/configuration.rb +399 -46
- data/lib/mocha/debug.rb +12 -0
- data/lib/mocha/deprecation.rb +11 -12
- data/lib/mocha/detection/mini_test.rb +23 -0
- data/lib/mocha/detection/test_unit.rb +27 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +8 -10
- data/lib/mocha/expectation.rb +290 -151
- data/lib/mocha/expectation_error.rb +6 -13
- data/lib/mocha/expectation_error_factory.rb +35 -0
- data/lib/mocha/expectation_list.rb +22 -22
- data/lib/mocha/hooks.rb +42 -0
- data/lib/mocha/in_state_ordering_constraint.rb +3 -7
- data/lib/mocha/inspect.rb +35 -43
- data/lib/mocha/instance_method.rb +12 -21
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test/adapter.rb +52 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -7
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +35 -25
- data/lib/mocha/integration/mini_test/version_140.rb +35 -26
- data/lib/mocha/integration/mini_test/version_141.rb +43 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +44 -35
- data/lib/mocha/integration/mini_test/version_200.rb +45 -36
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +44 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +70 -0
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +73 -0
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +68 -0
- data/lib/mocha/integration/mini_test.rb +51 -49
- data/lib/mocha/integration/monkey_patcher.rb +24 -0
- data/lib/mocha/integration/test_unit/adapter.rb +50 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +39 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +68 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +39 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +40 -30
- data/lib/mocha/integration/test_unit.rb +45 -51
- data/lib/mocha/integration.rb +6 -33
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +2 -6
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +6 -10
- data/lib/mocha/minitest.rb +8 -0
- data/lib/mocha/mock.rb +266 -79
- data/lib/mocha/mockery.rb +104 -106
- data/lib/mocha/names.rb +10 -20
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +169 -0
- data/lib/mocha/parameter_matchers/all_of.rb +18 -14
- data/lib/mocha/parameter_matchers/any_of.rb +19 -14
- data/lib/mocha/parameter_matchers/any_parameters.rb +14 -13
- data/lib/mocha/parameter_matchers/anything.rb +17 -14
- data/lib/mocha/parameter_matchers/base.rb +33 -31
- data/lib/mocha/parameter_matchers/equals.rb +18 -13
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +58 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +19 -14
- data/lib/mocha/parameter_matchers/has_entry.rb +58 -26
- data/lib/mocha/parameter_matchers/has_key.rb +18 -13
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +18 -13
- data/lib/mocha/parameter_matchers/includes.rb +80 -19
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +18 -13
- data/lib/mocha/parameter_matchers/is_a.rb +20 -14
- data/lib/mocha/parameter_matchers/kind_of.rb +20 -13
- data/lib/mocha/parameter_matchers/not.rb +19 -14
- data/lib/mocha/parameter_matchers/optionally.rb +23 -17
- data/lib/mocha/parameter_matchers/regexp_matches.rb +16 -12
- data/lib/mocha/parameter_matchers/responds_with.rb +17 -11
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +15 -9
- data/lib/mocha/parameter_matchers.rb +4 -5
- data/lib/mocha/parameters_matcher.rb +11 -14
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +45 -0
- data/lib/mocha/return_values.rb +11 -15
- data/lib/mocha/ruby_version.rb +4 -0
- data/lib/mocha/sequence.rb +21 -17
- data/lib/mocha/setup.rb +14 -0
- data/lib/mocha/single_return_value.rb +5 -8
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +69 -67
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/stubbing_error.rb +6 -14
- data/lib/mocha/test_unit.rb +8 -0
- data/lib/mocha/thrower.rb +6 -8
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +12 -22
- data/lib/mocha.rb +8 -3
- data/mocha.gemspec +43 -34
- data/yard-templates/default/layout/html/google_analytics.erb +8 -0
- data/yard-templates/default/layout/html/setup.rb +5 -0
- metadata +123 -268
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -54
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -8
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -98
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_230_to_262.rb +0 -59
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_240.rb +0 -58
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/object.rb +0 -223
- data/lib/mocha/options.rb +0 -1
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/parameter_matchers/query_string.rb +0 -47
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -1
- data/lib/mocha/unexpected_invocation.rb +0 -18
- data/lib/mocha_standalone.rb +0 -2
- data/lib/stubba.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/bug_18914_test.rb +0 -43
- data/test/acceptance/bug_21465_test.rb +0 -34
- data/test/acceptance/bug_21563_test.rb +0 -25
- data/test/acceptance/exception_rescue_test.rb +0 -55
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -232
- data/test/acceptance/failure_messages_test.rb +0 -64
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/acceptance/mocha_example_test.rb +0 -98
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -100
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
- data/test/acceptance/optional_parameters_test.rb +0 -70
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/raise_exception_test.rb +0 -39
- data/test/acceptance/return_value_test.rb +0 -52
- data/test/acceptance/sequence_test.rb +0 -192
- data/test/acceptance/states_test.rb +0 -70
- data/test/acceptance/stub_any_instance_method_test.rb +0 -198
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -72
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -75
- data/test/acceptance/stub_everything_test.rb +0 -56
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -66
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
- data/test/acceptance/stub_module_method_test.rb +0 -163
- data/test/acceptance/stub_test.rb +0 -52
- data/test/acceptance/stubba_example_test.rb +0 -102
- data/test/acceptance/stubba_test.rb +0 -15
- data/test/acceptance/stubba_test_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unstubbing_test.rb +0 -151
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -83
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -11
- data/test/test_runner.rb +0 -50
- data/test/unit/any_instance_method_test.rb +0 -136
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/backtrace_filter_test.rb +0 -19
- data/test/unit/cardinality_test.rb +0 -56
- data/test/unit/central_test.rb +0 -100
- data/test/unit/change_state_side_effect_test.rb +0 -41
- data/test/unit/class_method_test.rb +0 -260
- data/test/unit/configuration_test.rb +0 -38
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/exception_raiser_test.rb +0 -42
- data/test/unit/expectation_list_test.rb +0 -71
- data/test/unit/expectation_test.rb +0 -480
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -23
- data/test/unit/mock_test.rb +0 -312
- data/test/unit/mockery_test.rb +0 -150
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yields_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -38
- data/test/unit/object_test.rb +0 -87
- 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/equals_test.rb +0 -25
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -96
- data/test/unit/parameter_matchers/has_key_test.rb +0 -55
- data/test/unit/parameter_matchers/has_value_test.rb +0 -57
- data/test/unit/parameter_matchers/includes_test.rb +0 -44
- 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 -46
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -25
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
- 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/single_return_value_test.rb +0 -14
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/state_machine_test.rb +0 -98
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/thrower_test.rb +0 -20
- data/test/unit/yield_parameters_test.rb +0 -93
data/examples/misc.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class MiscExampleTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_mocking_a_class_method
|
7
|
-
product = Product.new
|
8
|
-
Product.expects(:find).with(1).returns(product)
|
9
|
-
assert_equal product, Product.find(1)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_mocking_an_instance_method_on_a_real_object
|
13
|
-
product = Product.new
|
14
|
-
product.expects(:save).returns(true)
|
15
|
-
assert product.save
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_stubbing_instance_methods_on_real_objects
|
19
|
-
prices = [stub(:pence => 1000), stub(:pence => 2000)]
|
20
|
-
product = Product.new
|
21
|
-
product.stubs(:prices).returns(prices)
|
22
|
-
assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_stubbing_an_instance_method_on_all_instances_of_a_class
|
26
|
-
Product.any_instance.stubs(:name).returns('stubbed_name')
|
27
|
-
product = Product.new
|
28
|
-
assert_equal 'stubbed_name', product.name
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_traditional_mocking
|
32
|
-
object = mock()
|
33
|
-
object.expects(:expected_method).with(:p1, :p2).returns(:result)
|
34
|
-
assert_equal :result, object.expected_method(:p1, :p2)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_shortcuts
|
38
|
-
object = stub(:method1 => :result1, :method2 => :result2)
|
39
|
-
assert_equal :result1, object.method1
|
40
|
-
assert_equal :result2, object.method2
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/examples/mocha.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
class Enterprise
|
2
|
-
|
3
|
-
def initialize(dilithium)
|
4
|
-
@dilithium = dilithium
|
5
|
-
end
|
6
|
-
|
7
|
-
def go(warp_factor)
|
8
|
-
warp_factor.times { @dilithium.nuke(:anti_matter) }
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'test/unit'
|
14
|
-
require 'mocha'
|
15
|
-
|
16
|
-
class EnterpriseTest < Test::Unit::TestCase
|
17
|
-
|
18
|
-
def test_should_boldly_go
|
19
|
-
dilithium = mock()
|
20
|
-
dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test
|
21
|
-
enterprise = Enterprise.new(dilithium)
|
22
|
-
enterprise.go(2)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/examples/stubba.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
class Order
|
2
|
-
|
3
|
-
attr_accessor :shipped_on
|
4
|
-
|
5
|
-
def total_cost
|
6
|
-
line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost
|
7
|
-
end
|
8
|
-
|
9
|
-
def total_weight
|
10
|
-
line_items.inject(0) { |total, line_item| total + line_item.weight }
|
11
|
-
end
|
12
|
-
|
13
|
-
def shipping_cost
|
14
|
-
total_weight * 5 + 10
|
15
|
-
end
|
16
|
-
|
17
|
-
class << self
|
18
|
-
|
19
|
-
def find_all
|
20
|
-
# Database.connection.execute('select * from orders...
|
21
|
-
end
|
22
|
-
|
23
|
-
def number_shipped_since(date)
|
24
|
-
find_all.select { |order| order.shipped_on > date }.length
|
25
|
-
end
|
26
|
-
|
27
|
-
def unshipped_value
|
28
|
-
find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost }
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
require 'test/unit'
|
36
|
-
require 'mocha'
|
37
|
-
|
38
|
-
class OrderTest < Test::Unit::TestCase
|
39
|
-
|
40
|
-
# illustrates stubbing instance method
|
41
|
-
def test_should_calculate_shipping_cost_based_on_total_weight
|
42
|
-
order = Order.new
|
43
|
-
order.stubs(:total_weight).returns(10)
|
44
|
-
assert_equal 60, order.shipping_cost
|
45
|
-
end
|
46
|
-
|
47
|
-
# illustrates stubbing class method
|
48
|
-
def test_should_count_number_of_orders_shipped_after_specified_date
|
49
|
-
now = Time.now; week_in_secs = 7 * 24 * 60 * 60
|
50
|
-
order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs
|
51
|
-
order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs
|
52
|
-
Order.stubs(:find_all).returns([order_1, order_2])
|
53
|
-
assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs)
|
54
|
-
end
|
55
|
-
|
56
|
-
# illustrates stubbing instance method for all instances of a class
|
57
|
-
def test_should_calculate_value_of_unshipped_orders
|
58
|
-
Order.stubs(:find_all).returns([Order.new, Order.new, Order.new])
|
59
|
-
Order.any_instance.stubs(:shipped_on).returns(nil)
|
60
|
-
Order.any_instance.stubs(:total_cost).returns(10)
|
61
|
-
assert_equal 30, Order.unshipped_value
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/lib/mocha/class_method.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'metaclass'
|
2
|
-
|
3
|
-
module Mocha
|
4
|
-
|
5
|
-
class ClassMethod
|
6
|
-
|
7
|
-
attr_reader :stubbee, :method
|
8
|
-
|
9
|
-
def initialize(stubbee, method)
|
10
|
-
@stubbee = stubbee
|
11
|
-
@method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym
|
12
|
-
end
|
13
|
-
|
14
|
-
def stub
|
15
|
-
hide_original_method
|
16
|
-
define_new_method
|
17
|
-
end
|
18
|
-
|
19
|
-
def unstub
|
20
|
-
remove_new_method
|
21
|
-
restore_original_method
|
22
|
-
mock.unstub(method.to_sym)
|
23
|
-
unless mock.any_expectations?
|
24
|
-
reset_mocha
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def mock
|
29
|
-
stubbee.mocha
|
30
|
-
end
|
31
|
-
|
32
|
-
def reset_mocha
|
33
|
-
stubbee.reset_mocha
|
34
|
-
end
|
35
|
-
|
36
|
-
def hide_original_method
|
37
|
-
if method_exists?(method)
|
38
|
-
begin
|
39
|
-
stubbee.__metaclass__.send(:alias_method, hidden_method, method)
|
40
|
-
rescue NameError
|
41
|
-
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def define_new_method
|
47
|
-
stubbee.__metaclass__.class_eval(%{
|
48
|
-
def #{method}(*args, &block)
|
49
|
-
mocha.method_missing(:#{method}, *args, &block)
|
50
|
-
end
|
51
|
-
}, __FILE__, __LINE__)
|
52
|
-
end
|
53
|
-
|
54
|
-
def remove_new_method
|
55
|
-
stubbee.__metaclass__.send(:remove_method, method)
|
56
|
-
end
|
57
|
-
|
58
|
-
def restore_original_method
|
59
|
-
if method_exists?(hidden_method)
|
60
|
-
begin
|
61
|
-
stubbee.__metaclass__.send(:alias_method, method, hidden_method)
|
62
|
-
stubbee.__metaclass__.send(:remove_method, hidden_method)
|
63
|
-
rescue NameError
|
64
|
-
# deal with nasties like ActiveRecord::Associations::AssociationProxy
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def hidden_method
|
70
|
-
if RUBY_VERSION < '1.9'
|
71
|
-
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" }
|
72
|
-
else
|
73
|
-
method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" }
|
74
|
-
end
|
75
|
-
hidden_method = "__stubba__#{method_name}__stubba__"
|
76
|
-
RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym
|
77
|
-
end
|
78
|
-
|
79
|
-
def matches?(other)
|
80
|
-
return false unless (other.class == self.class)
|
81
|
-
(stubbee.object_id == other.stubbee.object_id) and (method == other.method)
|
82
|
-
end
|
83
|
-
|
84
|
-
alias_method :==, :eql?
|
85
|
-
|
86
|
-
def to_s
|
87
|
-
"#{stubbee}.#{method}"
|
88
|
-
end
|
89
|
-
|
90
|
-
def method_exists?(method)
|
91
|
-
symbol = method.to_sym
|
92
|
-
__metaclass__ = stubbee.__metaclass__
|
93
|
-
__metaclass__.public_method_defined?(symbol) || __metaclass__.protected_method_defined?(symbol) || __metaclass__.private_method_defined?(symbol)
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Mocha
|
2
|
-
|
3
|
-
module Integration
|
4
|
-
|
5
|
-
module MiniTest
|
6
|
-
|
7
|
-
class AssertionCounter
|
8
|
-
|
9
|
-
def initialize(test_case)
|
10
|
-
@test_case = test_case
|
11
|
-
end
|
12
|
-
|
13
|
-
def increment
|
14
|
-
@test_case._assertions += 1
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,59 +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 Version230To262
|
11
|
-
def self.included(mod)
|
12
|
-
$stderr.puts "Monkey patching MiniTest >= v2.3.0 <= v2.6.2" if $mocha_options['debug']
|
13
|
-
end
|
14
|
-
def run runner
|
15
|
-
trap 'INFO' do
|
16
|
-
time = runner.start_time ? Time.now - runner.start_time : 0
|
17
|
-
warn "%s#%s %.2fs" % [self.class, self.__name__, time]
|
18
|
-
runner.status $stderr
|
19
|
-
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
20
|
-
|
21
|
-
assertion_counter = AssertionCounter.new(self)
|
22
|
-
result = ""
|
23
|
-
begin
|
24
|
-
begin
|
25
|
-
@passed = nil
|
26
|
-
self.setup
|
27
|
-
self.run_setup_hooks
|
28
|
-
self.__send__ self.__name__
|
29
|
-
mocha_verify(assertion_counter)
|
30
|
-
result = "." unless io?
|
31
|
-
@passed = true
|
32
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
33
|
-
raise
|
34
|
-
rescue Exception => e
|
35
|
-
@passed = false
|
36
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
37
|
-
ensure
|
38
|
-
begin
|
39
|
-
self.run_teardown_hooks
|
40
|
-
self.teardown
|
41
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
42
|
-
raise
|
43
|
-
rescue Exception => e
|
44
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
45
|
-
end
|
46
|
-
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
47
|
-
end
|
48
|
-
ensure
|
49
|
-
mocha_teardown
|
50
|
-
end
|
51
|
-
result
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
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 GemVersion230To240
|
12
|
-
def self.included(mod)
|
13
|
-
$stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.4.0" 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/module_method.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'mocha/class_method'
|
2
|
-
|
3
|
-
module Mocha
|
4
|
-
|
5
|
-
class ModuleMethod < ClassMethod
|
6
|
-
|
7
|
-
def method_exists?(method)
|
8
|
-
return true if stubbee.public_methods(false).include?(method)
|
9
|
-
return true if stubbee.protected_methods(false).include?(method)
|
10
|
-
return true if stubbee.private_methods(false).include?(method)
|
11
|
-
return false
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Mocha # :nodoc:
|
2
|
-
|
3
|
-
class MultipleYields # :nodoc:
|
4
|
-
|
5
|
-
attr_reader :parameter_groups
|
6
|
-
|
7
|
-
def initialize(*parameter_groups)
|
8
|
-
@parameter_groups = parameter_groups
|
9
|
-
end
|
10
|
-
|
11
|
-
def each
|
12
|
-
@parameter_groups.each do |parameter_group|
|
13
|
-
yield(parameter_group)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|