rspec 0.5.16 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGES +12 -0
  2. data/EXAMPLES.rd +2 -2
  3. data/examples/custom_method_spec.rb +2 -2
  4. data/examples/mocking_spec.rb +2 -2
  5. data/lib/spec/api/helper.rb +0 -6
  6. data/lib/spec/api/helper/diff.rb +1 -0
  7. data/lib/spec/api/helper/have_helper.rb +7 -23
  8. data/lib/spec/api/helper/should_helper.rb +23 -19
  9. data/lib/spec/api/helper/should_negator.rb +10 -18
  10. data/lib/spec/api/mocks/argument_expectation.rb +2 -2
  11. data/lib/spec/api/mocks/message_expectation.rb +28 -53
  12. data/lib/spec/api/mocks/mock.rb +4 -5
  13. data/lib/spec/api/sugar.rb +6 -23
  14. data/lib/spec/runner/instance_exec.rb +11 -5
  15. data/lib/spec/version.rb +2 -2
  16. data/test/spec/api/helper/arbitrary_predicate_test.rb +16 -16
  17. data/test/spec/api/helper/containment_test.rb +16 -16
  18. data/test/spec/api/helper/identity_test.rb +8 -8
  19. data/test/spec/api/helper/object_equality_test.rb +13 -13
  20. data/test/spec/api/helper/raising_test.rb +14 -14
  21. data/test/spec/api/helper/regex_matching_test.rb +4 -4
  22. data/test/spec/api/helper/should_have_test.rb +26 -20
  23. data/test/spec/api/helper/should_satisfy_test.rb +5 -5
  24. data/test/spec/api/helper/throwing_test.rb +7 -7
  25. data/test/spec/api/helper/true_false_special_case_test.rb +12 -12
  26. data/test/spec/api/helper/typing_test.rb +14 -14
  27. data/test/spec/api/mocks/mock_arg_constraints_test.rb +26 -20
  28. data/test/spec/api/mocks/mock_counts_test.rb +431 -0
  29. data/test/spec/api/mocks/mock_ordering_test.rb +61 -42
  30. data/test/spec/api/mocks/mock_test.rb +68 -230
  31. data/test/spec/api/sugar_test.rb +1 -1
  32. data/test/spec/runner/backtrace_tweaker_test.rb +2 -2
  33. data/test/spec/runner/context_runner_test.rb +4 -4
  34. data/test/spec/runner/context_test.rb +22 -22
  35. data/test/spec/runner/execution_context_test.rb +1 -1
  36. data/test/spec/runner/reporter_test.rb +6 -6
  37. data/test/spec/runner/specification_test.rb +30 -30
  38. data/test/test_classes.rb +13 -4
  39. metadata +6 -11
  40. data/lib/spec/api/helper/instance_helper.rb +0 -15
  41. data/lib/spec/api/helper/instance_negator.rb +0 -15
  42. data/lib/spec/api/helper/kind_helper.rb +0 -15
  43. data/lib/spec/api/helper/kind_negator.rb +0 -15
  44. data/lib/spec/api/helper/respond_helper.rb +0 -15
  45. data/lib/spec/api/helper/respond_negator.rb +0 -15
  46. data/test/spec/api/duck_type_test.rb +0 -19
@@ -1,14 +1,20 @@
1
- # http://eigenclass.org/hiki.rb?cmd=view&p=instance_exec&key=instance_exec
1
+ # http://eigenclass.org/hiki.rb?bounded+space+instance_exec
2
2
  class Object
3
3
  module InstanceExecHelper; end
4
4
  include InstanceExecHelper
5
- def instance_exec(*args, &block) # !> method redefined; discarding old instance_exec
6
- mname = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}"
7
- InstanceExecHelper.module_eval{ define_method(mname, &block) }
5
+ def instance_exec(*args, &block)
6
+ begin
7
+ old_critical, Thread.critical = Thread.critical, true
8
+ n = 0
9
+ n += 1 while respond_to?(mname="__instance_exec#{n}")
10
+ InstanceExecHelper.module_eval{ define_method(mname, &block) }
11
+ ensure
12
+ Thread.critical = old_critical
13
+ end
8
14
  begin
