mocha 0.5.6 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -4
- data/RELEASE +45 -0
- data/Rakefile +55 -33
- data/lib/mocha.rb +1 -0
- data/lib/mocha/any_instance_method.rb +24 -4
- data/lib/mocha/backtrace_filter.rb +17 -0
- data/lib/mocha/cardinality.rb +92 -0
- data/lib/mocha/central.rb +1 -9
- data/lib/mocha/change_state_side_effect.rb +19 -0
- data/lib/mocha/class_method.rb +25 -5
- data/lib/mocha/configuration.rb +60 -0
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation.rb +109 -48
- data/lib/mocha/expectation_error.rb +6 -6
- data/lib/mocha/expectation_list.rb +10 -14
- data/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/lib/mocha/instance_method.rb +9 -0
- data/lib/mocha/logger.rb +15 -0
- data/lib/mocha/mock.rb +19 -14
- data/lib/mocha/mockery.rb +166 -0
- data/lib/mocha/module_method.rb +17 -0
- data/lib/mocha/names.rb +53 -0
- data/lib/mocha/object.rb +26 -9
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/parameter_matchers/all_of.rb +3 -3
- data/lib/mocha/parameter_matchers/any_of.rb +3 -3
- data/lib/mocha/parameter_matchers/anything.rb +1 -1
- data/lib/mocha/parameter_matchers/has_entries.rb +4 -1
- data/lib/mocha/parameter_matchers/has_entry.rb +3 -2
- data/lib/mocha/parameter_matchers/has_key.rb +1 -1
- data/lib/mocha/parameter_matchers/has_value.rb +1 -1
- data/lib/mocha/parameter_matchers/not.rb +2 -2
- data/lib/mocha/parameter_matchers/object.rb +1 -1
- data/lib/mocha/parameter_matchers/optionally.rb +22 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +2 -2
- data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/lib/mocha/single_return_value.rb +2 -9
- data/lib/mocha/standalone.rb +151 -17
- data/lib/mocha/state_machine.rb +91 -0
- data/lib/mocha/stubbing_error.rb +16 -0
- data/lib/mocha/test_case_adapter.rb +76 -22
- data/lib/stubba.rb +2 -1
- data/test/acceptance/acceptance_test_helper.rb +38 -0
- data/test/acceptance/bug_18914_test.rb +43 -0
- data/test/acceptance/{expected_invocation_count_acceptance_test.rb → expected_invocation_count_test.rb} +29 -20
- data/test/acceptance/failure_messages_test.rb +64 -0
- data/test/acceptance/{mocha_acceptance_test.rb → mocha_example_test.rb} +5 -5
- data/test/{integration/mocha_test_result_integration_test.rb → acceptance/mocha_test_result_test.rb} +19 -40
- data/test/acceptance/mock_test.rb +100 -0
- data/test/acceptance/{mock_with_initializer_block_acceptance_test.rb → mock_with_initializer_block_test.rb} +12 -5
- data/test/acceptance/{mocked_methods_dispatch_acceptance_test.rb → mocked_methods_dispatch_test.rb} +12 -5
- data/test/acceptance/{optional_parameters_acceptance_test.rb → optional_parameters_test.rb} +11 -4
- data/test/acceptance/{parameter_matcher_acceptance_test.rb → parameter_matcher_test.rb} +67 -5
- data/test/acceptance/{partial_mocks_acceptance_test.rb → partial_mocks_test.rb} +12 -5
- data/test/acceptance/return_value_test.rb +52 -0
- data/test/acceptance/{sequence_acceptance_test.rb → sequence_test.rb} +13 -6
- data/test/acceptance/{standalone_acceptance_test.rb → standalone_test.rb} +19 -11
- data/test/acceptance/states_test.rb +70 -0
- data/test/acceptance/stub_any_instance_method_test.rb +195 -0
- data/test/acceptance/stub_class_method_test.rb +203 -0
- data/test/acceptance/stub_everything_test.rb +56 -0
- data/test/acceptance/stub_instance_method_test.rb +165 -0
- data/test/acceptance/stub_module_method_test.rb +163 -0
- data/test/acceptance/stub_test.rb +52 -0
- data/test/acceptance/{stubba_acceptance_test.rb → stubba_example_test.rb} +1 -1
- data/test/{integration/stubba_test_result_integration_test.rb → acceptance/stubba_test_result_test.rb} +17 -36
- data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +155 -0
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +145 -0
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_public_class_method_test.rb +161 -0
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +141 -0
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
- data/test/execution_point.rb +3 -1
- data/test/simple_counter.rb +13 -0
- data/test/test_helper.rb +0 -1
- data/test/test_runner.rb +6 -4
- 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 +19 -0
- data/test/unit/cardinality_test.rb +56 -0
- data/test/unit/central_test.rb +4 -63
- data/test/unit/change_state_side_effect_test.rb +41 -0
- data/test/unit/class_method_test.rb +38 -1
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/{expectation_raiser_test.rb → exception_raiser_test.rb} +14 -0
- data/test/unit/expectation_list_test.rb +4 -22
- data/test/unit/expectation_test.rb +70 -94
- data/test/unit/in_state_ordering_constraint_test.rb +43 -0
- data/test/unit/mock_test.rb +16 -37
- data/test/unit/mockery_test.rb +149 -0
- data/test/unit/{no_yield_test.rb → no_yields_test.rb} +0 -0
- data/test/unit/object_test.rb +6 -89
- data/test/unit/parameter_matchers/equals_test.rb +25 -0
- data/test/unit/parameter_matchers/has_entries_test.rb +22 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +24 -2
- data/test/unit/parameter_matchers/has_key_test.rb +11 -0
- data/test/unit/parameter_matchers/has_value_test.rb +12 -0
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +4 -0
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
- data/test/unit/single_return_value_test.rb +0 -19
- data/test/unit/state_machine_test.rb +98 -0
- metadata +108 -69
- data/lib/mocha/auto_verify.rb +0 -118
- data/lib/mocha/infinite_range.rb +0 -25
- data/lib/mocha/missing_expectation.rb +0 -17
- data/lib/mocha/setup_and_teardown.rb +0 -23
- data/lib/mocha/stub.rb +0 -18
- data/test/integration/stubba_integration_test.rb +0 -89
- data/test/unit/auto_verify_test.rb +0 -129
- data/test/unit/expectation_error_test.rb +0 -24
- data/test/unit/infinite_range_test.rb +0 -53
- data/test/unit/missing_expectation_test.rb +0 -42
- data/test/unit/setup_and_teardown_test.rb +0 -76
- data/test/unit/stub_test.rb +0 -24
File without changes
|
data/test/unit/object_test.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/object'
|
3
|
+
require 'mocha/mockery'
|
2
4
|
require 'mocha/mock'
|
3
5
|
require 'method_definer'
|
4
6
|
|
5
|
-
require 'mocha/object'
|
6
|
-
|
7
7
|
class ObjectTest < Test::Unit::TestCase
|
8
8
|
|
9
9
|
include Mocha
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_should_build_mocha_referring_to_self
|
12
12
|
instance = Object.new
|
13
13
|
mocha = instance.mocha
|
14
14
|
assert_not_nil mocha
|
15
15
|
assert mocha.is_a?(Mock)
|
16
|
+
assert_equal instance.mocha_inspect, mocha.mocha_inspect
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_should_reuse_existing_mocha
|
@@ -27,58 +28,6 @@ class ObjectTest < Test::Unit::TestCase
|
|
27
28
|
assert_nil instance.reset_mocha
|
28
29
|
end
|
29
30
|
|
30
|
-
def test_should_stub_instance_method
|
31
|
-
instance = Object.new
|
32
|
-
$stubba = Mock.new
|
33
|
-
$stubba.expects(:stub).with(Mocha::InstanceMethod.new(instance, :method1))
|
34
|
-
instance.expects(:method1)
|
35
|
-
$stubba.verify
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_build_and_store_expectation
|
39
|
-
instance = Object.new
|
40
|
-
$stubba = Mock.new
|
41
|
-
$stubba.stubs(:stub)
|
42
|
-
expectation = instance.expects(:method1)
|
43
|
-
assert_equal [expectation], instance.mocha.expectations.to_a
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_should_verify_expectations
|
47
|
-
instance = Object.new
|
48
|
-
$stubba = Mock.new
|
49
|
-
$stubba.stubs(:stub)
|
50
|
-
instance.expects(:method1).with(:value1, :value2)
|
51
|
-
assert_raise(ExpectationError) { instance.verify }
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_should_pass_backtrace_into_expects
|
55
|
-
instance = Object.new
|
56
|
-
$stubba = Mock.new
|
57
|
-
$stubba.stubs(:stub)
|
58
|
-
mocha = Object.new
|
59
|
-
mocha.define_instance_accessor(:expects_parameters)
|
60
|
-
mocha.define_instance_method(:expects) { |*parameters| self.expects_parameters = parameters }
|
61
|
-
backtrace = Object.new
|
62
|
-
instance.define_instance_method(:mocha) { mocha }
|
63
|
-
instance.define_instance_method(:caller) { backtrace }
|
64
|
-
instance.expects(:method1)
|
65
|
-
assert_equal [:method1, backtrace], mocha.expects_parameters
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_should_pass_backtrace_into_stubs
|
69
|
-
instance = Object.new
|
70
|
-
$stubba = Mock.new
|
71
|
-
$stubba.stubs(:stub)
|
72
|
-
mocha = Object.new
|
73
|
-
mocha.define_instance_accessor(:stubs_parameters)
|
74
|
-
mocha.define_instance_method(:stubs) { |*parameters| self.stubs_parameters = parameters }
|
75
|
-
backtrace = Object.new
|
76
|
-
instance.define_instance_method(:mocha) { mocha }
|
77
|
-
instance.define_instance_method(:caller) { backtrace }
|
78
|
-
instance.stubs(:method1)
|
79
|
-
assert_equal [:method1, backtrace], mocha.stubs_parameters
|
80
|
-
end
|
81
|
-
|
82
31
|
def test_should_build_any_instance_object
|
83
32
|
klass = Class.new
|
84
33
|
any_instance = klass.any_instance
|
@@ -93,44 +42,12 @@ class ObjectTest < Test::Unit::TestCase
|
|
93
42
|
assert_equal any_instance_1, any_instance_2
|
94
43
|
end
|
95
44
|
|
96
|
-
def test_should_stub_class_method
|
97
|
-
klass = Class.new
|
98
|
-
$stubba = Mock.new
|
99
|
-
$stubba.expects(:stub).with(Mocha::ClassMethod.new(klass, :method1))
|
100
|
-
klass.expects(:method1)
|
101
|
-
$stubba.verify
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_should_build_and_store_class_method_expectation
|
105
|
-
klass = Class.new
|
106
|
-
$stubba = Mock.new
|
107
|
-
$stubba.stubs(:stub)
|
108
|
-
expectation = klass.expects(:method1)
|
109
|
-
assert_equal [expectation], klass.mocha.expectations.to_a
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_should_stub_module_method
|
113
|
-
mod = Module.new
|
114
|
-
$stubba = Mock.new
|
115
|
-
$stubba.expects(:stub).with(Mocha::ClassMethod.new(mod, :method1))
|
116
|
-
mod.expects(:method1)
|
117
|
-
$stubba.verify
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_should_build_and_store_module_method_expectation
|
121
|
-
mod = Module.new
|
122
|
-
$stubba = Mock.new
|
123
|
-
$stubba.stubs(:stub)
|
124
|
-
expectation = mod.expects(:method1)
|
125
|
-
assert_equal [expectation], mod.mocha.expectations.to_a
|
126
|
-
end
|
127
|
-
|
128
45
|
def test_should_use_stubba_instance_method_for_object
|
129
46
|
assert_equal Mocha::InstanceMethod, Object.new.stubba_method
|
130
47
|
end
|
131
48
|
|
132
|
-
def
|
133
|
-
assert_equal Mocha::
|
49
|
+
def test_should_use_stubba_module_method_for_module
|
50
|
+
assert_equal Mocha::ModuleMethod, Module.new.stubba_method
|
134
51
|
end
|
135
52
|
|
136
53
|
def test_should_use_stubba_class_method_for_class
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/parameter_matchers/equals'
|
4
|
+
require 'mocha/inspect'
|
5
|
+
|
6
|
+
class EqualsTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha::ParameterMatchers
|
9
|
+
|
10
|
+
def test_should_match_object_that_equals_value
|
11
|
+
matcher = equals('x')
|
12
|
+
assert matcher.matches?(['x'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_match_object_that_does_not_equal_value
|
16
|
+
matcher = equals('x')
|
17
|
+
assert !matcher.matches?(['y'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_describe_matcher
|
21
|
+
matcher = equals('x')
|
22
|
+
assert_equal "'x'", matcher.mocha_inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/parameter_matchers/has_entries'
|
4
|
+
require 'mocha/parameter_matchers/object'
|
4
5
|
require 'mocha/inspect'
|
5
6
|
|
6
7
|
class HasEntriesTest < Test::Unit::TestCase
|
@@ -22,9 +23,29 @@ class HasEntriesTest < Test::Unit::TestCase
|
|
22
23
|
description = matcher.mocha_inspect
|
23
24
|
matches = /has_entries\((.*)\)/.match(description)
|
24
25
|
assert_not_nil matches[0]
|
25
|
-
entries = eval(matches[1])
|
26
|
+
entries = eval(matches[1], binding, __FILE__, __LINE__)
|
26
27
|
assert_equal 'value_1', entries[:key_1]
|
27
28
|
assert_equal 'value_2', entries[:key_2]
|
28
29
|
end
|
29
30
|
|
31
|
+
def test_should_match_hash_including_specified_entries_with_nested_key_matchers
|
32
|
+
matcher = has_entries(equals(:key_1) => 'value_1', equals(:key_2) => 'value_2')
|
33
|
+
assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }])
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_not_match_hash_not_including_specified_entries_with_nested_key_matchers
|
37
|
+
matcher = has_entries(equals(:key_1) => 'value_2', equals(:key_2) => 'value_2', equals(:key_3) => 'value_3')
|
38
|
+
assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_match_hash_including_specified_entries_with_nested_value_matchers
|
42
|
+
matcher = has_entries(:key_1 => equals('value_1'), :key_2 => equals('value_2'))
|
43
|
+
assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3' }])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_not_match_hash_not_including_specified_entries_with_nested_value_matchers
|
47
|
+
matcher = has_entries(:key_1 => equals('value_2'), :key_2 => equals('value_2'), :key_3 => equals('value_3'))
|
48
|
+
assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
49
|
+
end
|
50
|
+
|
30
51
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/parameter_matchers/has_entry'
|
4
|
+
require 'mocha/parameter_matchers/object'
|
5
|
+
require 'mocha/parameter_matchers/equals'
|
4
6
|
require 'mocha/inspect'
|
5
7
|
|
6
8
|
class HasEntryTest < Test::Unit::TestCase
|
@@ -29,12 +31,32 @@ class HasEntryTest < Test::Unit::TestCase
|
|
29
31
|
|
30
32
|
def test_should_describe_matcher_with_key_value_pair
|
31
33
|
matcher = has_entry(:key_1, 'value_1')
|
32
|
-
assert_equal "has_entry(:key_1
|
34
|
+
assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect
|
33
35
|
end
|
34
36
|
|
35
37
|
def test_should_describe_matcher_with_entry
|
36
38
|
matcher = has_entry(:key_1 => 'value_1')
|
37
|
-
assert_equal "has_entry(:key_1
|
39
|
+
assert_equal "has_entry(:key_1 => 'value_1')", matcher.mocha_inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_match_hash_including_specified_entry_with_nested_key_matcher
|
43
|
+
matcher = has_entry(equals(:key_1) => 'value_1')
|
44
|
+
assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_match_hash_including_specified_entry_with_nested_value_matcher
|
48
|
+
matcher = has_entry(:key_1 => equals('value_1'))
|
49
|
+
assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_not_match_hash_not_including_specified_entry_with_nested_key_matcher
|
53
|
+
matcher = has_entry(equals(:key_1) => 'value_2')
|
54
|
+
assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_not_match_hash_not_including_specified_entry_with_nested_value_matcher
|
58
|
+
matcher = has_entry(:key_1 => equals('value_2'))
|
59
|
+
assert !matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
38
60
|
end
|
39
61
|
|
40
62
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/parameter_matchers/has_key'
|
4
|
+
require 'mocha/parameter_matchers/object'
|
4
5
|
require 'mocha/inspect'
|
5
6
|
|
6
7
|
class HasKeyTest < Test::Unit::TestCase
|
@@ -22,4 +23,14 @@ class HasKeyTest < Test::Unit::TestCase
|
|
22
23
|
assert_equal 'has_key(:key)', matcher.mocha_inspect
|
23
24
|
end
|
24
25
|
|
26
|
+
def test_should_match_hash_including_specified_key_with_nested_key_matcher
|
27
|
+
matcher = has_key(equals(:key_1))
|
28
|
+
assert matcher.matches?([{ :key_1 => 1, :key_2 => 2 }])
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_not_match_hash_not_including_specified_key_with_nested_key_matcher
|
32
|
+
matcher = has_key(equals(:key_1))
|
33
|
+
assert !matcher.matches?([{ :key_2 => 2 }])
|
34
|
+
end
|
35
|
+
|
25
36
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/parameter_matchers/has_value'
|
4
|
+
require 'mocha/parameter_matchers/object'
|
5
|
+
require 'mocha/parameter_matchers/equals'
|
4
6
|
require 'mocha/inspect'
|
5
7
|
|
6
8
|
class HasValueTest < Test::Unit::TestCase
|
@@ -22,4 +24,14 @@ class HasValueTest < Test::Unit::TestCase
|
|
22
24
|
assert_equal "has_value('value_1')", matcher.mocha_inspect
|
23
25
|
end
|
24
26
|
|
27
|
+
def test_should_match_hash_including_specified_value_with_nested_value_matcher
|
28
|
+
matcher = has_value(equals('value_1'))
|
29
|
+
assert matcher.matches?([{ :key_1 => 'value_1', :key_2 => 'value_2' }])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_not_match_hash_not_including_specified_value_with_nested_value_matcher
|
33
|
+
matcher = has_value(equals('value_1'))
|
34
|
+
assert !matcher.matches?([{ :key_2 => 'value_2' }])
|
35
|
+
end
|
36
|
+
|
25
37
|
end
|
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
|
3
3
|
require 'mocha/parameter_matchers/regexp_matches'
|
4
4
|
require 'mocha/inspect'
|
5
5
|
|
6
|
-
class
|
6
|
+
class RegexpMatchesTest < Test::Unit::TestCase
|
7
7
|
|
8
8
|
include Mocha::ParameterMatchers
|
9
9
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/parameter_matchers/responds_with'
|
4
|
+
require 'mocha/inspect'
|
5
|
+
|
6
|
+
class RespondsWithTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha::ParameterMatchers
|
9
|
+
|
10
|
+
def test_should_match_parameter_responding_with_expected_value
|
11
|
+
matcher = responds_with(:upcase, 'FOO')
|
12
|
+
assert matcher.matches?(['foo'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_match_parameter_responding_with_unexpected_value
|
16
|
+
matcher = responds_with(:upcase, 'FOO')
|
17
|
+
assert !matcher.matches?(['bar'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_describe_matcher
|
21
|
+
matcher = responds_with(:foo, :bar)
|
22
|
+
assert_equal 'responds_with(:foo, :bar)', matcher.mocha_inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/parameter_matchers/yaml_equivalent'
|
4
|
+
require 'mocha/inspect'
|
5
|
+
|
6
|
+
class YamlEquivalentTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha::ParameterMatchers
|
9
|
+
|
10
|
+
def test_should_match_parameter_matching_yaml_representation_of_object
|
11
|
+
matcher = yaml_equivalent([1, 2, 3])
|
12
|
+
assert matcher.matches?(["--- \n- 1\n- 2\n- 3\n"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_not_match_parameter_matching_yaml_representation_of_object
|
16
|
+
matcher = yaml_equivalent([1, 2, 3])
|
17
|
+
assert !matcher.matches?(["--- \n- 4\n- 5\n"])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_describe_matcher
|
21
|
+
matcher = yaml_equivalent([1, 2, 3])
|
22
|
+
assert_equal "yaml_equivalent([1, 2, 3])", matcher.mocha_inspect
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,33 +1,14 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
2
|
|
3
3
|
require 'mocha/single_return_value'
|
4
|
-
require 'deprecation_disabler'
|
5
4
|
|
6
5
|
class SingleReturnValueTest < Test::Unit::TestCase
|
7
6
|
|
8
7
|
include Mocha
|
9
|
-
include DeprecationDisabler
|
10
8
|
|
11
9
|
def test_should_return_value
|
12
10
|
value = SingleReturnValue.new('value')
|
13
11
|
assert_equal 'value', value.evaluate
|
14
12
|
end
|
15
13
|
|
16
|
-
def test_should_return_result_of_calling_proc
|
17
|
-
proc = lambda { 'value' }
|
18
|
-
value = SingleReturnValue.new(proc)
|
19
|
-
result = nil
|
20
|
-
disable_deprecations { result = value.evaluate }
|
21
|
-
assert_equal 'value', result
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_indicate_deprecated_use_of_expectation_returns_method
|
25
|
-
proc = lambda {}
|
26
|
-
value = SingleReturnValue.new(proc)
|
27
|
-
Deprecation.messages = []
|
28
|
-
disable_deprecations { value.evaluate }
|
29
|
-
expected_message = "use of Expectation#returns with instance of Proc - see Expectation#returns RDoc for alternatives"
|
30
|
-
assert_equal [expected_message], Deprecation.messages
|
31
|
-
end
|
32
|
-
|
33
14
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/state_machine'
|
4
|
+
|
5
|
+
class StateMachineTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_initially_be_in_no_state
|
10
|
+
state_machine = StateMachine.new('name')
|
11
|
+
any_state.each do |state|
|
12
|
+
assert !state_machine.is(state).active?
|
13
|
+
assert state_machine.is_not(state).active?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_be_able_to_enter_a_state
|
18
|
+
state_machine = StateMachine.new('name')
|
19
|
+
state = 'A'
|
20
|
+
other_states = any_state.reject { |s| s == state }
|
21
|
+
|
22
|
+
state_machine.is(state).activate
|
23
|
+
|
24
|
+
assert state_machine.is(state).active?
|
25
|
+
assert !state_machine.is_not(state).active?
|
26
|
+
other_states.each do |s|
|
27
|
+
assert !state_machine.is(s).active?
|
28
|
+
assert state_machine.is_not(s).active?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_be_able_to_change_state
|
33
|
+
state_machine = StateMachine.new('name')
|
34
|
+
state = 'B'
|
35
|
+
other_states = any_state.reject { |s| s == state }
|
36
|
+
|
37
|
+
state_machine.is('A').activate
|
38
|
+
state_machine.is(state).activate
|
39
|
+
|
40
|
+
assert state_machine.is(state).active?
|
41
|
+
assert !state_machine.is_not(state).active?
|
42
|
+
other_states.each do |s|
|
43
|
+
assert !state_machine.is(s).active?
|
44
|
+
assert state_machine.is_not(s).active?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_be_put_into_an_initial_state
|
49
|
+
state_machine = StateMachine.new('name')
|
50
|
+
initial_state = 'A'
|
51
|
+
other_states = any_state.reject { |s| s == initial_state }
|
52
|
+
|
53
|
+
state_machine.starts_as(initial_state)
|
54
|
+
|
55
|
+
assert state_machine.is(initial_state).active?
|
56
|
+
assert !state_machine.is_not(initial_state).active?
|
57
|
+
other_states.each do |state|
|
58
|
+
assert !state_machine.is(state).active?
|
59
|
+
assert state_machine.is_not(state).active?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_be_put_into_a_new_state
|
64
|
+
next_state = 'B'
|
65
|
+
|
66
|
+
other_states = any_state.reject { |s| s == next_state }
|
67
|
+
state_machine = StateMachine.new('name').starts_as('A')
|
68
|
+
|
69
|
+
state_machine.become(next_state)
|
70
|
+
|
71
|
+
assert state_machine.is(next_state).active?
|
72
|
+
assert !state_machine.is_not(next_state).active?
|
73
|
+
other_states.each do |state|
|
74
|
+
assert !state_machine.is(state).active?
|
75
|
+
assert state_machine.is_not(state).active?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_describe_itself_as_name_and_current_state
|
80
|
+
state_machine = StateMachine.new('state_machine_name')
|
81
|
+
assert_equal 'state_machine_name has no current state', state_machine.mocha_inspect
|
82
|
+
inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new
|
83
|
+
state_machine.is(inspectable_state).activate
|
84
|
+
assert_equal "state_machine_name is 'inspectable_state'", state_machine.mocha_inspect
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_should_have_self_describing_states
|
88
|
+
state_machine = StateMachine.new('state_machine_name')
|
89
|
+
inspectable_state = Class.new { define_method(:mocha_inspect) { "'inspectable_state'" } }.new
|
90
|
+
assert_equal "state_machine_name is 'inspectable_state'", state_machine.is(inspectable_state).mocha_inspect
|
91
|
+
assert_equal "state_machine_name is not 'inspectable_state'", state_machine.is_not(inspectable_state).mocha_inspect
|
92
|
+
end
|
93
|
+
|
94
|
+
def any_state
|
95
|
+
%w(A B C D)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|