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
@@ -1,58 +1,58 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe "should be_predicate" do
|
4
|
+
it "should pass when actual returns true for :predicate?" do
|
5
5
|
actual = stub("actual", :happy? => true)
|
6
6
|
actual.should be_happy
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "should pass when actual returns true for :predicates? (present tense)" do
|
10
10
|
actual = stub("actual", :exists? => true)
|
11
11
|
actual.should be_exist
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
it "should fail when actual returns false for :predicate?" do
|
15
15
|
actual = stub("actual", :happy? => false)
|
16
16
|
lambda {
|
17
17
|
actual.should be_happy
|
18
18
|
}.should fail_with("expected happy? to return true, got false")
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
it "should fail when actual does not respond to :predicate?" do
|
22
22
|
lambda {
|
23
23
|
Object.new.should be_happy
|
24
24
|
}.should raise_error(NameError)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
describe "should_not be_predicate" do
|
29
|
+
it "should pass when actual returns false for :sym?" do
|
30
30
|
actual = stub("actual", :happy? => false)
|
31
31
|
actual.should_not be_happy
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
it "should fail when actual returns true for :sym?" do
|
35
35
|
actual = stub("actual", :happy? => true)
|
36
36
|
lambda {
|
37
37
|
actual.should_not be_happy
|
38
38
|
}.should fail_with("expected happy? to return false, got true")
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it "should fail when actual does not respond to :sym?" do
|
42
42
|
lambda {
|
43
43
|
Object.new.should_not be_happy
|
44
44
|
}.should raise_error(NameError)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
describe "should be_predicate(*args)" do
|
49
|
+
it "should pass when actual returns true for :predicate?(*args)" do
|
50
50
|
actual = mock("actual")
|
51
51
|
actual.should_receive(:older_than?).with(3).and_return(true)
|
52
52
|
actual.should be_older_than(3)
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
it "should fail when actual returns false for :predicate?(*args)" do
|
56
56
|
actual = mock("actual")
|
57
57
|
actual.should_receive(:older_than?).with(3).and_return(false)
|
58
58
|
lambda {
|
@@ -60,21 +60,21 @@ context "should be_predicate(*args)" do
|
|
60
60
|
}.should fail_with("expected older_than?(3) to return true, got false")
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
it "should fail when actual does not respond to :predicate?" do
|
64
64
|
lambda {
|
65
65
|
Object.new.should be_older_than(3)
|
66
66
|
}.should raise_error(NameError)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
describe "should_not be_predicate(*args)" do
|
71
|
+
it "should pass when actual returns false for :predicate?(*args)" do
|
72
72
|
actual = mock("actual")
|
73
73
|
actual.should_receive(:older_than?).with(3).and_return(false)
|
74
74
|
actual.should_not be_older_than(3)
|
75
75
|
end
|
76
76
|
|
77
|
-
|
77
|
+
it "should fail when actual returns true for :predicate?(*args)" do
|
78
78
|
actual = mock("actual")
|
79
79
|
actual.should_receive(:older_than?).with(3).and_return(true)
|
80
80
|
lambda {
|
@@ -82,101 +82,110 @@ context "should_not be_predicate(*args)" do
|
|
82
82
|
}.should fail_with("expected older_than?(3) to return false, got true")
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
it "should fail when actual does not respond to :predicate?" do
|
86
86
|
lambda {
|
87
87
|
Object.new.should_not be_older_than(3)
|
88
88
|
}.should raise_error(NameError)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
describe "should be_true" do
|
93
|
+
it "should pass when actual equal(true)" do
|
94
94
|
true.should be_true
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
it "should fail when actual equal(false)" do
|
98
98
|
lambda {
|
99
99
|
false.should be_true
|
100
100
|
}.should fail_with("expected true, got false")
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
describe "should be_false" do
|
105
|
+
it "should pass when actual equal(false)" do
|
106
106
|
false.should be_false
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
it "should fail when actual equal(true)" do
|
110
110
|
lambda {
|
111
111
|
true.should be_false
|
112
112
|
}.should fail_with("expected false, got true")
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
|
117
|
-
|
116
|
+
describe "should be_nil" do
|
117
|
+
it "should pass when actual is nil" do
|
118
118
|
nil.should be_nil
|
119
119
|
end
|
120
120
|
|
121
|
-
|
121
|
+
it "should fail when actual is not nil" do
|
122
122
|
lambda {
|
123
123
|
:not_nil.should be_nil
|
124
124
|
}.should fail_with("expected nil, got :not_nil")
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
|
129
|
-
|
128
|
+
describe "should_not be_nil" do
|
129
|
+
it "should pass when actual is not nil" do
|
130
130
|
:not_nil.should_not be_nil
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
it "should fail when actual is nil" do
|
134
134
|
lambda {
|
135
135
|
nil.should_not be_nil
|
136
136
|
}.should fail_with("expected not nil, got nil")
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
|
141
|
-
|
140
|
+
describe "should be <" do
|
141
|
+
it "should pass when < operator returns true" do
|
142
142
|
3.should be < 4
|
143
143
|
end
|
144
144
|
|
145
|
-
|
145
|
+
it "should fail when < operator returns false" do
|
146
146
|
lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
describe "should be <=" do
|
151
|
+
it "should pass when <= operator returns true" do
|
152
152
|
3.should be <= 4
|
153
153
|
4.should be <= 4
|
154
154
|
end
|
155
155
|
|
156
|
-
|
156
|
+
it "should fail when <= operator returns false" do
|
157
157
|
lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
|
162
|
-
|
161
|
+
describe "should be >=" do
|
162
|
+
it "should pass when >= operator returns true" do
|
163
163
|
4.should be >= 4
|
164
164
|
5.should be >= 4
|
165
165
|
end
|
166
166
|
|
167
|
-
|
167
|
+
it "should fail when >= operator returns false" do
|
168
168
|
lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
|
173
|
-
|
172
|
+
describe "should be >" do
|
173
|
+
it "should pass when > operator returns true" do
|
174
174
|
5.should be > 4
|
175
175
|
end
|
176
176
|
|
177
|
-
|
177
|
+
it "should fail when > operator returns false" do
|
178
178
|
lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
describe "should be(value)" do
|
183
|
+
it "should pass if actual.equal?(value)" do
|
184
|
+
5.should be(5)
|
185
|
+
end
|
186
|
+
it "should fail if !actual.equal?(value)" do
|
187
|
+
lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
182
191
|
|
@@ -5,228 +5,228 @@ class SomethingExpected
|
|
5
5
|
attr_accessor :some_value
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
describe "should change(actual, message)" do
|
9
|
+
before(:each) do
|
10
10
|
@instance = SomethingExpected.new
|
11
11
|
@instance.some_value = 5
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
it "should pass when actual is modified by the block" do
|
15
15
|
lambda {@instance.some_value = 6}.should change(@instance, :some_value)
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "should fail when actual is not modified by the block" do
|
19
19
|
lambda do
|
20
20
|
lambda {}.should change(@instance, :some_value)
|
21
21
|
end.should fail_with("some_value should have changed, but is still 5")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
describe "should_not change(actual, message)" do
|
26
|
+
before(:each) do
|
27
27
|
@instance = SomethingExpected.new
|
28
28
|
@instance.some_value = 5
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
it "should pass when actual is not modified by the block" do
|
32
32
|
lambda { }.should_not change(@instance, :some_value)
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
it "should fail when actual is not modified by the block" do
|
36
36
|
lambda do
|
37
37
|
lambda {@instance.some_value = 6}.should_not change(@instance, :some_value)
|
38
38
|
end.should fail_with("some_value should not have changed, but did change from 5 to 6")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
describe "should change { block }" do
|
43
|
+
before(:each) do
|
44
44
|
@instance = SomethingExpected.new
|
45
45
|
@instance.some_value = 5
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
it "should pass when actual is modified by the block" do
|
49
49
|
lambda {@instance.some_value = 6}.should change { @instance.some_value }
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "should fail when actual is not modified by the block" do
|
53
53
|
lambda do
|
54
54
|
lambda {}.should change{ @instance.some_value }
|
55
55
|
end.should fail_with("result should have changed, but is still 5")
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
it "should warn if passed a block using do/end" do
|
59
59
|
lambda do
|
60
60
|
lambda {}.should change do
|
61
61
|
end
|
62
|
-
end.
|
62
|
+
end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
describe "should_not change { block }" do
|
67
|
+
before(:each) do
|
68
68
|
@instance = SomethingExpected.new
|
69
69
|
@instance.some_value = 5
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
it "should pass when actual is modified by the block" do
|
73
73
|
lambda {}.should_not change{ @instance.some_value }
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
it "should fail when actual is not modified by the block" do
|
77
77
|
lambda do
|
78
78
|
lambda {@instance.some_value = 6}.should_not change { @instance.some_value }
|
79
79
|
end.should fail_with("result should not have changed, but did change from 5 to 6")
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
it "should warn if passed a block using do/end" do
|
83
83
|
lambda do
|
84
84
|
lambda {}.should_not change do
|
85
85
|
end
|
86
|
-
end.
|
86
|
+
end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
describe "should change(actual, message).by(expected)" do
|
91
|
+
before(:each) do
|
92
92
|
@instance = SomethingExpected.new
|
93
93
|
@instance.some_value = 5
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
it "should pass when attribute is changed by expected amount" do
|
97
97
|
lambda { @instance.some_value += 1 }.should change(@instance, :some_value).by(1)
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
it "should fail when the attribute is changed by unexpected amount" do
|
101
101
|
lambda do
|
102
102
|
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by(1)
|
103
103
|
end.should fail_with("some_value should have been changed by 1, but was changed by 2")
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
|
107
107
|
lambda do
|
108
108
|
lambda { @instance.some_value -= 1 }.should change(@instance, :some_value).by(1)
|
109
109
|
end.should fail_with("some_value should have been changed by 1, but was changed by -1")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
describe "should change{ block }.by(expected)" do
|
114
|
+
before(:each) do
|
115
115
|
@instance = SomethingExpected.new
|
116
116
|
@instance.some_value = 5
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
it "should pass when attribute is changed by expected amount" do
|
120
120
|
lambda { @instance.some_value += 1 }.should change{@instance.some_value}.by(1)
|
121
121
|
end
|
122
122
|
|
123
|
-
|
123
|
+
it "should fail when the attribute is changed by unexpected amount" do
|
124
124
|
lambda do
|
125
125
|
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by(1)
|
126
126
|
end.should fail_with("result should have been changed by 1, but was changed by 2")
|
127
127
|
end
|
128
128
|
|
129
|
-
|
129
|
+
it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
|
130
130
|
lambda do
|
131
131
|
lambda { @instance.some_value -= 1 }.should change{@instance.some_value}.by(1)
|
132
132
|
end.should fail_with("result should have been changed by 1, but was changed by -1")
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
|
137
|
-
|
136
|
+
describe "should change(actual, message).from(old)" do
|
137
|
+
before(:each) do
|
138
138
|
@instance = SomethingExpected.new
|
139
139
|
@instance.some_value = 'string'
|
140
140
|
end
|
141
141
|
|
142
|
-
|
142
|
+
it "should pass when attribute is == to expected value before executing block" do
|
143
143
|
lambda { @instance.some_value = "astring" }.should change(@instance, :some_value).from("string")
|
144
144
|
end
|
145
145
|
|
146
|
-
|
146
|
+
it "should fail when attribute is not == to expected value before executing block" do
|
147
147
|
lambda do
|
148
148
|
lambda { @instance.some_value = "knot" }.should change(@instance, :some_value).from("cat")
|
149
149
|
end.should fail_with("some_value should have initially been \"cat\", but was \"string\"")
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
|
154
|
-
|
153
|
+
describe "should change{ block }.from(old)" do
|
154
|
+
before(:each) do
|
155
155
|
@instance = SomethingExpected.new
|
156
156
|
@instance.some_value = 'string'
|
157
157
|
end
|
158
158
|
|
159
|
-
|
159
|
+
it "should pass when attribute is == to expected value before executing block" do
|
160
160
|
lambda { @instance.some_value = "astring" }.should change{@instance.some_value}.from("string")
|
161
161
|
end
|
162
162
|
|
163
|
-
|
163
|
+
it "should fail when attribute is not == to expected value before executing block" do
|
164
164
|
lambda do
|
165
165
|
lambda { @instance.some_value = "knot" }.should change{@instance.some_value}.from("cat")
|
166
166
|
end.should fail_with("result should have initially been \"cat\", but was \"string\"")
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
|
171
|
-
|
170
|
+
describe "should change(actual, message).to(new)" do
|
171
|
+
before(:each) do
|
172
172
|
@instance = SomethingExpected.new
|
173
173
|
@instance.some_value = 'string'
|
174
174
|
end
|
175
175
|
|
176
|
-
|
176
|
+
it "should pass when attribute is == to expected value after executing block" do
|
177
177
|
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat")
|
178
178
|
end
|
179
179
|
|
180
|
-
|
180
|
+
it "should fail when attribute is not == to expected value after executing block" do
|
181
181
|
lambda do
|
182
182
|
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("dog")
|
183
183
|
end.should fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
|
188
|
-
|
187
|
+
describe "should change{ block }.to(new)" do
|
188
|
+
before(:each) do
|
189
189
|
@instance = SomethingExpected.new
|
190
190
|
@instance.some_value = 'string'
|
191
191
|
end
|
192
192
|
|
193
|
-
|
193
|
+
it "should pass when attribute is == to expected value after executing block" do
|
194
194
|
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat")
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "should fail when attribute is not == to expected value after executing block" do
|
198
198
|
lambda do
|
199
199
|
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("dog")
|
200
200
|
end.should fail_with("result should have been changed to \"dog\", but is now \"cat\"")
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
|
205
|
-
|
204
|
+
describe "should change(actual, message).from(old).to(new)" do
|
205
|
+
before(:each) do
|
206
206
|
@instance = SomethingExpected.new
|
207
207
|
@instance.some_value = 'string'
|
208
208
|
end
|
209
209
|
|
210
|
-
|
210
|
+
it "should pass when #to comes before #from" do
|
211
211
|
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat").from("string")
|
212
212
|
end
|
213
213
|
|
214
|
-
|
214
|
+
it "should pass when #from comes before #to" do
|
215
215
|
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("cat")
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
|
-
|
220
|
-
|
219
|
+
describe "should change{ block }.from(old).to(new)" do
|
220
|
+
before(:each) do
|
221
221
|
@instance = SomethingExpected.new
|
222
222
|
@instance.some_value = 'string'
|
223
223
|
end
|
224
224
|
|
225
|
-
|
225
|
+
it "should pass when #to comes before #from" do
|
226
226
|
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat").from("string")
|
227
227
|
end
|
228
228
|
|
229
|
-
|
229
|
+
it "should pass when #from comes before #to" do
|
230
230
|
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("cat")
|
231
231
|
end
|
232
232
|
end
|