9
15
  ret = send(mname, *args)
10
16
  ensure
11
- InstanceExecHelper.module_eval{ undef_method(mname) } rescue nil
17
+ InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
12
18
  end
13
19
  ret
14
20
  end
@@ -2,8 +2,8 @@ module Spec
2
2
  module VERSION
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
- MINOR = 5
6
- TINY = 16
5
+ MINOR = 6
6
+ TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -6,18 +6,18 @@ module Spec
6
6
 
7
7
  class ArbitraryPredicateTest < Test::Unit::TestCase
8
8
 
9
- # should.be.funny
9
+ # should_be_funny
10
10
 
11
11
  def test_should_be_funny_should_raise_when_target_doesnt_understand_funny
12
12
  assert_raise(NoMethodError) do
13
- 5.should.be.funny
13
+ 5.should_be_funny
14
14
  end
15
15
  end
16
16
 
17
17
  def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_false
18
18
  mock = HandCodedMock.new(false)
19
19
  assert_raise(ExpectationNotMetError) do
20
- mock.should.be.funny
20
+ mock.should_be_funny
21
21
  end
22
22
  mock.__verify
23
23
  end
@@ -25,7 +25,7 @@ module Spec
25
25
  def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_nil
26
26
  mock = HandCodedMock.new(nil)
27
27
  assert_raise(ExpectationNotMetError) do
28
- mock.should.be.funny
28
+ mock.should_be_funny
29
29
  end
30
30
  mock.__verify
31
31
  end
@@ -33,7 +33,7 @@ module Spec
33
33
  def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_true
34
34
  mock = HandCodedMock.new(true)
35
35
  assert_nothing_raised do
36
- mock.should.be.funny
36
+ mock.should_be_funny
37
37
  end
38
38
  mock.__verify
39
39
  end
@@ -41,33 +41,33 @@ module Spec
41
41
  def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
42
42
  mock = HandCodedMock.new(5)
43
43
  assert_nothing_raised do
44
- mock.should.be.funny
44
+ mock.should_be_funny
45
45
  end
46
46
  mock.__verify
47
47
  end
48
48
 
49
- # should.be.funny(args)
49
+ # should_be_funny(args)
50
50
 
51
51
  def test_should_be_funny_with_args_passes_args_properly
52
52
  mock = HandCodedMock.new(true)
53
53
  assert_nothing_raised do
54
- mock.should.be.hungry(1, 2, 3)
54
+ mock.should_be_hungry(1, 2, 3)
55
55
  end
56
56
  mock.__verify
57
57
  end
58
58
 
59
- # should.not.be.funny
59
+ # should_not_be_funny
60
60
 
61
61
  def test_should_not_be_funny_should_raise_when_target_doesnt_understand_funny
62
62
  assert_raise(NoMethodError) do
63
- 5.should.not.be.funny
63
+ 5.should_not_be_funny
64
64
  end
65
65
  end
66
66
 
67
67
  def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_true
68
68
  mock = HandCodedMock.new(true)
69
69
  assert_raise(ExpectationNotMetError) do
70
- mock.should.not.be.funny
70
+ mock.should_not_be_funny
71
71
  end
72
72
  mock.__verify
73
73
  end
@@ -75,7 +75,7 @@ module Spec
75
75
  def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_nil
76
76
  mock = HandCodedMock.new(nil)
77
77
  assert_nothing_raised do
78
- mock.should.not.be.funny
78
+ mock.should_not_be_funny
79
79
  end
80
80
  mock.__verify
81
81
  end
@@ -83,7 +83,7 @@ module Spec
83
83
  def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_false
84
84
  mock = HandCodedMock.new(false)
85
85
  assert_nothing_raised do
86
- mock.should.not.be.funny
86
+ mock.should_not_be_funny
87
87
  end
88
88
  mock.__verify
