jferris-mocha 0.9.5.0.1240002286
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/COPYING +3 -0
- data/MIT-LICENSE +7 -0
- data/README +37 -0
- data/RELEASE +269 -0
- data/Rakefile +217 -0
- data/examples/misc.rb +43 -0
- data/examples/mocha.rb +25 -0
- data/examples/stubba.rb +64 -0
- data/lib/mocha/any_instance_method.rb +55 -0
- data/lib/mocha/api.rb +232 -0
- data/lib/mocha/argument_iterator.rb +21 -0
- data/lib/mocha/backtrace_filter.rb +17 -0
- data/lib/mocha/cardinality.rb +95 -0
- data/lib/mocha/central.rb +27 -0
- data/lib/mocha/change_state_side_effect.rb +19 -0
- data/lib/mocha/class_method.rb +87 -0
- data/lib/mocha/configuration.rb +60 -0
- data/lib/mocha/deprecation.rb +22 -0
- data/lib/mocha/exception_raiser.rb +17 -0
- data/lib/mocha/expectation.rb +484 -0
- data/lib/mocha/expectation_error.rb +15 -0
- data/lib/mocha/expectation_list.rb +50 -0
- data/lib/mocha/in_state_ordering_constraint.rb +19 -0
- data/lib/mocha/inspect.rb +67 -0
- data/lib/mocha/instance_method.rb +16 -0
- data/lib/mocha/integration/bacon/assertion_counter.rb +23 -0
- data/lib/mocha/integration/bacon/version_11_and_above.rb +34 -0
- data/lib/mocha/integration/bacon.rb +1 -0
- data/lib/mocha/integration/mini_test/assertion_counter.rb +23 -0
- data/lib/mocha/integration/mini_test/version_131_and_above.rb +49 -0
- data/lib/mocha/integration/mini_test.rb +1 -0
- data/lib/mocha/integration/test_unit/assertion_counter.rb +23 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +49 -0
- data/lib/mocha/integration/test_unit/gem_version_201_and_above.rb +49 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +48 -0
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +50 -0
- data/lib/mocha/integration/test_unit.rb +4 -0
- data/lib/mocha/invocation.rb +10 -0
- data/lib/mocha/is_a.rb +9 -0
- data/lib/mocha/logger.rb +15 -0
- data/lib/mocha/metaclass.rb +13 -0
- data/lib/mocha/method_matcher.rb +21 -0
- data/lib/mocha/mock.rb +200 -0
- data/lib/mocha/mockery.rb +189 -0
- data/lib/mocha/module_method.rb +16 -0
- data/lib/mocha/multiple_yields.rb +20 -0
- data/lib/mocha/names.rb +53 -0
- data/lib/mocha/no_yields.rb +11 -0
- data/lib/mocha/object.rb +187 -0
- data/lib/mocha/parameter_matchers/all_of.rb +42 -0
- data/lib/mocha/parameter_matchers/any_of.rb +47 -0
- data/lib/mocha/parameter_matchers/any_parameters.rb +40 -0
- data/lib/mocha/parameter_matchers/anything.rb +33 -0
- data/lib/mocha/parameter_matchers/base.rb +15 -0
- data/lib/mocha/parameter_matchers/equals.rb +42 -0
- data/lib/mocha/parameter_matchers/has_entries.rb +45 -0
- data/lib/mocha/parameter_matchers/has_entry.rb +57 -0
- data/lib/mocha/parameter_matchers/has_key.rb +42 -0
- data/lib/mocha/parameter_matchers/has_value.rb +42 -0
- data/lib/mocha/parameter_matchers/includes.rb +40 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +42 -0
- data/lib/mocha/parameter_matchers/is_a.rb +42 -0
- data/lib/mocha/parameter_matchers/kind_of.rb +42 -0
- data/lib/mocha/parameter_matchers/not.rb +42 -0
- data/lib/mocha/parameter_matchers/object.rb +15 -0
- data/lib/mocha/parameter_matchers/optionally.rb +55 -0
- data/lib/mocha/parameter_matchers/regexp_matches.rb +43 -0
- data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
- data/lib/mocha/parameter_matchers.rb +27 -0
- data/lib/mocha/parameters_matcher.rb +37 -0
- data/lib/mocha/pretty_parameters.rb +28 -0
- data/lib/mocha/return_values.rb +31 -0
- data/lib/mocha/sequence.rb +42 -0
- data/lib/mocha/single_return_value.rb +17 -0
- data/lib/mocha/single_yield.rb +18 -0
- data/lib/mocha/state_machine.rb +91 -0
- data/lib/mocha/stubbing_error.rb +16 -0
- data/lib/mocha/unexpected_invocation.rb +18 -0
- data/lib/mocha/yield_parameters.rb +31 -0
- data/lib/mocha.rb +69 -0
- data/lib/mocha_standalone.rb +2 -0
- data/lib/stubba.rb +4 -0
- data/test/acceptance/acceptance_test_helper.rb +38 -0
- data/test/acceptance/api_test.rb +139 -0
- data/test/acceptance/bacon_spec.rb +67 -0
- data/test/acceptance/bacon_test.rb +110 -0
- data/test/acceptance/bug_18914_test.rb +43 -0
- data/test/acceptance/bug_21465_test.rb +34 -0
- data/test/acceptance/bug_21563_test.rb +25 -0
- data/test/acceptance/expected_invocation_count_test.rb +196 -0
- data/test/acceptance/failure_messages_test.rb +64 -0
- data/test/acceptance/minitest_test.rb +146 -0
- data/test/acceptance/mocha_example_test.rb +98 -0
- data/test/acceptance/mocha_test_result_test.rb +84 -0
- data/test/acceptance/mock_test.rb +100 -0
- data/test/acceptance/mock_with_initializer_block_test.rb +51 -0
- data/test/acceptance/mocked_methods_dispatch_test.rb +78 -0
- data/test/acceptance/optional_parameters_test.rb +70 -0
- data/test/acceptance/parameter_matcher_test.rb +209 -0
- data/test/acceptance/partial_mocks_test.rb +47 -0
- data/test/acceptance/return_value_test.rb +52 -0
- data/test/acceptance/sequence_test.rb +186 -0
- data/test/acceptance/spy_test.rb +109 -0
- 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 +203 -0
- data/test/acceptance/stub_module_method_test.rb +163 -0
- data/test/acceptance/stub_test.rb +52 -0
- data/test/acceptance/stubba_example_test.rb +102 -0
- data/test/acceptance/stubba_test.rb +15 -0
- data/test/acceptance/stubba_test_result_test.rb +66 -0
- 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 +157 -0
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +147 -0
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
- data/test/acceptance/stubbing_non_public_class_method_test.rb +163 -0
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +143 -0
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
- data/test/deprecation_disabler.rb +15 -0
- data/test/execution_point.rb +36 -0
- data/test/matcher_helpers.rb +5 -0
- data/test/method_definer.rb +24 -0
- data/test/simple_counter.rb +13 -0
- data/test/test_helper.rb +16 -0
- data/test/test_runner.rb +33 -0
- data/test/unit/any_instance_method_test.rb +126 -0
- data/test/unit/array_inspect_test.rb +16 -0
- data/test/unit/assert_received_test.rb +136 -0
- data/test/unit/backtrace_filter_test.rb +19 -0
- data/test/unit/cardinality_test.rb +56 -0
- data/test/unit/central_test.rb +65 -0
- data/test/unit/change_state_side_effect_test.rb +41 -0
- data/test/unit/class_method_test.rb +237 -0
- data/test/unit/date_time_inspect_test.rb +21 -0
- data/test/unit/exception_raiser_test.rb +42 -0
- data/test/unit/expectation_list_test.rb +57 -0
- data/test/unit/expectation_test.rb +526 -0
- data/test/unit/hash_inspect_test.rb +16 -0
- data/test/unit/have_received_test.rb +137 -0
- data/test/unit/in_state_ordering_constraint_test.rb +43 -0
- data/test/unit/invocation_test.rb +17 -0
- data/test/unit/metaclass_test.rb +22 -0
- data/test/unit/method_matcher_test.rb +23 -0
- data/test/unit/mock_test.rb +329 -0
- data/test/unit/mockery_test.rb +163 -0
- data/test/unit/multiple_yields_test.rb +18 -0
- data/test/unit/no_yields_test.rb +18 -0
- data/test/unit/object_inspect_test.rb +37 -0
- data/test/unit/object_test.rb +82 -0
- data/test/unit/parameter_matchers/all_of_test.rb +26 -0
- data/test/unit/parameter_matchers/any_of_test.rb +26 -0
- data/test/unit/parameter_matchers/anything_test.rb +21 -0
- data/test/unit/parameter_matchers/equals_test.rb +25 -0
- data/test/unit/parameter_matchers/has_entries_test.rb +51 -0
- data/test/unit/parameter_matchers/has_entry_test.rb +82 -0
- data/test/unit/parameter_matchers/has_key_test.rb +36 -0
- data/test/unit/parameter_matchers/has_value_test.rb +37 -0
- data/test/unit/parameter_matchers/includes_test.rb +25 -0
- data/test/unit/parameter_matchers/instance_of_test.rb +25 -0
- data/test/unit/parameter_matchers/is_a_test.rb +25 -0
- data/test/unit/parameter_matchers/kind_of_test.rb +25 -0
- data/test/unit/parameter_matchers/not_test.rb +26 -0
- data/test/unit/parameter_matchers/regexp_matches_test.rb +25 -0
- data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +27 -0
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
- data/test/unit/parameters_matcher_test.rb +121 -0
- data/test/unit/return_values_test.rb +63 -0
- data/test/unit/sequence_test.rb +104 -0
- data/test/unit/single_return_value_test.rb +14 -0
- data/test/unit/single_yield_test.rb +18 -0
- data/test/unit/state_machine_test.rb +98 -0
- data/test/unit/string_inspect_test.rb +11 -0
- data/test/unit/yield_parameters_test.rb +93 -0
- metadata +245 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/parameters_matcher'
|
3
|
+
|
4
|
+
class ParametersMatcherTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Mocha
|
7
|
+
|
8
|
+
def test_should_match_any_actual_parameters_if_no_expected_parameters_specified
|
9
|
+
parameters_matcher = ParametersMatcher.new
|
10
|
+
assert parameters_matcher.match?(actual_parameters = [1, 2, 3])
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_match_if_actual_parameters_are_same_as_expected_parameters
|
14
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
|
15
|
+
assert parameters_matcher.match?(actual_parameters = [4, 5, 6])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_not_match_if_actual_parameters_are_different_from_expected_parameters
|
19
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
|
20
|
+
assert !parameters_matcher.match?(actual_parameters = [1, 2, 3])
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_not_match_if_there_are_less_actual_parameters_than_expected_parameters
|
24
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, 6])
|
25
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 5])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_not_match_if_there_are_more_actual_parameters_than_expected_parameters
|
29
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5])
|
30
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 5, 6])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_not_match_if_not_all_required_parameters_are_supplied
|
34
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
35
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
36
|
+
assert !parameters_matcher.match?(actual_parameters = [4])
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_match_if_all_required_parameters_match_and_no_optional_parameters_are_supplied
|
40
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
41
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
42
|
+
assert parameters_matcher.match?(actual_parameters = [4, 5])
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_match_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied
|
46
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
47
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
48
|
+
assert parameters_matcher.match?(actual_parameters = [4, 5, 6])
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_match_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied
|
52
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
53
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
54
|
+
assert parameters_matcher.match?(actual_parameters = [4, 5, 6, 7])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_not_match_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied
|
58
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
59
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
60
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 7, 8])
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_not_match_if_all_required_parameters_match_but_some_optional_parameters_do_not_match
|
64
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
65
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
66
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 5, 6, 0])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_not_match_if_some_required_parameters_do_not_match_although_all_optional_parameters_do_match
|
70
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
71
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
72
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 0, 6])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_not_match_if_all_required_parameters_match_but_no_optional_parameters_match
|
76
|
+
optionals = ParameterMatchers::Optionally.new(6, 7)
|
77
|
+
parameters_matcher = ParametersMatcher.new(expected_parameters = [4, 5, optionals])
|
78
|
+
assert !parameters_matcher.match?(actual_parameters = [4, 5, 0, 0])
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_match_if_actual_parameters_satisfy_matching_block
|
82
|
+
parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 }
|
83
|
+
assert parameters_matcher.match?(actual_parameters = [1, 2])
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_not_match_if_actual_parameters_do_not_satisfy_matching_block
|
87
|
+
parameters_matcher = ParametersMatcher.new { |x, y| x + y == 3 }
|
88
|
+
assert !parameters_matcher.match?(actual_parameters = [2, 3])
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_should_remove_outer_array_braces
|
92
|
+
params = [1, 2, [3, 4]]
|
93
|
+
parameters_matcher = ParametersMatcher.new(params)
|
94
|
+
assert_equal '(1, 2, [3, 4])', parameters_matcher.mocha_inspect
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_display_numeric_arguments_as_is
|
98
|
+
params = [1, 2, 3]
|
99
|
+
parameters_matcher = ParametersMatcher.new(params)
|
100
|
+
assert_equal '(1, 2, 3)', parameters_matcher.mocha_inspect
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_should_remove_curly_braces_if_hash_is_only_argument
|
104
|
+
params = [{:a => 1, :z => 2}]
|
105
|
+
parameters_matcher = ParametersMatcher.new(params)
|
106
|
+
assert_nil parameters_matcher.mocha_inspect.index('{')
|
107
|
+
assert_nil parameters_matcher.mocha_inspect.index('}')
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_should_not_remove_curly_braces_if_hash_is_not_the_only_argument
|
111
|
+
params = [1, {:a => 1}]
|
112
|
+
parameters_matcher = ParametersMatcher.new(params)
|
113
|
+
assert_equal '(1, {:a => 1})', parameters_matcher.mocha_inspect
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_should_indicate_that_matcher_will_match_any_actual_parameters
|
117
|
+
parameters_matcher = ParametersMatcher.new
|
118
|
+
assert_equal '(any_parameters)', parameters_matcher.mocha_inspect
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/return_values'
|
4
|
+
|
5
|
+
class ReturnValuesTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_return_nil
|
10
|
+
values = ReturnValues.new
|
11
|
+
assert_nil values.next
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_keep_returning_nil
|
15
|
+
values = ReturnValues.new
|
16
|
+
values.next
|
17
|
+
assert_nil values.next
|
18
|
+
assert_nil values.next
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_return_evaluated_single_return_value
|
22
|
+
values = ReturnValues.new(SingleReturnValue.new('value'))
|
23
|
+
assert_equal 'value', values.next
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_keep_returning_evaluated_single_return_value
|
27
|
+
values = ReturnValues.new(SingleReturnValue.new('value'))
|
28
|
+
values.next
|
29
|
+
assert_equal 'value', values.next
|
30
|
+
assert_equal 'value', values.next
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_return_consecutive_evaluated_single_return_values
|
34
|
+
values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2'))
|
35
|
+
assert_equal 'value_1', values.next
|
36
|
+
assert_equal 'value_2', values.next
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_keep_returning_last_of_consecutive_evaluated_single_return_values
|
40
|
+
values = ReturnValues.new(SingleReturnValue.new('value_1'), SingleReturnValue.new('value_2'))
|
41
|
+
values.next
|
42
|
+
values.next
|
43
|
+
assert_equal 'value_2', values.next
|
44
|
+
assert_equal 'value_2', values.next
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_build_single_return_values_for_each_values
|
48
|
+
values = ReturnValues.build('value_1', 'value_2', 'value_3').values
|
49
|
+
assert_equal 'value_1', values[0].evaluate
|
50
|
+
assert_equal 'value_2', values[1].evaluate
|
51
|
+
assert_equal 'value_3', values[2].evaluate
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_combine_two_sets_of_return_values
|
55
|
+
values_1 = ReturnValues.build('value_1')
|
56
|
+
values_2 = ReturnValues.build('value_2a', 'value_2b')
|
57
|
+
values = (values_1 + values_2).values
|
58
|
+
assert_equal 'value_1', values[0].evaluate
|
59
|
+
assert_equal 'value_2a', values[1].evaluate
|
60
|
+
assert_equal 'value_2b', values[2].evaluate
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/sequence'
|
3
|
+
require 'mocha/expectation'
|
4
|
+
|
5
|
+
class SequenceTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
class FakeExpectation
|
10
|
+
|
11
|
+
attr_reader :ordering_constraints
|
12
|
+
|
13
|
+
def initialize(satisfied = false)
|
14
|
+
@satisfied = satisfied
|
15
|
+
@ordering_constraints = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_ordering_constraint(ordering_constraint)
|
19
|
+
@ordering_constraints << ordering_constraint
|
20
|
+
end
|
21
|
+
|
22
|
+
def satisfied?
|
23
|
+
@satisfied
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_be_satisfied_if_no_expectations_added
|
29
|
+
sequence = Sequence.new('name')
|
30
|
+
assert sequence.satisfied_to_index?(0)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_be_satisfied_if_one_unsatisfied_expectations_added_but_it_is_not_included_by_index
|
34
|
+
sequence = Sequence.new('name')
|
35
|
+
expectation = FakeExpectation.new(satisfied = false)
|
36
|
+
sequence.constrain_as_next_in_sequence(expectation)
|
37
|
+
assert sequence.satisfied_to_index?(0)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_not_be_satisfied_if_one_unsatisfied_expectations_added_and_it_is_included_by_index
|
41
|
+
sequence = Sequence.new('name')
|
42
|
+
expectation = FakeExpectation.new(satisfied = false)
|
43
|
+
sequence.constrain_as_next_in_sequence(expectation)
|
44
|
+
assert !sequence.satisfied_to_index?(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_be_satisfied_if_one_satisfied_expectations_added_and_it_is_included_by_index
|
48
|
+
sequence = Sequence.new('name')
|
49
|
+
expectation = FakeExpectation.new(satisfied = true)
|
50
|
+
sequence.constrain_as_next_in_sequence(expectation)
|
51
|
+
assert sequence.satisfied_to_index?(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_not_be_satisfied_if_one_satisfied_and_one_unsatisfied_expectation_added_and_both_are_included_by_index
|
55
|
+
sequence = Sequence.new('name')
|
56
|
+
expectation_one = FakeExpectation.new(satisfied = true)
|
57
|
+
expectation_two = FakeExpectation.new(satisfied = false)
|
58
|
+
sequence.constrain_as_next_in_sequence(expectation_one)
|
59
|
+
sequence.constrain_as_next_in_sequence(expectation_two)
|
60
|
+
assert !sequence.satisfied_to_index?(2)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_be_satisfied_if_two_satisfied_expectations_added_and_both_are_included_by_index
|
64
|
+
sequence = Sequence.new('name')
|
65
|
+
expectation_one = FakeExpectation.new(satisfied = true)
|
66
|
+
expectation_two = FakeExpectation.new(satisfied = true)
|
67
|
+
sequence.constrain_as_next_in_sequence(expectation_one)
|
68
|
+
sequence.constrain_as_next_in_sequence(expectation_two)
|
69
|
+
assert sequence.satisfied_to_index?(2)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_add_ordering_constraint_to_expectation
|
73
|
+
sequence = Sequence.new('name')
|
74
|
+
expectation = FakeExpectation.new
|
75
|
+
sequence.constrain_as_next_in_sequence(expectation)
|
76
|
+
assert_equal 1, expectation.ordering_constraints.length
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_not_allow_invocation_of_second_method_when_first_n_sequence_has_not_been_invoked
|
80
|
+
sequence = Sequence.new('name')
|
81
|
+
expectation_one = FakeExpectation.new(satisfied = false)
|
82
|
+
expectation_two = FakeExpectation.new(satisfied = false)
|
83
|
+
sequence.constrain_as_next_in_sequence(expectation_one)
|
84
|
+
sequence.constrain_as_next_in_sequence(expectation_two)
|
85
|
+
assert !expectation_two.ordering_constraints[0].allows_invocation_now?
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_allow_invocation_of_second_method_when_first_in_sequence_has_been_invoked
|
89
|
+
sequence = Sequence.new('name')
|
90
|
+
expectation_one = FakeExpectation.new(satisfied = true)
|
91
|
+
expectation_two = FakeExpectation.new(satisfied = false)
|
92
|
+
sequence.constrain_as_next_in_sequence(expectation_one)
|
93
|
+
sequence.constrain_as_next_in_sequence(expectation_two)
|
94
|
+
assert expectation_two.ordering_constraints[0].allows_invocation_now?
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_describe_ordering_constraint_as_being_part_of_named_sequence
|
98
|
+
sequence = Sequence.new('wibble')
|
99
|
+
expectation = FakeExpectation.new
|
100
|
+
sequence.constrain_as_next_in_sequence(expectation)
|
101
|
+
assert_equal "in sequence 'wibble'", expectation.ordering_constraints[0].mocha_inspect
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/single_return_value'
|
4
|
+
|
5
|
+
class SingleReturnValueTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_return_value
|
10
|
+
value = SingleReturnValue.new('value')
|
11
|
+
assert_equal 'value', value.evaluate
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/single_yield'
|
4
|
+
|
5
|
+
class SingleYieldTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_provide_parameters_for_single_yield_in_single_invocation
|
10
|
+
parameter_group = SingleYield.new(1, 2, 3)
|
11
|
+
parameter_groups = []
|
12
|
+
parameter_group.each do |parameters|
|
13
|
+
parameter_groups << parameters
|
14
|
+
end
|
15
|
+
assert_equal [[1, 2, 3]], parameter_groups
|
16
|
+
end
|
17
|
+
|
18
|
+
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
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/inspect'
|
3
|
+
|
4
|
+
class StringInspectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_should_replace_escaped_quotes_with_single_quote
|
7
|
+
string = "my_string"
|
8
|
+
assert_equal "'my_string'", string.mocha_inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/yield_parameters'
|
4
|
+
require 'mocha/no_yields'
|
5
|
+
require 'mocha/single_yield'
|
6
|
+
require 'mocha/multiple_yields'
|
7
|
+
|
8
|
+
class YieldParametersTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
include Mocha
|
11
|
+
|
12
|
+
def test_should_return_null_yield_parameter_group_by_default
|
13
|
+
yield_parameters = YieldParameters.new
|
14
|
+
assert yield_parameters.next_invocation.is_a?(NoYields)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_return_single_yield_parameter_group
|
18
|
+
yield_parameters = YieldParameters.new
|
19
|
+
yield_parameters.add(1, 2, 3)
|
20
|
+
parameter_group = yield_parameters.next_invocation
|
21
|
+
assert parameter_group.is_a?(SingleYield)
|
22
|
+
assert_equal [1, 2, 3], parameter_group.parameters
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_keep_returning_single_yield_parameter_group
|
26
|
+
yield_parameters = YieldParameters.new
|
27
|
+
yield_parameters.add(1, 2, 3)
|
28
|
+
yield_parameters.next_invocation
|
29
|
+
parameter_group = yield_parameters.next_invocation
|
30
|
+
assert parameter_group.is_a?(SingleYield)
|
31
|
+
assert_equal [1, 2, 3], parameter_group.parameters
|
32
|
+
parameter_group = yield_parameters.next_invocation
|
33
|
+
assert parameter_group.is_a?(SingleYield)
|
34
|
+
assert_equal [1, 2, 3], parameter_group.parameters
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_return_consecutive_single_yield_parameter_groups
|
38
|
+
yield_parameters = YieldParameters.new
|
39
|
+
yield_parameters.add(1, 2, 3)
|
40
|
+
yield_parameters.add(4, 5)
|
41
|
+
parameter_group = yield_parameters.next_invocation
|
42
|
+
assert parameter_group.is_a?(SingleYield)
|
43
|
+
assert_equal [1, 2, 3], parameter_group.parameters
|
44
|
+
parameter_group = yield_parameters.next_invocation
|
45
|
+
assert parameter_group.is_a?(SingleYield)
|
46
|
+
assert_equal [4, 5], parameter_group.parameters
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_return_multiple_yield_parameter_group
|
50
|
+
yield_parameters = YieldParameters.new
|
51
|
+
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
52
|
+
parameter_group = yield_parameters.next_invocation
|
53
|
+
assert parameter_group.is_a?(MultipleYields)
|
54
|
+
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_keep_returning_multiple_yield_parameter_group
|
58
|
+
yield_parameters = YieldParameters.new
|
59
|
+
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
60
|
+
yield_parameters.next_invocation
|
61
|
+
parameter_group = yield_parameters.next_invocation
|
62
|
+
assert parameter_group.is_a?(MultipleYields)
|
63
|
+
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
64
|
+
parameter_group = yield_parameters.next_invocation
|
65
|
+
assert parameter_group.is_a?(MultipleYields)
|
66
|
+
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_return_consecutive_multiple_yield_parameter_groups
|
70
|
+
yield_parameters = YieldParameters.new
|
71
|
+
yield_parameters.multiple_add([1, 2, 3], [4, 5])
|
72
|
+
yield_parameters.multiple_add([6, 7], [8, 9, 0])
|
73
|
+
parameter_group = yield_parameters.next_invocation
|
74
|
+
assert parameter_group.is_a?(MultipleYields)
|
75
|
+
assert_equal [[1, 2, 3], [4, 5]], parameter_group.parameter_groups
|
76
|
+
parameter_group = yield_parameters.next_invocation
|
77
|
+
assert parameter_group.is_a?(MultipleYields)
|
78
|
+
assert_equal [[6, 7], [8, 9, 0]], parameter_group.parameter_groups
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_return_consecutive_single_and_multiple_yield_parameter_groups
|
82
|
+
yield_parameters = YieldParameters.new
|
83
|
+
yield_parameters.add(1, 2, 3)
|
84
|
+
yield_parameters.multiple_add([4, 5, 6], [7, 8])
|
85
|
+
parameter_group = yield_parameters.next_invocation
|
86
|
+
assert parameter_group.is_a?(SingleYield)
|
87
|
+
assert_equal [1, 2, 3], parameter_group.parameters
|
88
|
+
parameter_group = yield_parameters.next_invocation
|
89
|
+
assert parameter_group.is_a?(MultipleYields)
|
90
|
+
assert_equal [[4, 5, 6], [7, 8]], parameter_group.parameter_groups
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|