rspec 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +28 -3
- data/EXAMPLES.rd +2 -16
- data/README +5 -2
- data/Rakefile +8 -4
- data/bin/spec +1 -0
- data/examples/custom_formatter.rb +2 -1
- data/examples/helper_method_spec.rb +12 -0
- data/examples/{mocking_spec.rb → mocking_example.rb} +0 -0
- data/examples/{bdd_framework_spec.rb → predicate_example.rb} +0 -0
- data/examples/stubbing_example.rb +28 -0
- data/lib/spec.rb +2 -1
- data/lib/spec/expectations.rb +7 -0
- data/lib/spec/expectations/diff.rb +56 -0
- data/lib/spec/expectations/exceptions.rb +6 -0
- data/lib/spec/expectations/expectations.rb +19 -0
- data/lib/spec/expectations/have_helper.rb +41 -0
- data/lib/spec/expectations/helper.rb +4 -0
- data/lib/spec/expectations/should_base.rb +52 -0
- data/lib/spec/expectations/should_helper.rb +93 -0
- data/lib/spec/expectations/should_negator.rb +71 -0
- data/lib/spec/{api → expectations}/sugar.rb +8 -8
- data/lib/spec/mocks.rb +5 -0
- data/lib/spec/{api/mocks → mocks}/argument_expectation.rb +1 -1
- data/lib/spec/{api → mocks}/exceptions.rb +3 -5
- data/lib/spec/{api/mocks → mocks}/message_expectation.rb +15 -9
- data/lib/spec/{api/mocks → mocks}/mock.rb +44 -26
- data/lib/spec/{api/mocks → mocks}/order_group.rb +1 -1
- data/lib/spec/runner/backtrace_tweaker.rb +4 -1
- data/lib/spec/runner/execution_context.rb +13 -4
- data/lib/spec/runner/formatter/base_text_formatter.rb +26 -13
- data/lib/spec/runner/formatter/html_formatter.rb +1 -1
- data/lib/spec/runner/option_parser.rb +6 -2
- data/lib/spec/runner/specification.rb +2 -2
- data/lib/spec/test_to_spec/ruby2ruby.rb +1 -1
- data/lib/spec/version.rb +1 -1
- data/test/spec/expectations/arbitrary_operator_test.rb +55 -0
- data/test/spec/expectations/arbitrary_predicate_test.rb +163 -0
- data/test/spec/{api/helper → expectations}/containment_test.rb +2 -2
- data/test/spec/expectations/diff_test.rb +62 -0
- data/test/spec/{api/helper → expectations}/identity_test.rb +2 -2
- data/test/spec/{api/helper → expectations}/object_equality_test.rb +2 -2
- data/test/spec/{api/helper → expectations}/raising_test.rb +5 -5
- data/test/spec/{api/helper → expectations}/regex_matching_test.rb +6 -6
- data/test/spec/{api/helper → expectations}/should_have_test.rb +11 -2
- data/test/spec/{api/helper → expectations}/should_satisfy_test.rb +2 -4
- data/test/spec/{api → expectations}/sugar_test.rb +8 -8
- data/test/spec/expectations/supported_symbols_test.rb +33 -0
- data/test/spec/{api/helper → expectations}/throwing_test.rb +2 -2
- data/test/spec/{api/helper → expectations}/true_false_special_case_test.rb +2 -2
- data/test/spec/{api/helper → expectations}/typing_test.rb +2 -2
- data/test/spec/{api/mocks → mocks}/mock_arg_constraints_test.rb +4 -4
- data/test/spec/{api/mocks → mocks}/mock_counts_test.rb +2 -2
- data/test/spec/{api/mocks → mocks}/mock_ordering_test.rb +2 -2
- data/test/spec/{api/mocks → mocks}/mock_test.rb +22 -7
- data/test/spec/{api/mocks → mocks}/null_object_test.rb +8 -2
- data/test/spec/runner/backtrace_tweaker_test.rb +21 -19
- data/test/spec/runner/context_matching_test.rb +2 -2
- data/test/spec/runner/context_runner_test.rb +6 -6
- data/test/spec/runner/context_test.rb +1 -1
- data/test/spec/runner/execution_context_test.rb +22 -5
- data/test/spec/runner/formatter/failure_dump_test.rb +7 -7
- data/test/spec/runner/option_parser_test.rb +20 -0
- data/test/spec/runner/reporter_test.rb +3 -3
- data/test/spec/runner/specification_test.rb +3 -3
- data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +4 -4
- data/test/spec/test_to_spec/sexp_transformer_test.rb +1 -1
- data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +2 -2
- data/test/test_classes.rb +21 -1
- data/test/test_helper.rb +1 -1
- data/vendor/selenium/README.txt +23 -0
- data/vendor/selenium/find_rspecs_home_page.rb +23 -0
- data/vendor/selenium/rspec_selenium.rb +33 -0
- data/vendor/watir/README.txt +32 -0
- data/vendor/watir/find_rspecs_home_page.rb +21 -0
- data/vendor/watir/find_rspecs_home_page.txt +15 -0
- data/vendor/watir/rspec_watir.rb +45 -0
- metadata +52 -41
- data/examples/airport_spec.rb +0 -33
- data/examples/custom_method_spec.rb +0 -24
- data/examples/sugar_spec.rb +0 -14
- data/lib/spec/api.rb +0 -8
- data/lib/spec/api/expectations.rb +0 -17
- data/lib/spec/api/helper.rb +0 -4
- data/lib/spec/api/helper/diff.rb +0 -54
- data/lib/spec/api/helper/have_helper.rb +0 -40
- data/lib/spec/api/helper/should_base.rb +0 -31
- data/lib/spec/api/helper/should_helper.rb +0 -93
- data/lib/spec/api/helper/should_negator.rb +0 -72
- data/test/spec/api/helper/arbitrary_predicate_test.rb +0 -112
- data/test/spec/api/helper/diff_test.rb +0 -60
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
module Spec
|
4
|
-
module
|
4
|
+
module Expectations
|
5
5
|
class SugarTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_should_allow_underscored_shoulds_on_regular_objects
|
@@ -10,21 +10,21 @@ module Spec
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_should_allow_underscored_shoulds_on_mocks
|
13
|
-
sweetener = Mock.new "sweetener"
|
13
|
+
sweetener = Mocks::Mock.new "sweetener"
|
14
14
|
sweetener.should_receive(:natural?)
|
15
15
|
sweetener.natural?
|
16
16
|
sweetener.__verify
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_should_allow_underscored_ats_on_mocks
|
20
|
-
sweetener = Mock.new "sweetener"
|
20
|
+
sweetener = Mocks::Mock.new "sweetener"
|
21
21
|
sweetener.should_receive(:natural?).at_least(:once)
|
22
22
|
sweetener.natural?
|
23
23
|
sweetener.__verify
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_should_allow_underscored_ands_on_mocks
|
27
|
-
sweetener = Mock.new "sweetener"
|
27
|
+
sweetener = Mocks::Mock.new "sweetener"
|
28
28
|
sweetener.should_receive(:natural?).at_least(:once).and_return(true)
|
29
29
|
natural = sweetener.natural?
|
30
30
|
natural.should_be true
|
@@ -32,14 +32,14 @@ module Spec
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_should_allow_underscored_anys_on_mocks
|
35
|
-
sweetener = Mock.new "sweetener"
|
35
|
+
sweetener = Mocks::Mock.new "sweetener"
|
36
36
|
sweetener.should_receive(:natural?).any_number_of_times
|
37
37
|
sweetener.natural?
|
38
38
|
sweetener.__verify
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_allow_underscored_anys_on_mocks
|
42
|
-
sweetener = Mock.new "sweetener"
|
42
|
+
sweetener = Mocks::Mock.new "sweetener"
|
43
43
|
sweetener.should_receive(:natural?).once.and_return(false)
|
44
44
|
natural = sweetener.natural?
|
45
45
|
natural.should_be false
|
@@ -69,7 +69,7 @@ module Spec
|
|
69
69
|
|
70
70
|
def test_is_an_instance_of_should_work_when_failing
|
71
71
|
n = 10
|
72
|
-
assert_raises(Spec::
|
72
|
+
assert_raises(Spec::Expectations::ExpectationNotMetError) do
|
73
73
|
n.should_be_an_instance_of String
|
74
74
|
end
|
75
75
|
end
|
@@ -83,7 +83,7 @@ module Spec
|
|
83
83
|
|
84
84
|
def test_is_a_kind_of_should_work_when_failing
|
85
85
|
n = 10
|
86
|
-
assert_raises(Spec::
|
86
|
+
assert_raises(Spec::Expectations::ExpectationNotMetError) do
|
87
87
|
n.should_be_a_kind_of Float
|
88
88
|
end
|
89
89
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Expectations
|
5
|
+
module Helper
|
6
|
+
class SupportedSymbolsTest < Test::Unit::TestCase
|
7
|
+
def test_should_support_less_than
|
8
|
+
"<".to_sym.should_be_supported_by_rspec
|
9
|
+
end
|
10
|
+
def test_should_support_less_than_or_equal_to
|
11
|
+
"<=".to_sym.should_be_supported_by_rspec
|
12
|
+
end
|
13
|
+
def test_should_support_greater_than_or_equal_to
|
14
|
+
">=".to_sym.should_be_supported_by_rspec
|
15
|
+
end
|
16
|
+
def test_should_support_greater_than
|
17
|
+
">".to_sym.should_be_supported_by_rspec
|
18
|
+
end
|
19
|
+
def test_should_support_equals_operator
|
20
|
+
"==".to_sym.should_be_supported_by_rspec
|
21
|
+
end
|
22
|
+
def test_should_support_regex_match_operator
|
23
|
+
"=~".to_sym.should_be_supported_by_rspec
|
24
|
+
end
|
25
|
+
end
|
26
|
+
class SupportedSymbolsTest < Test::Unit::TestCase
|
27
|
+
def test_should_not_support_not_equals_operator
|
28
|
+
"!=".to_sym.should_not_be_supported_by_rspec
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
module Spec
|
4
|
-
module
|
4
|
+
module Mocks
|
5
5
|
class PassingMockArgumentConstraintsTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def setup
|
@@ -63,8 +63,8 @@ module Spec
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_should_match_user_defined_type
|
66
|
-
@mock.should_receive(:random_call).with(Person.new("David"))
|
67
|
-
@mock.random_call(Person.new("David"))
|
66
|
+
@mock.should_receive(:random_call).with(Expectations::Person.new("David"))
|
67
|
+
@mock.random_call(Expectations::Person.new("David"))
|
68
68
|
@mock.__verify
|
69
69
|
end
|
70
70
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
module Spec
|
4
|
-
module
|
4
|
+
module Mocks
|
5
5
|
class MockTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def setup
|
@@ -16,7 +16,7 @@ module Spec
|
|
16
16
|
begin
|
17
17
|
@mock.__verify
|
18
18
|
rescue MockExpectationError => e
|
19
|
-
e.backtrace[0].should_match
|
19
|
+
e.backtrace[0].should_match(/mock_test\.rb:12:in .test_should_report_line/)
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -26,10 +26,26 @@ module Spec
|
|
26
26
|
@mock.__verify
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_should_pass_when_receiving_message_specified_as_not_to_be_received_with_different_args
|
30
|
+
@mock.should_not_receive(:message).with("unwanted text")
|
31
|
+
@mock.should_receive(:message).with("other text")
|
32
|
+
@mock.message "other text"
|
33
|
+
@mock.__verify
|
34
|
+
end
|
35
|
+
|
29
36
|
def test_should_fail_when_receiving_message_specified_as_not_to_be_received
|
30
37
|
@mock.should_not_receive(:not_expected)
|
38
|
+
@mock.not_expected
|
31
39
|
assert_raise(MockExpectationError) do
|
32
|
-
@mock.
|
40
|
+
@mock.__verify
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_fail_when_receiving_message_specified_as_not_to_be_received_with_args
|
45
|
+
@mock.should_not_receive(:not_expected).with("unexpected text")
|
46
|
+
@mock.not_expected "unexpected text"
|
47
|
+
assert_raise(MockExpectationError) do
|
48
|
+
@mock.__verify
|
33
49
|
end
|
34
50
|
end
|
35
51
|
|
@@ -75,7 +91,7 @@ module Spec
|
|
75
91
|
end
|
76
92
|
|
77
93
|
def test_should_fail_if_expectation_block_fails
|
78
|
-
@mock.should_receive(:random_call) {| a | a.should_be true}
|
94
|
+
@mock.should_receive(:random_call).with(true)# {| a | a.should_be true}
|
79
95
|
assert_raise(MockExpectationError) do
|
80
96
|
@mock.random_call false
|
81
97
|
end
|
@@ -83,7 +99,6 @@ module Spec
|
|
83
99
|
|
84
100
|
def test_should_fail_when_method_defined_as_never_is_received
|
85
101
|
@mock.should_receive(:random_call).never
|
86
|
-
#TODO - @mock.should_not_receive(:random_call)
|
87
102
|
assert_raise(MockExpectationError) do
|
88
103
|
@mock.random_call
|
89
104
|
@mock.__verify
|
@@ -113,7 +128,7 @@ module Spec
|
|
113
128
|
|
114
129
|
def test_should_raise_when_explicit_return_and_block_constrained
|
115
130
|
assert_raise(AmbiguousReturnError) {
|
116
|
-
@mock.should_receive(:fruit){|colour|
|
131
|
+
@mock.should_receive(:fruit) {|colour|
|
117
132
|
:strawberry
|
118
133
|
}.and_return :apple
|
119
134
|
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
|
3
3
|
module Spec
|
4
|
-
module
|
4
|
+
module Mocks
|
5
5
|
|
6
6
|
class NullObjectMockTest < Test::Unit::TestCase
|
7
7
|
|
@@ -26,6 +26,12 @@ module Spec
|
|
26
26
|
@mock.__verify
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_should_pass_when_receiving_message_specified_as_not_to_be_received_with_different_args
|
31
|
+
@mock.should_not_receive(:message).with("unwanted text")
|
32
|
+
@mock.message "other text"
|
33
|
+
@mock.__verify
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
module Spec
|
3
|
-
module Runner
|
4
|
-
class
|
3
|
+
module Runner
|
4
|
+
class NoisyBacktraceTweakerTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@error = RuntimeError.new
|
7
7
|
@tweaker = NoisyBacktraceTweaker.new
|
@@ -17,16 +17,18 @@ module Spec
|
|
17
17
|
@error.backtrace[0].should_equal "./examples/airport_spec.rb:28:in `spec name'"
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
@error.set_backtrace ["/lib/spec/
|
20
|
+
def test_should_leave_anything_in_spec_dir
|
21
|
+
@error.set_backtrace ["/lib/spec/expectations/anything.rb"]
|
22
22
|
@tweaker.tweak_backtrace @error, 'spec name'
|
23
|
-
@error.backtrace
|
23
|
+
@error.backtrace.should_not_be_empty
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def test_should_leave_anything_in_lib_spec_dir
|
27
|
+
['expectations', 'mocks', 'runner', 'stubs'].each do |child|
|
28
|
+
@error.set_backtrace ["/lib/spec/#{child}/anything.rb"]
|
29
|
+
@tweaker.tweak_backtrace @error, 'spec name'
|
30
|
+
@error.backtrace.should_not_be_empty
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_should_leave_bin_spec
|
@@ -53,16 +55,16 @@ module Spec
|
|
53
55
|
@error.backtrace[0].should_equal "./examples/airport_spec.rb:28:in `spec name'"
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
def test_should_remove_anything_in_lib_spec_dir
|
59
|
+
element = nil # Workaround to make test2spec work for our own tests
|
60
|
+
['expectations', 'mocks', 'runner', 'stubs'].each do |child|
|
61
|
+
element = "/lib/spec/#{child}/anything.rb"
|
62
|
+
@error.set_backtrace [element]
|
63
|
+
@tweaker.tweak_backtrace @error, 'spec name'
|
64
|
+
if !@error.backtrace.empty?
|
65
|
+
raise "Should have tweaked away '#{element}'"
|
66
|
+
end
|
67
|
+
end
|
66
68
|
end
|
67
69
|
|
68
70
|
def test_should_remove_bin_spec
|
@@ -5,9 +5,9 @@ module Spec
|
|
5
5
|
class ContextMatchingTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def setup
|
8
|
-
@formatter =
|
8
|
+
@formatter = Spec::Mocks::Mock.new "formatter"
|
9
9
|
@context = Context.new("context") {}
|
10
|
-
@matcher = Spec::
|
10
|
+
@matcher = Spec::Mocks::Mock.new("matcher")
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_should_use_spec_matcher
|
@@ -5,14 +5,14 @@ module Spec
|
|
5
5
|
class ContextRunnerTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_should_call_run_on_context
|
8
|
-
context1 =
|
9
|
-
context2 =
|
8
|
+
context1 = Spec::Mocks::Mock.new "context1", :null_object=>true
|
9
|
+
context2 = Spec::Mocks::Mock.new "context2", :null_object=>true
|
10
10
|
context1.should_receive(:run)
|
11
11
|
context1.should_receive(:number_of_specs).and_return(0)
|
12
12
|
context2.should_receive(:run)
|
13
13
|
context2.should_receive(:number_of_specs).and_return(0)
|
14
14
|
|
15
|
-
reporter =
|
15
|
+
reporter = Spec::Mocks::Mock.new 'reporter'
|
16
16
|
reporter.should_receive(:start).with(0)
|
17
17
|
reporter.should_receive(:end)
|
18
18
|
reporter.should_receive(:dump)
|
@@ -29,18 +29,18 @@ module Spec
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_should_support_single_spec
|
32
|
-
desired_context =
|
32
|
+
desired_context = Spec::Mocks::Mock.new "desired context"
|
33
33
|
desired_context.should_receive(:matches?).at_least(:once).and_return(true)
|
34
34
|
desired_context.should_receive(:run)
|
35
35
|
desired_context.should_receive(:run_single_spec)
|
36
36
|
desired_context.should_receive(:number_of_specs).and_return(1)
|
37
37
|
|
38
|
-
other_context =
|
38
|
+
other_context = Spec::Mocks::Mock.new "other context"
|
39
39
|
other_context.should_receive(:matches?).and_return(false)
|
40
40
|
other_context.should_receive(:run).never
|
41
41
|
other_context.should_receive(:number_of_specs).never
|
42
42
|
|
43
|
-
reporter =
|
43
|
+
reporter = Spec::Mocks::Mock.new 'reporter'
|
44
44
|
|
45
45
|
runner = ContextRunner.new(reporter, false, false, "desired context legal spec")
|
46
46
|
runner.add_context desired_context
|
@@ -5,22 +5,39 @@ module Spec
|
|
5
5
|
class ExecutionContextTest < Test::Unit::TestCase
|
6
6
|
|
7
7
|
def test_should_add_new_mock_to_spec_when_mock_message_received
|
8
|
-
spec =
|
9
|
-
spec.should_receive(:add_mock) {|mock| mock.instance_of?
|
8
|
+
spec = Spec::Mocks::Mock.new "spec"
|
9
|
+
spec.should_receive(:add_mock) {|mock| mock.instance_of? Spec::Mocks::Mock}
|
10
10
|
ec = ExecutionContext.new spec
|
11
11
|
mock = ec.mock("a mock", :null_object=>true)
|
12
12
|
end
|
13
|
+
|
14
|
+
def test_stub__should_stub_object_with_a_method
|
15
|
+
spec = Spec::Mocks::Mock.new "spec"
|
16
|
+
stub_space = Spec::Mocks::Mock.new "stub_space"
|
17
|
+
spec.should_receive(:stub_space) {stub_space}
|
18
|
+
target = Object.new
|
19
|
+
name = "foobar"
|
20
|
+
expected_stub = Object.new
|
21
|
+
stub_space.
|
22
|
+
should_receive(:create_stub).
|
23
|
+
once.
|
24
|
+
with(target, name).
|
25
|
+
and_return {expected_stub}
|
26
|
+
ec = ExecutionContext.new spec
|
27
|
+
stub = ec.stub(target, name)
|
28
|
+
assert_equal expected_stub, stub
|
29
|
+
end
|
13
30
|
|
14
31
|
def test_violated
|
15
|
-
assert_raise(Spec::
|
32
|
+
assert_raise(Spec::Expectations::ExpectationNotMetError) do
|
16
33
|
ExecutionContext.new(nil).violated
|
17
34
|
end
|
18
35
|
end
|
19
36
|
|
20
37
|
def test_duck_type
|
21
|
-
ec = ExecutionContext.new(
|
38
|
+
ec = ExecutionContext.new(Spec::Mocks::Mock.new("spec", :null_object => true))
|
22
39
|
duck_type = ec.duck_type(:length)
|
23
|
-
assert duck_type.is_a?(
|
40
|
+
assert duck_type.is_a?(Spec::Mocks::DuckTypeArgConstraint)
|
24
41
|
assert duck_type.matches?([])
|
25
42
|
end
|
26
43
|
end
|