89
89
  end
@@ -91,17 +91,17 @@ module Spec
91
91
  def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
92
92
  mock = HandCodedMock.new(5)
93
93
  assert_raise(ExpectationNotMetError) do
94
- mock.should.not.be.funny
94
+ mock.should_not_be_funny
95
95
  end
96
96
  mock.__verify
97
97
  end
98
98
 
99
- # should.be.funny(args)
99
+ # should_be_funny(args)
100
100
 
101
101
  def test_should_not_be_funny_with_args_passes_args_properly
102
102
  mock = HandCodedMock.new(false)
103
103
  assert_nothing_raised do
104
- mock.should.not.be.hungry(1, 2, 3)
104
+ mock.should_not_be_hungry(1, 2, 3)
105
105
  end
106
106
  mock.__verify
107
107
  end
@@ -16,49 +16,49 @@ module Spec
16
16
 
17
17
  def test_should_include_shouldnt_raise_when_string_inclusion_is_present
18
18
  assert_nothing_raised do
19
- @dummy.should.include "mm"
19
+ @dummy.should_include "mm"
20
20
  end
21
21
  end
22
22
 
23
23
  def test_should_include_should_raise_when_string_inclusion_is_missing
24
24
  assert_raise(ExpectationNotMetError) do
25
- @dummy.should.include "abc"
25
+ @dummy.should_include "abc"
26
26
  end
27
27
  end
28
28
 
29
29
  def test_should_include_shouldnt_raise_when_array_inclusion_is_present
30
30
  assert_nothing_raised do
31
- [1, 2, 3].should.include 2
31
+ [1, 2, 3].should_include 2
32
32
  end
33
33
  end
34
34
 
35
35
  def test_should_include_should_raise_when_array_inclusion_is_missing
36
36
  assert_raise(ExpectationNotMetError) do
37
- [1, 2, 3].should.include 5
37
+ [1, 2, 3].should_include 5
38
38
  end
39
39
  end
40
40
 
41
41
  def test_should_include_shouldnt_raise_when_hash_inclusion_is_present
42
42
  assert_nothing_raised do
43
- {"a"=>1}.should.include "a"
43
+ {"a"=>1}.should_include "a"
44
44
  end
45
45
  end
46
46
 
47
47
  def test_should_include_should_raise_when_hash_inclusion_is_missing
48
48
  assert_raise(ExpectationNotMetError) do
49
- {"a"=>1}.should.include "b"
49
+ {"a"=>1}.should_include "b"
50
50
  end
51
51
  end
52
52
 
53
53
  def test_should_include_shouldnt_raise_when_enumerable_inclusion_is_present
54
54
  assert_nothing_raised do
55
- IO.constants.should.include "SEEK_SET"
55
+ IO.constants.should_include "SEEK_SET"
56
56
  end
57
57
  end
58
58
 
59
59
  def test_should_include_should_raise_when_enumerable_inclusion_is_missing
60
60
  assert_raise(ExpectationNotMetError) do
61
- IO.constants.should.include "BLAH"
61
+ IO.constants.should_include "BLAH"
62
62
  end
63
63
  end
64
64
 
@@ -66,49 +66,49 @@ module Spec
66
66
 
67
67
  def test_should_not_include_shouldnt_raise_when_string_inclusion_is_missing
68
68
  assert_nothing_raised do
69
- @dummy.should.not.include "abc"
69
+ @dummy.should_not_include "abc"
70
70
  end
71
71
  end
72
72
 
73
73
  def test_should_not_include_should_raise_when_string_inclusion_is_present
74
74
  assert_raise(ExpectationNotMetError) do
75
- @dummy.should.not.include "mm"
75
+ @dummy.should_not_include "mm"
76
76
  end
77
77
  end
78
78
 
79
79
  def test_should_not_include_shouldnt_raise_when_array_inclusion_is_missing
80
80
  assert_nothing_raised do
81
- [1, 2, 3].should.not.include 5
81
+ [1, 2, 3].should_not_include 5
82
82
  end
