rspec 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +125 -9
- data/EXAMPLES.rd +50 -27
- data/README +14 -1
- data/Rakefile +95 -42
- data/UPGRADE +31 -0
- data/bin/spec +0 -1
- data/bin/spec_translator +6 -0
- data/examples/auto_spec_description_example.rb +19 -0
- data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
- data/examples/behave_as_example.rb +45 -0
- data/examples/custom_expectation_matchers.rb +13 -12
- data/examples/dynamic_spec.rb +2 -2
- data/examples/file_accessor_spec.rb +2 -2
- data/examples/greeter_spec.rb +3 -3
- data/examples/helper_method_example.rb +2 -2
- data/examples/io_processor_spec.rb +4 -4
- data/examples/legacy_spec.rb +10 -0
- data/examples/mocking_example.rb +5 -5
- data/examples/multi_threaded_behaviour_runner.rb +25 -0
- data/examples/partial_mock_example.rb +4 -4
- data/examples/predicate_example.rb +4 -4
- data/examples/priority.txt +1 -0
- data/examples/shared_behaviours_example.rb +31 -0
- data/examples/stack_spec.rb +52 -69
- data/examples/stubbing_example.rb +10 -10
- data/examples/test_case_adapter_example.rb +26 -0
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +9 -4
- data/lib/spec/dsl.rb +10 -0
- data/lib/spec/dsl/behaviour.rb +189 -0
- data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
- data/lib/spec/dsl/behaviour_eval.rb +170 -0
- data/lib/spec/dsl/behaviour_factory.rb +32 -0
- data/lib/spec/dsl/composite_proc_builder.rb +28 -0
- data/lib/spec/dsl/configuration.rb +38 -0
- data/lib/spec/dsl/description.rb +34 -0
- data/lib/spec/dsl/example.rb +114 -0
- data/lib/spec/dsl/example_matcher.rb +28 -0
- data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
- data/lib/spec/expectations.rb +0 -3
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/extensions/object.rb +10 -53
- data/lib/spec/expectations/handler.rb +14 -18
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/object.rb +6 -0
- data/lib/spec/matchers.rb +19 -21
- data/lib/spec/matchers/be.rb +40 -11
- data/lib/spec/matchers/be_close.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +52 -0
- data/lib/spec/matchers/respond_to.rb +21 -11
- data/lib/spec/mocks.rb +5 -28
- data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
- data/lib/spec/mocks/argument_expectation.rb +7 -4
- data/lib/spec/mocks/methods.rb +11 -16
- data/lib/spec/mocks/mock.rb +6 -3
- data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +30 -0
- data/lib/spec/rake/spectask.rb +23 -21
- data/lib/spec/rake/verify_rcov.rb +1 -0
- data/lib/spec/runner.rb +88 -35
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +102 -0
- data/lib/spec/runner/command_line.rb +5 -17
- data/lib/spec/runner/drb_command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +22 -9
- data/lib/spec/runner/formatter.rb +4 -0
- data/lib/spec/runner/formatter/base_formatter.rb +63 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
- data/lib/spec/runner/formatter/html_formatter.rb +74 -29
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
- data/lib/spec/runner/heckle_runner.rb +8 -7
- data/lib/spec/runner/option_parser.rb +136 -55
- data/lib/spec/runner/options.rb +26 -0
- data/lib/spec/runner/reporter.rb +38 -31
- data/lib/spec/runner/spec_parser.rb +22 -13
- data/lib/spec/test_case_adapter.rb +10 -0
- data/lib/spec/translator.rb +103 -86
- data/lib/spec/version.rb +7 -15
- data/plugins/mock_frameworks/flexmock.rb +27 -0
- data/plugins/mock_frameworks/mocha.rb +21 -0
- data/plugins/mock_frameworks/rspec.rb +18 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_spec.rb +508 -0
- data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
- data/spec/spec/dsl/configuration_spec.rb +43 -0
- data/spec/spec/dsl/description_spec.rb +51 -0
- data/spec/spec/dsl/example_class_spec.rb +24 -0
- data/spec/spec/dsl/example_instance_spec.rb +140 -0
- data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
- data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
- data/spec/spec/expectations/differs/default_spec.rb +12 -12
- data/spec/spec/expectations/extensions/object_spec.rb +10 -10
- data/spec/spec/expectations/fail_with_spec.rb +20 -20
- data/spec/spec/matchers/be_close_spec.rb +37 -31
- data/spec/spec/matchers/be_spec.rb +50 -41
- data/spec/spec/matchers/change_spec.rb +54 -54
- data/spec/spec/matchers/description_generation_spec.rb +43 -31
- data/spec/spec/matchers/eql_spec.rb +24 -37
- data/spec/spec/matchers/equal_spec.rb +24 -37
- data/spec/spec/matchers/exist_spec.rb +48 -0
- data/spec/spec/matchers/handler_spec.rb +36 -23
- data/spec/spec/matchers/has_spec.rb +8 -8
- data/spec/spec/matchers/have_spec.rb +38 -38
- data/spec/spec/matchers/include_spec.rb +6 -6
- data/spec/spec/matchers/match_spec.rb +8 -8
- data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
- data/spec/spec/matchers/raise_error_spec.rb +34 -34
- data/spec/spec/matchers/respond_to_spec.rb +32 -8
- data/spec/spec/matchers/satisfy_spec.rb +6 -6
- data/spec/spec/matchers/should_===_spec.rb +38 -0
- data/spec/spec/matchers/should_==_spec.rb +37 -0
- data/spec/spec/matchers/should_=~_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
- data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
- data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/spec/mocks/at_least_spec.rb +30 -30
- data/spec/spec/mocks/at_most_spec.rb +53 -57
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
- data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +111 -141
- data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
- data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
- data/spec/spec/mocks/once_counts_spec.rb +32 -35
- data/spec/spec/mocks/options_hash_spec.rb +12 -10
- data/spec/spec/mocks/partial_mock_spec.rb +15 -15
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
- data/spec/spec/mocks/precise_counts_spec.rb +28 -32
- data/spec/spec/mocks/record_messages_spec.rb +10 -10
- data/spec/spec/mocks/stub_spec.rb +45 -45
- data/spec/spec/mocks/twice_counts_spec.rb +21 -21
- data/spec/spec/package/bin_spec_spec.rb +12 -0
- data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
- data/spec/spec/runner/command_line_spec.rb +8 -8
- data/spec/spec/runner/context_matching_spec.rb +14 -15
- data/spec/spec/runner/drb_command_line_spec.rb +12 -12
- data/spec/spec/runner/execution_context_spec.rb +8 -29
- data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/heckle_runner_spec.rb +21 -21
- data/spec/spec/runner/heckler_spec.rb +5 -5
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
- data/spec/spec/runner/object_ext_spec.rb +3 -3
- data/spec/spec/runner/option_parser_spec.rb +171 -102
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
- data/spec/spec/runner/reporter_spec.rb +106 -97
- data/spec/spec/runner/spec_matcher_spec.rb +46 -51
- data/spec/spec/runner/spec_parser_spec.rb +72 -16
- data/spec/spec/spec_classes.rb +12 -3
- data/spec/spec/translator_spec.rb +165 -36
- metadata +66 -76
- data/RELEASE-PLAN +0 -117
- data/examples/auto_spec_name_generation_example.rb +0 -18
- data/lib/spec/callback.rb +0 -11
- data/lib/spec/callback/callback_container.rb +0 -60
- data/lib/spec/callback/extensions/module.rb +0 -24
- data/lib/spec/callback/extensions/object.rb +0 -37
- data/lib/spec/deprecated.rb +0 -3
- data/lib/spec/expectations/extensions/proc.rb +0 -57
- data/lib/spec/expectations/should.rb +0 -5
- data/lib/spec/expectations/should/base.rb +0 -64
- data/lib/spec/expectations/should/change.rb +0 -69
- data/lib/spec/expectations/should/have.rb +0 -128
- data/lib/spec/expectations/should/not.rb +0 -74
- data/lib/spec/expectations/should/should.rb +0 -81
- data/lib/spec/expectations/sugar.rb +0 -47
- data/lib/spec/runner/context.rb +0 -154
- data/lib/spec/runner/context_eval.rb +0 -142
- data/lib/spec/runner/context_runner.rb +0 -55
- data/lib/spec/runner/execution_context.rb +0 -17
- data/lib/spec/runner/spec_matcher.rb +0 -25
- data/lib/spec/runner/specification.rb +0 -114
- data/spec/spec/callback/callback_container_spec.rb +0 -27
- data/spec/spec/callback/module_spec.rb +0 -37
- data/spec/spec/callback/object_spec.rb +0 -90
- data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
- data/spec/spec/expectations/should/should_==_spec.rb +0 -19
- data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
- data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
- data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
- data/spec/spec/expectations/should/should_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
- data/spec/spec/expectations/should/should_change_spec.rb +0 -184
- data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
- data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
- data/spec/spec/expectations/should/should_have_spec.rb +0 -64
- data/spec/spec/expectations/should/should_include_spec.rb +0 -59
- data/spec/spec/expectations/should/should_match_spec.rb +0 -25
- data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
- data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
- data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
- data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
- data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
- data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
- data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
- data/spec/spec/runner/context_runner_spec.rb +0 -100
- data/spec/spec/runner/context_spec.rb +0 -405
- data/spec/spec/runner/kernel_ext_spec.rb +0 -16
- data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
- data/spec/spec/runner/specification_class_spec.rb +0 -72
- data/spec/spec/runner/specification_instance_spec.rb +0 -160
- data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
@@ -2,340 +2,310 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
2
|
|
3
3
|
module Spec
|
4
4
|
module Mocks
|
5
|
-
|
5
|
+
describe "a Mock expectation" do
|
6
6
|
|
7
|
-
|
8
|
-
@mock =
|
7
|
+
before do
|
8
|
+
@mock = mock("test mock")
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
after do
|
12
|
+
@mock.rspec_reset
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should report line number of expectation of unreceived message" do
|
12
16
|
@mock.should_receive(:wont_happen).with("x", 3)
|
13
17
|
#NOTE - this test is quite ticklish because it specifies that
|
14
18
|
#the above statement appears on line 12 of this file.
|
15
19
|
|
16
20
|
begin
|
17
|
-
@mock.
|
21
|
+
@mock.rspec_verify
|
18
22
|
violated
|
19
23
|
rescue MockExpectationError => e
|
20
|
-
e.backtrace[0].
|
24
|
+
e.backtrace[0].should match(/mock_spec\.rb:16/)
|
21
25
|
end
|
22
26
|
|
23
27
|
end
|
24
28
|
|
25
|
-
|
29
|
+
it "should pass when not receiving message specified as not to be received" do
|
26
30
|
@mock.should_not_receive(:not_expected)
|
27
|
-
@mock.
|
31
|
+
@mock.rspec_verify
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
it "should pass when receiving message specified as not to be received with different args" do
|
31
35
|
@mock.should_not_receive(:message).with("unwanted text")
|
32
36
|
@mock.should_receive(:message).with("other text")
|
33
37
|
@mock.message "other text"
|
34
|
-
@mock.
|
38
|
+
@mock.rspec_verify
|
35
39
|
end
|
36
40
|
|
37
|
-
|
41
|
+
it "should fail when receiving message specified as not to be received" do
|
38
42
|
@mock.should_not_receive(:not_expected)
|
39
43
|
@mock.not_expected
|
40
44
|
begin
|
41
|
-
@mock.
|
45
|
+
@mock.rspec_verify
|
42
46
|
violated
|
43
47
|
rescue MockExpectationError => e
|
44
|
-
e.message.
|
48
|
+
e.message.should == "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once"
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
48
|
-
|
52
|
+
it "should fail when receiving message specified as not to be received with args" do
|
49
53
|
@mock.should_not_receive(:not_expected).with("unexpected text")
|
50
54
|
@mock.not_expected("unexpected text")
|
51
55
|
begin
|
52
|
-
@mock.
|
56
|
+
@mock.rspec_verify
|
53
57
|
violated
|
54
58
|
rescue MockExpectationError => e
|
55
|
-
e.message.
|
59
|
+
e.message.should == "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once"
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
59
|
-
|
63
|
+
it "should pass when receiving message specified as not to be received with wrong args" do
|
60
64
|
@mock.should_not_receive(:not_expected).with("unexpected text")
|
61
65
|
@mock.not_expected "really unexpected text"
|
62
|
-
@mock.
|
66
|
+
@mock.rspec_verify
|
63
67
|
end
|
64
68
|
|
65
|
-
|
69
|
+
it "should allow block to calculate return values" do
|
66
70
|
@mock.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
|
67
|
-
@mock.something("a","b","c").
|
68
|
-
@mock.
|
71
|
+
@mock.something("a","b","c").should == "cba"
|
72
|
+
@mock.rspec_verify
|
69
73
|
end
|
70
74
|
|
71
|
-
|
75
|
+
it "should allow parameter as return value" do
|
72
76
|
@mock.should_receive(:something).with("a","b","c").and_return("booh")
|
73
|
-
@mock.something("a","b","c").
|
74
|
-
@mock.
|
77
|
+
@mock.something("a","b","c").should == "booh"
|
78
|
+
@mock.rspec_verify
|
75
79
|
end
|
76
80
|
|
77
|
-
|
81
|
+
it "should return nil if no return value set" do
|
78
82
|
@mock.should_receive(:something).with("a","b","c")
|
79
|
-
@mock.something("a","b","c").should
|
80
|
-
@mock.
|
83
|
+
@mock.something("a","b","c").should be_nil
|
84
|
+
@mock.rspec_verify
|
81
85
|
end
|
82
86
|
|
83
|
-
|
87
|
+
it "should raise exception if args dont match when method called" do
|
84
88
|
@mock.should_receive(:something).with("a","b","c").and_return("booh")
|
85
89
|
begin
|
86
90
|
@mock.something("a","d","c")
|
87
91
|
violated
|
88
92
|
rescue MockExpectationError => e
|
89
|
-
e.message.
|
93
|
+
e.message.should == "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")"
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
93
|
-
|
97
|
+
it "should fail if unexpected method called" do
|
94
98
|
begin
|
95
99
|
@mock.something("a","b","c")
|
96
100
|
violated
|
97
101
|
rescue MockExpectationError => e
|
98
|
-
e.message.
|
102
|
+
e.message.should == "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")"
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
102
|
-
|
106
|
+
it "should use block for expectation if provided" do
|
103
107
|
@mock.should_receive(:something) do | a, b |
|
104
|
-
a.
|
105
|
-
b.
|
108
|
+
a.should == "a"
|
109
|
+
b.should == "b"
|
106
110
|
"booh"
|
107
111
|
end
|
108
|
-
@mock.something("a", "b").
|
109
|
-
@mock.
|
112
|
+
@mock.something("a", "b").should == "booh"
|
113
|
+
@mock.rspec_verify
|
110
114
|
end
|
111
115
|
|
112
|
-
|
113
|
-
@mock.should_receive(:something) {| bool | bool.should
|
116
|
+
it "should fail if expectation block fails" do
|
117
|
+
@mock.should_receive(:something) {| bool | bool.should be_true}
|
114
118
|
begin
|
115
119
|
@mock.something false
|
116
120
|
rescue MockExpectationError => e
|
117
|
-
e.message.
|
121
|
+
e.message.should match(/Mock 'test mock' received :something but passed block failed with: expected true, got false/)
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
121
|
-
|
125
|
+
it "should fail when method defined as never is received" do
|
122
126
|
@mock.should_receive(:not_expected).never
|
123
127
|
begin
|
124
128
|
@mock.not_expected
|
125
129
|
rescue MockExpectationError => e
|
126
|
-
e.message.
|
130
|
+
e.message.should == "Mock 'test mock' expected :not_expected 0 times, but received it 1 times"
|
127
131
|
end
|
128
132
|
end
|
129
133
|
|
130
|
-
|
134
|
+
it "should raise when told to" do
|
131
135
|
@mock.should_receive(:something).and_raise(RuntimeError)
|
132
136
|
lambda do
|
133
137
|
@mock.something
|
134
|
-
end.
|
138
|
+
end.should raise_error(RuntimeError)
|
135
139
|
end
|
136
140
|
|
137
|
-
|
141
|
+
it "should raise passed an Exception instance" do
|
138
142
|
error = RuntimeError.new("error message")
|
139
143
|
@mock.should_receive(:something).and_raise(error)
|
140
144
|
begin
|
141
145
|
@mock.something
|
142
146
|
rescue RuntimeError => e
|
143
|
-
e.message.
|
147
|
+
e.message.should eql("error message")
|
144
148
|
end
|
145
149
|
end
|
146
150
|
|
147
|
-
|
151
|
+
it "should raise RuntimeError with passed message" do
|
148
152
|
@mock.should_receive(:something).and_raise("error message")
|
149
153
|
begin
|
150
154
|
@mock.something
|
151
155
|
rescue RuntimeError => e
|
152
|
-
e.message.
|
156
|
+
e.message.should eql("error message")
|
153
157
|
end
|
154
158
|
end
|
155
159
|
|
156
|
-
|
160
|
+
it "should not raise when told to if args dont match" do
|
157
161
|
@mock.should_receive(:something).with(2).and_raise(RuntimeError)
|
158
162
|
lambda do
|
159
163
|
@mock.something 1
|
160
|
-
end.
|
164
|
+
end.should raise_error(MockExpectationError)
|
161
165
|
end
|
162
166
|
|
163
|
-
|
167
|
+
it "should throw when told to" do
|
164
168
|
@mock.should_receive(:something).and_throw(:blech)
|
165
169
|
lambda do
|
166
170
|
@mock.something
|
167
|
-
end.
|
171
|
+
end.should throw_symbol(:blech)
|
168
172
|
end
|
169
173
|
|
170
|
-
|
174
|
+
it "should raise when explicit return and block constrained" do
|
171
175
|
lambda do
|
172
176
|
@mock.should_receive(:fruit) do |colour|
|
173
177
|
:strawberry
|
174
178
|
end.and_return :apple
|
175
|
-
end.
|
179
|
+
end.should raise_error(AmbiguousReturnError)
|
176
180
|
end
|
177
181
|
|
178
|
-
|
182
|
+
it "should ignore args on any args" do
|
179
183
|
@mock.should_receive(:something).at_least(:once).with(:any_args)
|
180
184
|
@mock.something
|
181
185
|
@mock.something 1
|
182
186
|
@mock.something "a", 2
|
183
187
|
@mock.something [], {}, "joe", 7
|
184
|
-
@mock.
|
188
|
+
@mock.rspec_verify
|
185
189
|
end
|
186
190
|
|
187
|
-
|
191
|
+
it "should fail on no args if any args received" do
|
188
192
|
@mock.should_receive(:something).with(:no_args)
|
189
193
|
begin
|
190
194
|
@mock.something 1
|
191
195
|
rescue MockExpectationError => e
|
192
|
-
e.message.
|
196
|
+
e.message.should == "Mock 'test mock' expected :something with (no args) but received it with (1)"
|
193
197
|
end
|
194
198
|
end
|
195
199
|
|
196
|
-
|
200
|
+
it "should fail when args are expected but none are received" do
|
197
201
|
@mock.should_receive(:something).with(1)
|
198
202
|
begin
|
199
203
|
@mock.something
|
200
204
|
rescue MockExpectationError => e
|
201
|
-
e.message.
|
205
|
+
e.message.should == "Mock 'test mock' expected :something with (1) but received it with (no args)"
|
202
206
|
end
|
203
207
|
end
|
204
208
|
|
205
|
-
|
209
|
+
it "should yield 0 args to blocks that take a variable number of arguments" do
|
206
210
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield
|
207
211
|
a = nil
|
208
212
|
@mock.yield_back {|*a|}
|
209
|
-
a.
|
210
|
-
@mock.
|
213
|
+
a.should == []
|
214
|
+
@mock.rspec_verify
|
211
215
|
end
|
212
216
|
|
213
|
-
|
217
|
+
it "should yield one arg to blocks that take a variable number of arguments" do
|
214
218
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
|
215
219
|
a = nil
|
216
220
|
@mock.yield_back {|*a|}
|
217
|
-
a.
|
218
|
-
@mock.
|
221
|
+
a.should == [99]
|
222
|
+
@mock.rspec_verify
|
219
223
|
end
|
220
224
|
|
221
|
-
|
225
|
+
it "should yield many args to blocks that take a variable number of arguments" do
|
222
226
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield(99, 27, "go")
|
223
227
|
a = nil
|
224
228
|
@mock.yield_back {|*a|}
|
225
|
-
a.
|
226
|
-
@mock.
|
229
|
+
a.should == [99, 27, "go"]
|
230
|
+
@mock.rspec_verify
|
227
231
|
end
|
228
232
|
|
229
|
-
|
233
|
+
it "should yield single value" do
|
230
234
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
|
231
235
|
a = nil
|
232
236
|
@mock.yield_back {|a|}
|
233
|
-
a.
|
234
|
-
@mock.
|
237
|
+
a.should == 99
|
238
|
+
@mock.rspec_verify
|
235
239
|
end
|
236
240
|
|
237
|
-
|
241
|
+
it "should yield two values" do
|
238
242
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
239
243
|
a, b = nil
|
240
244
|
@mock.yield_back {|a,b|}
|
241
|
-
a.
|
242
|
-
b.
|
243
|
-
@mock.
|
245
|
+
a.should == 'wha'
|
246
|
+
b.should == 'zup'
|
247
|
+
@mock.rspec_verify
|
244
248
|
end
|
245
249
|
|
246
|
-
|
250
|
+
it "should fail when calling yielding method with wrong arity" do
|
247
251
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
248
252
|
begin
|
249
253
|
@mock.yield_back {|a|}
|
250
254
|
rescue MockExpectationError => e
|
251
|
-
e.message.
|
255
|
+
e.message.should == "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1"
|
252
256
|
end
|
253
257
|
end
|
254
258
|
|
255
|
-
|
259
|
+
it "should fail when calling yielding method without block" do
|
256
260
|
@mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
|
257
261
|
begin
|
258
262
|
@mock.yield_back
|
259
263
|
rescue MockExpectationError => e
|
260
|
-
e.message.
|
264
|
+
e.message.should == "Mock 'test mock' asked to yield |\"wha\", \"zup\"| but no block was passed"
|
261
265
|
end
|
262
266
|
end
|
263
267
|
|
264
|
-
|
268
|
+
it "should be able to mock send" do
|
265
269
|
@mock.should_receive(:send).with(:any_args)
|
266
270
|
@mock.send 'hi'
|
267
|
-
@mock.
|
271
|
+
@mock.rspec_verify
|
268
272
|
end
|
269
273
|
|
270
|
-
|
274
|
+
it "should be able to raise from method calling yielding mock" do
|
271
275
|
@mock.should_receive(:yield_me).and_yield 44
|
272
276
|
|
273
277
|
lambda do
|
274
278
|
@mock.yield_me do |x|
|
275
279
|
raise "Bang"
|
276
280
|
end
|
277
|
-
end.
|
278
|
-
|
279
|
-
@mock.__verify
|
280
|
-
end
|
281
|
+
end.should raise_error(StandardError)
|
281
282
|
|
282
|
-
|
283
|
-
@mock.should_receive(:foobar)
|
284
|
-
@mock.foobar
|
285
|
-
@mock.__verify
|
286
|
-
begin
|
287
|
-
@mock.foobar
|
288
|
-
rescue MockExpectationError => e
|
289
|
-
e.message.should_eql "Mock 'test mock' received unexpected message :foobar with (no args)"
|
290
|
-
end
|
283
|
+
@mock.rspec_verify
|
291
284
|
end
|
292
285
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
end
|
304
|
-
|
305
|
-
specify "should verify if auto verify not set explicitly" do
|
306
|
-
reporter = Spec::Mocks::Mock.new("reporter", :null_object => true)
|
307
|
-
reporter.should_receive(:spec_finished) do |name, error, location|
|
308
|
-
error.to_s.should_match /expected :abcde with \(any args\) once, but received it 0 times/
|
309
|
-
end
|
310
|
-
Runner::Specification.new("spec") do
|
311
|
-
mock = Spec::Mocks::Mock.new("mock")
|
312
|
-
mock.should_receive(:abcde)
|
313
|
-
end.run(reporter, nil, nil, nil, nil)
|
314
|
-
reporter.__verify
|
315
|
-
end
|
316
|
-
|
317
|
-
specify "should not verify if auto verify is set to false" do
|
318
|
-
reporter = Spec::Mocks::Mock.new("reporter", :null_object => true)
|
319
|
-
reporter.should_receive(:spec_finished) do |name, error, location|
|
320
|
-
error.should_be_nil
|
321
|
-
end
|
322
|
-
Runner::Specification.new("spec") do
|
323
|
-
mock = Spec::Mocks::Mock.new("mock", :auto_verify => false)
|
324
|
-
mock.should_receive(:abcde)
|
325
|
-
end.run(reporter, nil, nil, nil, nil)
|
326
|
-
reporter.__verify
|
327
|
-
end
|
286
|
+
# TODO - this is failing, but not if you run the file w/ --reverse - weird!!!!!!
|
287
|
+
# specify "should clear expectations after verify" do
|
288
|
+
# @mock.should_receive(:foobar)
|
289
|
+
# @mock.foobar
|
290
|
+
# @mock.rspec_verify
|
291
|
+
# begin
|
292
|
+
# @mock.foobar
|
293
|
+
# rescue MockExpectationError => e
|
294
|
+
# e.message.should == "Mock 'test mock' received unexpected message :foobar with (no args)"
|
295
|
+
# end
|
296
|
+
# end
|
328
297
|
|
329
|
-
|
298
|
+
it "should restore objects to their original state on rspec_reset" do
|
330
299
|
mock = mock("this is a mock")
|
331
300
|
mock.should_receive(:blah)
|
332
|
-
mock.
|
301
|
+
mock.rspec_reset
|
302
|
+
mock.rspec_verify #should throw if reset didn't work
|
333
303
|
end
|
334
304
|
|
335
305
|
end
|
336
306
|
|
337
|
-
|
338
|
-
|
307
|
+
describe "a mock message receiving a block" do
|
308
|
+
before(:each) do
|
339
309
|
@mock = mock("mock")
|
340
310
|
@calls = 0
|
341
311
|
end
|
@@ -344,7 +314,7 @@ module Spec
|
|
344
314
|
@calls = @calls + 1
|
345
315
|
end
|
346
316
|
|
347
|
-
|
317
|
+
it "should call the block after #should_receive" do
|
348
318
|
@mock.should_receive(:foo) { add_call }
|
349
319
|
|
350
320
|
@mock.foo
|
@@ -352,7 +322,7 @@ module Spec
|
|
352
322
|
@calls.should == 1
|
353
323
|
end
|
354
324
|
|
355
|
-
|
325
|
+
it "should call the block after #once" do
|
356
326
|
@mock.should_receive(:foo).once { add_call }
|
357
327
|
|
358
328
|
@mock.foo
|
@@ -360,7 +330,7 @@ module Spec
|
|
360
330
|
@calls.should == 1
|
361
331
|
end
|
362
332
|
|
363
|
-
|
333
|
+
it "should call the block after #twice" do
|
364
334
|
@mock.should_receive(:foo).twice { add_call }
|
365
335
|
|
366
336
|
@mock.foo
|
@@ -369,7 +339,7 @@ module Spec
|
|
369
339
|
@calls.should == 2
|
370
340
|
end
|
371
341
|
|
372
|
-
|
342
|
+
it "should call the block after #times" do
|
373
343
|
@mock.should_receive(:foo).exactly(10).times { add_call }
|
374
344
|
|
375
345
|
(1..10).each { @mock.foo }
|
@@ -377,7 +347,7 @@ module Spec
|
|
377
347
|
@calls.should == 10
|
378
348
|
end
|
379
349
|
|
380
|
-
|
350
|
+
it "should call the block after #any_number_of_times" do
|
381
351
|
@mock.should_receive(:foo).any_number_of_times { add_call }
|
382
352
|
|
383
353
|
(1..7).each { @mock.foo }
|
@@ -385,7 +355,7 @@ module Spec
|
|
385
355
|
@calls.should == 7
|
386
356
|
end
|
387
357
|
|
388
|
-
|
358
|
+
it "should call the block after #with" do
|
389
359
|
@mock.should_receive(:foo).with(:arg) { add_call }
|
390
360
|
|
391
361
|
@mock.foo(:arg)
|
@@ -393,7 +363,7 @@ module Spec
|
|
393
363
|
@calls.should == 1
|
394
364
|
end
|
395
365
|
|
396
|
-
|
366
|
+
it "should call the block after #ordered" do
|
397
367
|
@mock.should_receive(:foo).ordered { add_call }
|
398
368
|
@mock.should_receive(:bar).ordered { add_call }
|
399
369
|
|