rspec 0.7.5.1 → 0.8.0
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/CHANGES +60 -1
- data/EXAMPLES.rd +38 -19
- data/MIT-LICENSE +1 -1
- data/README +24 -17
- data/RELEASE-PLAN +117 -0
- data/Rakefile +24 -18
- data/TODO.0.8.0 +5 -0
- data/examples/auto_spec_name_generation_example.rb +18 -0
- data/examples/custom_expectation_matchers.rb +53 -0
- data/examples/dynamic_spec.rb +9 -0
- data/examples/io_processor_spec.rb +2 -2
- data/examples/mocking_example.rb +4 -4
- data/examples/partial_mock_example.rb +2 -2
- data/examples/predicate_example.rb +2 -2
- data/examples/stack_spec.rb +32 -36
- data/examples/stubbing_example.rb +19 -19
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +3 -0
- data/lib/spec/callback.rb +8 -0
- data/lib/spec/callback/extensions/object.rb +4 -0
- data/lib/spec/deprecated.rb +3 -0
- data/lib/spec/expectations.rb +44 -17
- data/lib/spec/expectations/extensions.rb +1 -2
- data/lib/spec/expectations/extensions/object.rb +78 -130
- data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
- data/lib/spec/expectations/handler.rb +47 -0
- data/lib/spec/expectations/should/base.rb +32 -29
- data/lib/spec/expectations/should/change.rb +1 -1
- data/lib/spec/expectations/should/have.rb +9 -17
- data/lib/spec/expectations/should/not.rb +54 -56
- data/lib/spec/expectations/should/should.rb +59 -65
- data/lib/spec/expectations/sugar.rb +27 -4
- data/lib/spec/matchers.rb +160 -0
- data/lib/spec/matchers/be.rb +161 -0
- data/lib/spec/matchers/be_close.rb +37 -0
- data/lib/spec/matchers/change.rb +120 -0
- data/lib/spec/matchers/eql.rb +43 -0
- data/lib/spec/matchers/equal.rb +43 -0
- data/lib/spec/matchers/has.rb +44 -0
- data/lib/spec/matchers/have.rb +140 -0
- data/lib/spec/matchers/include.rb +50 -0
- data/lib/spec/matchers/match.rb +41 -0
- data/lib/spec/matchers/raise_error.rb +100 -0
- data/lib/spec/matchers/respond_to.rb +35 -0
- data/lib/spec/matchers/satisfy.rb +47 -0
- data/lib/spec/matchers/throw_symbol.rb +75 -0
- data/lib/spec/mocks.rb +224 -1
- data/lib/spec/mocks/argument_expectation.rb +16 -2
- data/lib/spec/mocks/error_generator.rb +5 -3
- data/lib/spec/mocks/errors.rb +2 -2
- data/lib/spec/mocks/extensions/object.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +29 -19
- data/lib/spec/mocks/{mock_methods.rb → methods.rb} +5 -5
- data/lib/spec/mocks/mock.rb +2 -2
- data/lib/spec/mocks/mock_handler.rb +81 -68
- data/lib/spec/rake/spectask.rb +7 -12
- data/lib/spec/rake/verify_rcov.rb +1 -1
- data/lib/spec/runner.rb +117 -0
- data/lib/spec/runner/command_line.rb +8 -5
- data/lib/spec/runner/context.rb +13 -37
- data/lib/spec/runner/context_eval.rb +4 -3
- data/lib/spec/runner/context_runner.rb +7 -4
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/execution_context.rb +3 -11
- data/lib/spec/runner/extensions/kernel.rb +7 -5
- data/lib/spec/runner/extensions/object.rb +4 -1
- data/lib/spec/runner/formatter/base_text_formatter.rb +11 -3
- data/lib/spec/runner/formatter/html_formatter.rb +21 -10
- data/lib/spec/runner/heckle_runner.rb +24 -8
- data/lib/spec/runner/heckle_runner_win.rb +10 -0
- data/lib/spec/runner/option_parser.rb +58 -13
- data/lib/spec/runner/spec_matcher.rb +22 -29
- data/lib/spec/runner/spec_parser.rb +1 -0
- data/lib/spec/runner/specification.rb +36 -22
- data/lib/spec/translator.rb +87 -0
- data/lib/spec/version.rb +16 -7
- data/spec/spec/callback/callback_container_spec.rb +27 -0
- data/spec/spec/callback/module_spec.rb +37 -0
- data/spec/spec/callback/object_spec.rb +90 -0
- data/spec/spec/callback/object_with_class_callback_spec.rb +19 -0
- data/spec/spec/expectations/differs/default_spec.rb +107 -0
- data/spec/spec/expectations/extensions/object_spec.rb +46 -0
- data/spec/spec/expectations/fail_with_spec.rb +71 -0
- data/spec/spec/expectations/should/should_==_spec.rb +19 -0
- data/spec/spec/expectations/should/should_=~_spec.rb +13 -0
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +21 -0
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +30 -0
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +81 -0
- data/spec/spec/expectations/should/should_be_close_spec.rb +18 -0
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +44 -0
- data/spec/spec/expectations/should/should_be_false_spec.rb +39 -0
- data/spec/spec/expectations/should/should_be_spec.rb +11 -0
- data/spec/spec/expectations/should/should_be_true_spec.rb +27 -0
- data/spec/spec/expectations/should/should_change_spec.rb +184 -0
- data/spec/spec/expectations/should/should_eql_spec.rb +11 -0
- data/spec/spec/expectations/should/should_equal_spec.rb +11 -0
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +53 -0
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +45 -0
- data/spec/spec/expectations/should/should_have_key_spec.rb +21 -0
- data/spec/spec/expectations/should/should_have_spec.rb +64 -0
- data/spec/spec/expectations/should/should_include_spec.rb +59 -0
- data/spec/spec/expectations/should/should_match_spec.rb +25 -0
- data/spec/spec/expectations/should/should_not_==_spec.rb +15 -0
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +21 -0
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +11 -0
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +68 -0
- data/spec/spec/expectations/should/should_not_be_spec.rb +11 -0
- data/spec/spec/expectations/should/should_not_change_spec.rb +24 -0
- data/spec/spec/expectations/should/should_not_eql_spec.rb +11 -0
- data/spec/spec/expectations/should/should_not_equal_spec.rb +11 -0
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +15 -0
- data/spec/spec/expectations/should/should_not_include_spec.rb +58 -0
- data/spec/spec/expectations/should/should_not_match_spec.rb +11 -0
- data/spec/spec/expectations/should/should_not_raise_spec.rb +75 -0
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +15 -0
- data/spec/spec/expectations/should/should_not_throw_spec.rb +35 -0
- data/spec/spec/expectations/should/should_raise_spec.rb +66 -0
- data/spec/spec/expectations/should/should_respond_to_spec.rb +15 -0
- data/spec/spec/expectations/should/should_satisfy_spec.rb +35 -0
- data/spec/spec/expectations/should/should_throw_spec.rb +27 -0
- data/spec/spec/matchers/be_close_spec.rb +33 -0
- data/spec/spec/matchers/be_spec.rb +182 -0
- data/spec/spec/matchers/change_spec.rb +232 -0
- data/spec/spec/matchers/description_generation_spec.rb +147 -0
- data/spec/spec/matchers/eql_spec.rb +41 -0
- data/spec/spec/matchers/equal_spec.rb +41 -0
- data/spec/spec/matchers/handler_spec.rb +75 -0
- data/spec/spec/matchers/has_spec.rb +37 -0
- data/spec/spec/matchers/have_spec.rb +259 -0
- data/spec/spec/matchers/include_spec.rb +33 -0
- data/spec/spec/matchers/match_spec.rb +37 -0
- data/spec/spec/matchers/matcher_methods_spec.rb +85 -0
- data/spec/spec/matchers/raise_error_spec.rb +147 -0
- data/spec/spec/matchers/respond_to_spec.rb +30 -0
- data/spec/spec/matchers/satisfy_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +59 -0
- data/spec/spec/mocks/any_number_of_times_spec.rb +34 -0
- data/spec/spec/mocks/at_least_spec.rb +97 -0
- data/spec/spec/mocks/at_most_spec.rb +97 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
- data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
- data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
- data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +74 -0
- data/spec/spec/mocks/mock_ordering_spec.rb +80 -0
- data/spec/spec/mocks/mock_spec.rb +407 -0
- data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
- data/spec/spec/mocks/null_object_mock_spec.rb +40 -0
- data/spec/spec/mocks/once_counts_spec.rb +56 -0
- data/spec/spec/mocks/options_hash_spec.rb +31 -0
- data/spec/spec/mocks/partial_mock_spec.rb +52 -0
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +64 -0
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +92 -0
- data/spec/spec/mocks/precise_counts_spec.rb +56 -0
- data/spec/spec/mocks/record_messages_spec.rb +26 -0
- data/spec/spec/mocks/stub_spec.rb +159 -0
- data/spec/spec/mocks/twice_counts_spec.rb +67 -0
- data/spec/spec/runner/command_line_spec.rb +32 -0
- data/spec/spec/runner/context_matching_spec.rb +28 -0
- data/spec/spec/runner/context_runner_spec.rb +100 -0
- data/spec/spec/runner/context_spec.rb +405 -0
- data/spec/spec/runner/drb_command_line_spec.rb +74 -0
- data/spec/spec/runner/execution_context_spec.rb +52 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +40 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +21 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +36 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +78 -0
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +18 -0
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +41 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +21 -0
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +46 -0
- data/spec/spec/runner/heckle_runner_spec.rb +63 -0
- data/spec/spec/runner/heckler_spec.rb +14 -0
- data/spec/spec/runner/kernel_ext_spec.rb +16 -0
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
- data/spec/spec/runner/object_ext_spec.rb +11 -0
- data/spec/spec/runner/option_parser_spec.rb +269 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +47 -0
- data/spec/spec/runner/reporter_spec.rb +126 -0
- data/spec/spec/runner/spec_matcher_spec.rb +107 -0
- data/spec/spec/runner/spec_name_generation_spec.rb +102 -0
- data/spec/spec/runner/spec_parser_spec.rb +37 -0
- data/spec/spec/runner/specification_class_spec.rb +72 -0
- data/spec/spec/runner/specification_instance_spec.rb +160 -0
- data/spec/spec/runner/specification_should_raise_spec.rb +136 -0
- data/spec/spec/spec_classes.rb +102 -0
- data/spec/spec/translator_spec.rb +79 -0
- data/spec/spec_helper.rb +35 -0
- metadata +141 -9
- data/bin/drbspec +0 -3
- data/lib/spec/expectations/diff.rb +0 -28
- data/lib/spec/expectations/extensions/numeric.rb +0 -19
- data/lib/spec/expectations/extensions/string.rb +0 -22
- data/lib/spec/expectations/message_builder.rb +0 -13
@@ -0,0 +1,53 @@
|
|
1
|
+
module AnimalSpecHelper
|
2
|
+
class Eat
|
3
|
+
def initialize(food)
|
4
|
+
@food = food
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(animal)
|
8
|
+
@animal = animal
|
9
|
+
@animal.eats?(@food)
|
10
|
+
end
|
11
|
+
|
12
|
+
def failure_message
|
13
|
+
"expected #{@animal} to eat #{@food}, but it does not"
|
14
|
+
end
|
15
|
+
|
16
|
+
def negative_failure_message
|
17
|
+
"expected #{@animal} not to eat #{@food}, but it does"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def eat(food)
|
22
|
+
Eat.new(food)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Animals
|
27
|
+
class Animal
|
28
|
+
def eats?(food)
|
29
|
+
return foods_i_eat.include?(food)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Mouse < Animal
|
34
|
+
def foods_i_eat
|
35
|
+
[:cheese]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "A mouse" do
|
41
|
+
include AnimalSpecHelper
|
42
|
+
setup do
|
43
|
+
@mouse = Animals::Mouse.new
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "should eat cheese" do
|
47
|
+
@mouse.should eat(:cheese)
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "should not eat cat" do
|
51
|
+
@mouse.should_not eat(:cat)
|
52
|
+
end
|
53
|
+
end
|
@@ -10,12 +10,12 @@ context "An IoProcessor" do
|
|
10
10
|
specify "should raise nothing when the file is exactly 32 bytes" do
|
11
11
|
lambda {
|
12
12
|
@processor.process(StringIO.new("z"*32))
|
13
|
-
}.
|
13
|
+
}.should_not raise_error
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should raise an exception when the file length is less than 32 bytes" do
|
17
17
|
lambda {
|
18
18
|
@processor.process(StringIO.new("z"*31))
|
19
|
-
}.
|
19
|
+
}.should raise_error(DataTooShort)
|
20
20
|
end
|
21
21
|
end
|
data/examples/mocking_example.rb
CHANGED
@@ -13,15 +13,15 @@ context "a mock" do
|
|
13
13
|
mock = mock("mock")
|
14
14
|
mock.should_receive(:msg).with(:arg1).and_return(:val1)
|
15
15
|
mock.should_receive(:msg).with(:arg2).and_return(:val2)
|
16
|
-
mock.msg(:arg1).
|
17
|
-
mock.msg(:arg2).
|
16
|
+
mock.msg(:arg1).should eql(:val1)
|
17
|
+
mock.msg(:arg2).should eql(:val2)
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "should be able to mock the same message twice w/ different args in reverse order" do
|
21
21
|
mock = mock("mock")
|
22
22
|
mock.should_receive(:msg).with(:arg1).and_return(:val1)
|
23
23
|
mock.should_receive(:msg).with(:arg2).and_return(:val2)
|
24
|
-
mock.msg(:arg2).
|
25
|
-
mock.msg(:arg1).
|
24
|
+
mock.msg(:arg2).should eql(:val2)
|
25
|
+
mock.msg(:arg1).should eql(:val1)
|
26
26
|
end
|
27
27
|
end
|
@@ -10,11 +10,11 @@ context "A partial mock" do
|
|
10
10
|
|
11
11
|
specify "should work at the class level" do
|
12
12
|
MockableClass.should_receive(:find).with(1).and_return {:stub_return}
|
13
|
-
MockableClass.find(1).
|
13
|
+
MockableClass.find(1).should equal(:stub_return)
|
14
14
|
end
|
15
15
|
|
16
16
|
specify "should revert to the original after each spec" do
|
17
|
-
MockableClass.find(1).
|
17
|
+
MockableClass.find(1).should equal(:original_return)
|
18
18
|
end
|
19
19
|
|
20
20
|
specify "can be mocked w/ ordering" do
|
@@ -17,11 +17,11 @@ context "BDD framework" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
specify "should be adopted quickly" do
|
20
|
-
@bdd_framework.
|
20
|
+
@bdd_framework.should be_adopted_quickly
|
21
21
|
end
|
22
22
|
|
23
23
|
specify "should be intuitive" do
|
24
|
-
@bdd_framework.
|
24
|
+
@bdd_framework.should be_intuitive
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
data/examples/stack_spec.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
require File.dirname(__FILE__) + "/stack"
|
3
3
|
|
4
|
-
context "A
|
4
|
+
context "A Stack" do
|
5
5
|
setup do
|
6
6
|
@stack = Stack.new
|
7
7
|
["a","b","c"].each { |x| @stack.push x }
|
8
8
|
end
|
9
9
|
|
10
|
-
specify "should add to the top when sent
|
10
|
+
specify "should add to the top when sent #push" do
|
11
11
|
@stack.push "d"
|
12
12
|
@stack.peek.should == "d"
|
13
13
|
end
|
14
14
|
|
15
|
-
specify "should return the top item when sent
|
15
|
+
specify "should return the top item when sent #peek" do
|
16
16
|
@stack.peek.should == "c"
|
17
17
|
end
|
18
18
|
|
19
|
-
specify "should NOT remove the top item when sent
|
19
|
+
specify "should NOT remove the top item when sent #peek" do
|
20
20
|
@stack.peek.should == "c"
|
21
21
|
@stack.peek.should == "c"
|
22
22
|
end
|
23
23
|
|
24
|
-
specify "should return the top item when sent
|
24
|
+
specify "should return the top item when sent #pop" do
|
25
25
|
@stack.pop.should == "c"
|
26
26
|
end
|
27
27
|
|
28
|
-
specify "should remove the top item when sent
|
28
|
+
specify "should remove the top item when sent #pop" do
|
29
29
|
@stack.pop.should == "c"
|
30
30
|
@stack.pop.should == "b"
|
31
31
|
end
|
@@ -36,21 +36,20 @@ context "An empty stack" do
|
|
36
36
|
@stack = Stack.new
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
39
|
+
# NOTE that this one auto-generates the description "should be_empty"
|
40
|
+
specify { @stack.should be_empty }
|
42
41
|
|
43
|
-
specify "should no longer be empty after
|
42
|
+
specify "should no longer be empty after #push" do
|
44
43
|
@stack.push "anything"
|
45
|
-
@stack.
|
44
|
+
@stack.should_not be_empty
|
46
45
|
end
|
47
46
|
|
48
|
-
specify "should complain when sent
|
49
|
-
lambda { @stack.peek }.
|
47
|
+
specify "should complain when sent #peek" do
|
48
|
+
lambda { @stack.peek }.should raise_error(StackUnderflowError)
|
50
49
|
end
|
51
50
|
|
52
|
-
specify "should complain when sent
|
53
|
-
lambda { @stack.pop }.
|
51
|
+
specify "should complain when sent #pop" do
|
52
|
+
lambda { @stack.pop }.should raise_error(StackUnderflowError)
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -60,18 +59,17 @@ context "An almost empty stack (with one item)" do
|
|
60
59
|
@stack.push 3
|
61
60
|
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
end
|
62
|
+
# NOTE that this one auto-generates the description "should not be empty"
|
63
|
+
specify { @stack.should_not be_empty }
|
66
64
|
|
67
|
-
specify "should remain not empty after
|
65
|
+
specify "should remain not empty after #peek" do
|
68
66
|
@stack.peek
|
69
|
-
@stack.
|
67
|
+
@stack.should_not be_empty
|
70
68
|
end
|
71
69
|
|
72
|
-
specify "should become empty after
|
70
|
+
specify "should become empty after #pop" do
|
73
71
|
@stack.pop
|
74
|
-
@stack.
|
72
|
+
@stack.should be_empty
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
@@ -81,13 +79,12 @@ context "An almost full stack (with one item less than capacity)" do
|
|
81
79
|
(1..9).each { |i| @stack.push i }
|
82
80
|
end
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
82
|
+
# NOTE that this one auto-generates the description "should not be full"
|
83
|
+
specify { @stack.should_not be_full }
|
87
84
|
|
88
|
-
specify "should become full when sent
|
85
|
+
specify "should become full when sent #push" do
|
89
86
|
@stack.push Object.new
|
90
|
-
@stack.
|
87
|
+
@stack.should be_full
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
@@ -97,21 +94,20 @@ context "A full stack" do
|
|
97
94
|
(1..10).each { |i| @stack.push i }
|
98
95
|
end
|
99
96
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
97
|
+
# NOTE that this one auto-generates the description "should be full"
|
98
|
+
specify { @stack.should be_full }
|
103
99
|
|
104
|
-
specify "should remain full after
|
100
|
+
specify "should remain full after #peek" do
|
105
101
|
@stack.peek
|
106
|
-
@stack.
|
102
|
+
@stack.should be_full
|
107
103
|
end
|
108
104
|
|
109
|
-
specify "should no longer be full after
|
105
|
+
specify "should no longer be full after #pop" do
|
110
106
|
@stack.pop
|
111
|
-
@stack.
|
107
|
+
@stack.should_not be_full
|
112
108
|
end
|
113
109
|
|
114
|
-
specify "should complain on
|
115
|
-
lambda { @stack.push Object.new }.
|
110
|
+
specify "should complain on #push" do
|
111
|
+
lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
|
116
112
|
end
|
117
113
|
end
|
@@ -4,7 +4,7 @@ context "A consumer of a stub" do
|
|
4
4
|
specify "should be able to stub methods on any Object" do
|
5
5
|
obj = Object.new
|
6
6
|
obj.stub!(:foobar).and_return {:return_value}
|
7
|
-
obj.foobar.
|
7
|
+
obj.foobar.should equal(:return_value)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -17,23 +17,23 @@ end
|
|
17
17
|
context "A stubbed method on a class" do
|
18
18
|
specify "should return the stubbed value" do
|
19
19
|
StubbableClass.stub!(:find).and_return(:stub_return)
|
20
|
-
StubbableClass.find(1).
|
20
|
+
StubbableClass.find(1).should equal(:stub_return)
|
21
21
|
end
|
22
22
|
|
23
23
|
specify "should revert to the original method after each spec" do
|
24
|
-
StubbableClass.find(1).
|
24
|
+
StubbableClass.find(1).should equal(:original_return)
|
25
25
|
end
|
26
26
|
|
27
27
|
specify "can stub! and mock the same message" do
|
28
28
|
StubbableClass.stub!(:msg).and_return(:stub_value)
|
29
29
|
StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
|
30
30
|
|
31
|
-
StubbableClass.msg.
|
32
|
-
StubbableClass.msg(:other_arg).
|
33
|
-
StubbableClass.msg(:arg).
|
34
|
-
StubbableClass.msg(:another_arg).
|
35
|
-
StubbableClass.msg(:yet_another_arg).
|
36
|
-
StubbableClass.msg.
|
31
|
+
StubbableClass.msg.should equal(:stub_value)
|
32
|
+
StubbableClass.msg(:other_arg).should equal(:stub_value)
|
33
|
+
StubbableClass.msg(:arg).should equal(:mock_value)
|
34
|
+
StubbableClass.msg(:another_arg).should equal(:stub_value)
|
35
|
+
StubbableClass.msg(:yet_another_arg).should equal(:stub_value)
|
36
|
+
StubbableClass.msg.should equal(:stub_value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,28 +41,28 @@ context "A mock" do
|
|
41
41
|
specify "can stub!" do
|
42
42
|
mock = mock("stubbing mock")
|
43
43
|
mock.stub!(:msg).and_return(:value)
|
44
|
-
(1..10).each {mock.msg.
|
44
|
+
(1..10).each {mock.msg.should equal(:value)}
|
45
45
|
end
|
46
46
|
|
47
47
|
specify "can stub! and mock" do
|
48
48
|
mock = mock("stubbing mock")
|
49
49
|
mock.stub!(:stub_message).and_return(:stub_value)
|
50
50
|
mock.should_receive(:mock_message).once.and_return(:mock_value)
|
51
|
-
(1..10).each {mock.stub_message.
|
52
|
-
mock.mock_message.
|
53
|
-
(1..10).each {mock.stub_message.
|
51
|
+
(1..10).each {mock.stub_message.should equal(:stub_value)}
|
52
|
+
mock.mock_message.should equal(:mock_value)
|
53
|
+
(1..10).each {mock.stub_message.should equal(:stub_value)}
|
54
54
|
end
|
55
55
|
|
56
56
|
specify "can stub! and mock the same message" do
|
57
57
|
mock = mock("stubbing mock")
|
58
58
|
mock.stub!(:msg).and_return(:stub_value)
|
59
59
|
mock.should_receive(:msg).with(:arg).and_return(:mock_value)
|
60
|
-
mock.msg.
|
61
|
-
mock.msg(:other_arg).
|
62
|
-
mock.msg(:arg).
|
63
|
-
mock.msg(:another_arg).
|
64
|
-
mock.msg(:yet_another_arg).
|
65
|
-
mock.msg.
|
60
|
+
mock.msg.should equal(:stub_value)
|
61
|
+
mock.msg(:other_arg).should equal(:stub_value)
|
62
|
+
mock.msg(:arg).should equal(:mock_value)
|
63
|
+
mock.msg(:another_arg).should equal(:stub_value)
|
64
|
+
mock.msg(:yet_another_arg).should equal(:stub_value)
|
65
|
+
mock.msg.should equal(:stub_value)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
data/examples/test_case_spec.rb
CHANGED
@@ -7,7 +7,7 @@ class RSpecIntegrationTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.verify_class_method
|
10
|
-
@@fixtures.
|
10
|
+
@@fixtures.should == true
|
11
11
|
end
|
12
12
|
|
13
13
|
def setup
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
context "RSpec should integrate with Test::Unit::TestCase" do
|
36
36
|
inherit RSpecIntegrationTest
|
37
37
|
include RandomHelperModule
|
38
|
-
|
38
|
+
|
39
39
|
fixtures :some_table
|
40
40
|
|
41
41
|
setup do
|
@@ -43,18 +43,18 @@ context "RSpec should integrate with Test::Unit::TestCase" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
specify "TestCase#setup should be called." do
|
46
|
-
@test_case_setup_called.
|
47
|
-
@rspec_setup_called.
|
46
|
+
@test_case_setup_called.should be_true
|
47
|
+
@rspec_setup_called.should be_true
|
48
48
|
end
|
49
49
|
|
50
50
|
specify "RSpec should be able to access TestCase methods" do
|
51
51
|
helper_method
|
52
|
-
@helper_method_called.
|
52
|
+
@helper_method_called.should be_true
|
53
53
|
end
|
54
54
|
|
55
55
|
specify "RSpec should be able to accept included modules" do
|
56
56
|
random_task
|
57
|
-
@random_task_called.
|
57
|
+
@random_task_called.should be_true
|
58
58
|
end
|
59
59
|
|
60
60
|
teardown do
|
data/lib/spec.rb
CHANGED
data/lib/spec/callback.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
require 'spec/callback/callback_container'
|
2
2
|
require 'spec/callback/extensions/module'
|
3
3
|
require 'spec/callback/extensions/object'
|
4
|
+
|
5
|
+
# Callback is a fork of Brian Takita's "callback library" (see http://callback.rubyforge.org),
|
6
|
+
# which Brian graciously contributed to RSpec in order to avoid the dependency.
|
7
|
+
#
|
8
|
+
# RSpec uses Callback internally to create hooks to Spec::Runner events. If you're interested
|
9
|
+
# in a simple, powerful API for generating callback events, check out http://callback.rubyforge.org.
|
10
|
+
module Callback
|
11
|
+
end
|
@@ -21,6 +21,10 @@ module Callback
|
|
21
21
|
callbacks.notify(event, *args, &error_handler)
|
22
22
|
end
|
23
23
|
|
24
|
+
def notify_class_callbacks(event, *args, &error_handler)
|
25
|
+
self.class.send(:notify_callbacks, event, *args, &error_handler)
|
26
|
+
end
|
27
|
+
|
24
28
|
# The CallbackContainer for this object.
|
25
29
|
def callbacks
|
26
30
|
@callbacks ||= CallbackContainer.new
|
data/lib/spec/expectations.rb
CHANGED
@@ -1,32 +1,59 @@
|
|
1
|
+
require 'spec/deprecated'
|
2
|
+
require 'spec/matchers'
|
1
3
|
require 'spec/expectations/sugar'
|
2
4
|
require 'spec/expectations/errors'
|
3
5
|
require 'spec/expectations/extensions'
|
4
6
|
require 'spec/expectations/should'
|
5
|
-
require 'spec/expectations/
|
7
|
+
require 'spec/expectations/handler'
|
6
8
|
|
7
9
|
module Spec
|
8
|
-
|
9
|
-
#
|
10
|
+
|
11
|
+
# Spec::Expectations lets you set expectations on your objects.
|
10
12
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
+
# result.should == 37
|
14
|
+
# team.should have(11).players_on_the_field
|
13
15
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
+
# == How Expectations work.
|
17
|
+
#
|
18
|
+
# Spec::Expectations adds two methods to Object:
|
19
|
+
#
|
20
|
+
# should(matcher=nil)
|
21
|
+
# should_not(matcher=nil)
|
22
|
+
#
|
23
|
+
# Both methods take an optional Expression Matcher (See Spec::Matchers).
|
24
|
+
#
|
25
|
+
# When +should+ receives an Expression Matcher, it calls <tt>matches?(self)</tt>. If
|
26
|
+
# it returns +true+, the spec passes and execution continues. If it returns
|
27
|
+
# +false+, then the spec fails with the message returned by <tt>matcher.failure_message</tt>.
|
28
|
+
#
|
29
|
+
# Similarly, when +should_not+ receives a matcher, it calls <tt>matches?(self)</tt>. If
|
30
|
+
# it returns +false+, the spec passes and execution continues. If it returns
|
31
|
+
# +true+, then the spec fails with the message returned by <tt>matcher.negative_failure_message</tt>.
|
32
|
+
#
|
33
|
+
# RSpec ships with a standard set of useful matchers, and writing your own
|
34
|
+
# matchers is quite simple. See Spec::Matchers for details.
|
16
35
|
module Expectations
|
17
36
|
class << self
|
18
|
-
|
19
|
-
|
37
|
+
attr_accessor :differ
|
38
|
+
|
39
|
+
# raises a Spec::Expectations::ExpectationNotMetError with message
|
40
|
+
#
|
41
|
+
# When a differ has been assigned and fail_with is passed
|
42
|
+
# <code>expected</code> and <code>target</code>, passes them
|
43
|
+
# to the differ to append a diff message to the failure message.
|
44
|
+
def fail_with(message, expected=nil, target=nil) # :nodoc:
|
45
|
+
if Array === message && message.length == 3
|
46
|
+
message, expected, target = message[0], message[1], message[2]
|
47
|
+
end
|
48
|
+
unless (differ.nil? || expected.nil? || target.nil?)
|
49
|
+
if expected.is_a?(String)
|
50
|
+
message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
|
51
|
+
elsif !target.is_a?(Proc)
|
52
|
+
message << "\nDiff:" << self.differ.diff_as_object(target, expected)
|
53
|
+
end
|
54
|
+
end
|
20
55
|
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
|
21
56
|
end
|
22
|
-
|
23
|
-
def build_message(actual, expectation, expected)
|
24
|
-
message_builder.build_message(actual, expectation, expected)
|
25
|
-
end
|
26
|
-
|
27
|
-
def message_builder #:nodoc:
|
28
|
-
@message_builder ||= MessageBuilder.new
|
29
|
-
end
|
30
57
|
end
|
31
58
|
end
|
32
59
|
end
|