83
83
  end
84
84
 
85
85
  def test_should_not_include_should_raise_when_array_inclusion_is_present
86
86
  assert_raise(ExpectationNotMetError) do
87
- [1, 2, 3].should.not.include 2
87
+ [1, 2, 3].should_not_include 2
88
88
  end
89
89
  end
90
90
 
91
91
  def test_should_not_include_shouldnt_raise_when_hash_inclusion_is_missing
92
92
  assert_nothing_raised do
93
- {"a"=>1}.should.not.include "b"
93
+ {"a"=>1}.should_not_include "b"
94
94
  end
95
95
  end
96
96
 
97
97
  def test_should_not_include_should_raise_when_hash_inclusion_is_present
98
98
  assert_raise(ExpectationNotMetError) do
99
- {"a"=>1}.should.not.include "a"
99
+ {"a"=>1}.should_not_include "a"
100
100
  end
101
101
  end
102
102
 
103
103
  def test_should_not_include_shouldnt_raise_when_enumerable_inclusion_is_present
104
104
  assert_nothing_raised do
105
- IO.constants.should.not.include "BLAH"
105
+ IO.constants.should_not_include "BLAH"
106
106
  end
107
107
  end
108
108
 
109
109
  def test_should_not_include_should_raise_when_enumerable_inclusion_is_missing
110
110
  assert_raise(ExpectationNotMetError) do
111
- IO.constants.should.not.include "SEEK_SET"
111
+ IO.constants.should_not_include "SEEK_SET"
112
112
  end
113
113
  end
114
114
  end
@@ -14,25 +14,25 @@ module Spec
14
14
 
15
15
  def test_should_not_raise_when_objects_are_same
16
16
  assert_nothing_raised do
17
- @dummy.should.be @dummy
17
+ @dummy.should_be @dummy
18
18
  end
19
19
  end
20
20
 
21
21
  def test_should_raise_when_objects_are_not_same
22
22
  assert_raise(ExpectationNotMetError) do
23
- @dummy.should.be @equal_dummy
23
+ @dummy.should_be @equal_dummy
24
24
  end
25
25
  end
26
26
 
27
27
  def test_should_not_raise_when_both_objects_are_nil
28
28
  assert_nothing_raised do
29
- @nil_var.should.be nil
29
+ @nil_var.should_be nil
30
30
  end
31
31
  end
32
32
 
33
33
  def test_should_raise_when_object_is_not_nil
34
34
  assert_raise(ExpectationNotMetError) do
35
- @dummy.should.be nil
35
+ @dummy.should_be nil
36
36
  end
37
37
  end
38
38
  end
@@ -47,25 +47,25 @@ module Spec
47
47
 
48
48
  def test_should_not_raise_when_objects_are_not_same
49
49
  assert_nothing_raised do
50
- @dummy.should.not.be @equal_dummy
50
+ @dummy.should_not_be @equal_dummy
51
51
  end
52
52
  end
53
53
 
54
54
  def test_should_raise_when_objects_are_same
55
55
  assert_raise(ExpectationNotMetError) do
56
- @dummy.should.not.be @dummy
56
+ @dummy.should_not_be @dummy
57
57
  end
58
58
  end
59
59
 
60
60
  def test_should_not_raise_when_left_is_not_nil_and_right_is_nil
61
61
  assert_nothing_raised do
62
- @dummy.should.not.be nil
62
+ @dummy.should_not_be nil
63
63
  end
64
64
  end
65
65
 
66
66
  def test_should_raise_when_both_objects_are_nil
67
67
  assert_raise(ExpectationNotMetError) do
68
- @nil_var.should.not.be nil
68
+ @nil_var.should_not_be nil
69
69
  end
70
70
  end
71
71
 
@@ -7,13 +7,13 @@ module Spec
7
7
 
8
8
  def test_should_not_raise_when_objects_are_equal
9
9
  assert_nothing_raised do
10
- 'apple'.should.equal 'apple'
10
+ 'apple'.should_equal 'apple'
11
11
  end
12
12
  end
13
13
 
14
14
  def test_should_raise_when_objects_are_not_equal
15
15
  assert_raise(ExpectationNotMetError) do
16
- 'apple'.should.equal 'orange'
16
+ 'apple'.should_equal 'orange'
17
17
  end
18
18
  end
19
19
  end
@@ -22,13 +22,13 @@ module Spec
22
22
 
23
23
  def test_should_not_raise_when_objects_are_not_equal
24
24
  assert_nothing_raised do
25
- 'apple'.should.not.equal 'orange'
25
+ 'apple'.should_not_equal 'orange'
26
26
  end
27
27
  end
28
28
 
29
29
  def test_should_not_equal_should_raise_when_objects_are_equal
30
30
  assert_raise(ExpectationNotMetError) do
31
- 'apple'.should.not.equal 'apple'
31
+ 'apple'.should_not_equal 'apple'
32
32
  end
33
33
  end
34
34
  end
@@ -36,26 +36,26 @@ module Spec
36
36
  class ShouldBeCloseTest < Test::Unit::TestCase
37
37
  def test_should_not_raise_when_values_are_within_bounds
38
38
  assert_nothing_raised do
39
- 3.5.should.be.close 3.5, 0.5
40
- 3.5.should.be.close 3.1, 0.5
41
- 3.5.should.be.close 3.01, 0.5
42
- 3.5.should.be.close 3.9, 0.5
43
- 3.5.should.be.close 3.99, 0.5
39
+ 3.5.should_be_close 3.5, 0.5
40
+ 3.5.should_be_close 3.1, 0.5
41
+ 3.5.should_be_close 3.01, 0.5
42
+ 3.5.should_be_close 3.9, 0.5
43
+ 3.5.should_be_close 3.99, 0.5
44
44
  end
45
45
  end
46
46
 
47
47
  def test_should_raise_when_values_are_outside_bounds
48
48
  assert_raise(ExpectationNotMetError) do
49
- 3.5.should.be.close 3.0, 0.5
49
+ 3.5.should_be_close 3.0, 0.5
50
50
  end
51
51
  assert_raise(ExpectationNotMetError) do
52
- 3.5.should.be.close 2.0, 0.5
52
+ 3.5.should_be_close 2.0, 0.5
53
53
  end
54
54
  assert_raise(ExpectationNotMetError) do
55
- 3.5.should.be.close 4.0, 0.5
55
+ 3.5.should_be_close 4.0, 0.5
56
56
  end
57
57
  assert_raise(ExpectationNotMetError) do
58
- 3.5.should.be.close 5.0, 0.5
58
+ 3.5.should_be_close 5.0, 0.5
59
59
  end
60
60
  end
61
61
 
@@ -7,31 +7,31 @@ module Spec
7
7
 
8
8
  def test_should_pass_when_exact_exception_is_raised
9
9
  assert_nothing_raised do
10
- proc { ''.nonexistent_method }.should.raise NoMethodError
10
+ proc { ''.nonexistent_method }.should_raise NoMethodError
11
11
  end
12
12
  end
13
13
 
14
14
  def test_should_pass_when_exact_exception_is_raised_with_message
15
15
  assert_nothing_raised do
16
- lambda { raise StandardError.new("this is standard") }.should.raise StandardError, "this is standard"
16
+ lambda { raise StandardError.new("this is standard") }.should_raise StandardError, "this is standard"
17
17
  end
18
18
  end
19
19
 
20
20
  def test_should_fail_when_exact_exception_is_raised_with_wrong_message
21
21
  assert_raises(Spec::Api::ExpectationNotMetError) do
22
- lambda { raise StandardError.new("chunky bacon") }.should.raise StandardError, "rotten tomatoes"
22
+ lambda { raise StandardError.new("chunky bacon") }.should_raise StandardError, "rotten tomatoes"
23
23
  end
24
24
  end
25
25
 
26
26
  def test_should_pass_when_subclass_exception_is_raised
27
27
  assert_nothing_raised do
28
- proc { ''.nonexistent_method }.should.raise
28
+ proc { ''.nonexistent_method }.should_raise
29
29
  end
30
30
  end
31
31
 
32
32
  def test_should_fail_when_wrong_exception_is_raised
33
33
  begin
34
- proc { ''.nonexistent_method }.should.raise SyntaxError
34
+ proc { ''.nonexistent_method }.should_raise SyntaxError
35
35
  rescue => e
36
36
  end
37
37
  assert_equal("<Proc> should raise <SyntaxError> but raised #<NoMethodError: undefined method `nonexistent_method' for \"\":String>", e.message)
@@ -39,7 +39,7 @@ module Spec
39
39
 
40
40
  def test_should_fail_when_no_exception_is_raised
41
41
  begin
42
- proc { }.should.raise SyntaxError
42
+ proc { }.should_raise SyntaxError
43
43
  rescue => e
44
44
  end
45
45
  assert_equal("<Proc> should raise <SyntaxError> but raised nothing", e.message)
@@ -50,37 +50,37 @@ module Spec
50
50
 
51
51
  def test_should_pass_when_exact_exception_is_raised_with_wrong_message
52
52
  assert_nothing_raised do
53
- lambda { raise StandardError.new("abc") }.should.not.raise StandardError, "xyz"
53
+ lambda { raise StandardError.new("abc") }.should_not_raise StandardError, "xyz"
54
54
  end
55
55
  end
56
56
 
57
57
  def test_should_faile_when_exact_exception_is_raised_with_message
58
58
  assert_raises(Spec::Api::ExpectationNotMetError) do
59
- lambda { raise StandardError.new("abc") }.should.not.raise StandardError, "abc"
59
+ lambda { raise StandardError.new("abc") }.should_not_raise StandardError, "abc"
60
60
  end
61
61
  end
62
62
 
63
63
  def test_should_pass_when_other_exception_is_raised
64
64
  assert_nothing_raised do
65
- proc { ''.nonexistent_method }.should.not.raise SyntaxError
65
+ proc { ''.nonexistent_method }.should_not_raise SyntaxError
66
66
  end
67
67
  end
68
68
 
69
69
  def test_should_pass_when_no_exception_is_raised
70
70
  assert_nothing_raised do
71
- proc { ''.to_s }.should.not.raise NoMethodError
71
+ proc { ''.to_s }.should_not_raise NoMethodError
72
72
  end
73
73
  end
74
74
 
75
75
  def test_without_exception_should_pass_when_no_exception_is_raised
76
76
  assert_nothing_raised do
77
- proc { ''.to_s }.should.not.raise
77
+ proc { ''.to_s }.should_not_raise
78
78
  end
79
79
  end
80
80
 
81
81
  def test_should_fail_when_specific_exception_is_raised
82
82
  begin
83
- proc { ''.nonexistent_method }.should.not.raise NoMethodError
83
+ proc { ''.nonexistent_method }.should_not_raise NoMethodError
84
84
  rescue => e
85
85
  end
86
86
  assert_equal("<Proc> should not raise <NoMethodError>", e.message)
@@ -88,7 +88,7 @@ module Spec
88
88
 
89
89
  def test_should_include_actual_error_in_failure_message
90
90
  begin
91
- proc { ''.nonexistent_method }.should.not.raise Exception
91
+ proc { ''.nonexistent_method }.should_not_raise Exception
92
92
  rescue => e
93
93
  end
94
94
  assert_equal("<Proc> should not raise <Exception> but raised #<NoMethodError: undefined method `nonexistent_method' for \"\":String>", e.message)
@@ -97,7 +97,7 @@ module Spec
97
97
  def TODOtest_should_understand_raised_with_message_matching
98
98
  lambda do
99
99
  raise 'Hello'
100
- end.should.raise(StandardError).with.message.matching /ello/
100
+ end.should_raise(StandardError).with.message.matching /ello/
101
101
  end
102
102
 
103
103
  end