rspec 0.6.3 → 0.6.4

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.
Files changed (90) hide show
  1. data/CHANGES +28 -3
  2. data/EXAMPLES.rd +2 -16
  3. data/README +5 -2
  4. data/Rakefile +8 -4
  5. data/bin/spec +1 -0
  6. data/examples/custom_formatter.rb +2 -1
  7. data/examples/helper_method_spec.rb +12 -0
  8. data/examples/{mocking_spec.rb → mocking_example.rb} +0 -0
  9. data/examples/{bdd_framework_spec.rb → predicate_example.rb} +0 -0
  10. data/examples/stubbing_example.rb +28 -0
  11. data/lib/spec.rb +2 -1
  12. data/lib/spec/expectations.rb +7 -0
  13. data/lib/spec/expectations/diff.rb +56 -0
  14. data/lib/spec/expectations/exceptions.rb +6 -0
  15. data/lib/spec/expectations/expectations.rb +19 -0
  16. data/lib/spec/expectations/have_helper.rb +41 -0
  17. data/lib/spec/expectations/helper.rb +4 -0
  18. data/lib/spec/expectations/should_base.rb +52 -0
  19. data/lib/spec/expectations/should_helper.rb +93 -0
  20. data/lib/spec/expectations/should_negator.rb +71 -0
  21. data/lib/spec/{api → expectations}/sugar.rb +8 -8
  22. data/lib/spec/mocks.rb +5 -0
  23. data/lib/spec/{api/mocks → mocks}/argument_expectation.rb +1 -1
  24. data/lib/spec/{api → mocks}/exceptions.rb +3 -5
  25. data/lib/spec/{api/mocks → mocks}/message_expectation.rb +15 -9
  26. data/lib/spec/{api/mocks → mocks}/mock.rb +44 -26
  27. data/lib/spec/{api/mocks → mocks}/order_group.rb +1 -1
  28. data/lib/spec/runner/backtrace_tweaker.rb +4 -1
  29. data/lib/spec/runner/execution_context.rb +13 -4
  30. data/lib/spec/runner/formatter/base_text_formatter.rb +26 -13
  31. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  32. data/lib/spec/runner/option_parser.rb +6 -2
  33. data/lib/spec/runner/specification.rb +2 -2
  34. data/lib/spec/test_to_spec/ruby2ruby.rb +1 -1
  35. data/lib/spec/version.rb +1 -1
  36. data/test/spec/expectations/arbitrary_operator_test.rb +55 -0
  37. data/test/spec/expectations/arbitrary_predicate_test.rb +163 -0
  38. data/test/spec/{api/helper → expectations}/containment_test.rb +2 -2
  39. data/test/spec/expectations/diff_test.rb +62 -0
  40. data/test/spec/{api/helper → expectations}/identity_test.rb +2 -2
  41. data/test/spec/{api/helper → expectations}/object_equality_test.rb +2 -2
  42. data/test/spec/{api/helper → expectations}/raising_test.rb +5 -5
  43. data/test/spec/{api/helper → expectations}/regex_matching_test.rb +6 -6
  44. data/test/spec/{api/helper → expectations}/should_have_test.rb +11 -2
  45. data/test/spec/{api/helper → expectations}/should_satisfy_test.rb +2 -4
  46. data/test/spec/{api → expectations}/sugar_test.rb +8 -8
  47. data/test/spec/expectations/supported_symbols_test.rb +33 -0
  48. data/test/spec/{api/helper → expectations}/throwing_test.rb +2 -2
  49. data/test/spec/{api/helper → expectations}/true_false_special_case_test.rb +2 -2
  50. data/test/spec/{api/helper → expectations}/typing_test.rb +2 -2
  51. data/test/spec/{api/mocks → mocks}/mock_arg_constraints_test.rb +4 -4
  52. data/test/spec/{api/mocks → mocks}/mock_counts_test.rb +2 -2
  53. data/test/spec/{api/mocks → mocks}/mock_ordering_test.rb +2 -2
  54. data/test/spec/{api/mocks → mocks}/mock_test.rb +22 -7
  55. data/test/spec/{api/mocks → mocks}/null_object_test.rb +8 -2
  56. data/test/spec/runner/backtrace_tweaker_test.rb +21 -19
  57. data/test/spec/runner/context_matching_test.rb +2 -2
  58. data/test/spec/runner/context_runner_test.rb +6 -6
  59. data/test/spec/runner/context_test.rb +1 -1
  60. data/test/spec/runner/execution_context_test.rb +22 -5
  61. data/test/spec/runner/formatter/failure_dump_test.rb +7 -7
  62. data/test/spec/runner/option_parser_test.rb +20 -0
  63. data/test/spec/runner/reporter_test.rb +3 -3
  64. data/test/spec/runner/specification_test.rb +3 -3
  65. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +4 -4
  66. data/test/spec/test_to_spec/sexp_transformer_test.rb +1 -1
  67. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +2 -2
  68. data/test/test_classes.rb +21 -1
  69. data/test/test_helper.rb +1 -1
  70. data/vendor/selenium/README.txt +23 -0
  71. data/vendor/selenium/find_rspecs_home_page.rb +23 -0
  72. data/vendor/selenium/rspec_selenium.rb +33 -0
  73. data/vendor/watir/README.txt +32 -0
  74. data/vendor/watir/find_rspecs_home_page.rb +21 -0
  75. data/vendor/watir/find_rspecs_home_page.txt +15 -0
  76. data/vendor/watir/rspec_watir.rb +45 -0
  77. metadata +52 -41
  78. data/examples/airport_spec.rb +0 -33
  79. data/examples/custom_method_spec.rb +0 -24
  80. data/examples/sugar_spec.rb +0 -14
  81. data/lib/spec/api.rb +0 -8
  82. data/lib/spec/api/expectations.rb +0 -17
  83. data/lib/spec/api/helper.rb +0 -4
  84. data/lib/spec/api/helper/diff.rb +0 -54
  85. data/lib/spec/api/helper/have_helper.rb +0 -40
  86. data/lib/spec/api/helper/should_base.rb +0 -31
  87. data/lib/spec/api/helper/should_helper.rb +0 -93
  88. data/lib/spec/api/helper/should_negator.rb +0 -72
  89. data/test/spec/api/helper/arbitrary_predicate_test.rb +0 -112
  90. data/test/spec/api/helper/diff_test.rb +0 -60
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Runner
3
3
  class Specification
4
-
4
+
5
5
  def initialize(name, &block)
6
6
  @name = name
7
7
  @block = block
@@ -38,7 +38,7 @@ module Spec
38
38
  def add_mock(mock)
39
39
  @mocks << mock
40
40
  end
41
-
41
+
42
42
  def matches_matcher?(matcher)
43
43
  matcher.matches? @name
44
44
  end
@@ -60,7 +60,6 @@ class Method
60
60
 
61
61
  end
62
62
 
63
-
64
63
  class RubyToRuby < SexpProcessor
65
64
 
66
65
  def self.translate(klass, method=nil)
@@ -75,6 +74,7 @@ class RubyToRuby < SexpProcessor
75
74
 
76
75
  def initialize
77
76
  super
77
+ @block_params = false
78
78
  @indent = " "
79
79
  self.auto_shift_type = true
80
80
  self.strict = true
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 6
6
- TINY = 3
6
+ TINY = 4
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Expectations
5
+ module Helper
6
+
7
+ class ArbitraryOperatorTest < Test::Unit::TestCase
8
+
9
+ # == arg
10
+
11
+ def test_should_pass_when_equals_operator_passes
12
+ assert_nothing_raised do
13
+ (2+2).should == 4
14
+ end
15
+ end
16
+
17
+ def test_should_fail_when_equals_operator_fails
18
+ assert_raise(ExpectationNotMetError) do
19
+ (2+2).should == 5
20
+ end
21
+ end
22
+
23
+ # =~ arg
24
+
25
+ def test_should_pass_when_match_operator_passes
26
+ assert_nothing_raised do
27
+ "foo".should =~ /oo/
28
+ end
29
+ end
30
+
31
+ def test_should_fail_when_match_operator_fails
32
+ assert_raise(ExpectationNotMetError) do
33
+ "fu".should =~ /oo/
34
+ end
35
+ end
36
+
37
+ # < and >
38
+
39
+ def test_should_pass_when_comparison_passes
40
+ assert_nothing_raised do
41
+ 3.should_be < 4
42
+ end
43
+ end
44
+
45
+ def test_should_fail_when_comparison_fails
46
+ assert_raise(ExpectationNotMetError) do
47
+ 3.should_be > 4
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,163 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Expectations
5
+ module Helper
6
+
7
+ class ShouldBeArbitraryPredicateTest < Test::Unit::TestCase
8
+
9
+ # should_be_<predicate>
10
+
11
+ def test_should_pass_when_predicate_returns_true
12
+ mock = HandCodedMock.new(true)
13
+ assert_nothing_raised do
14
+ mock.should_be_funny
15
+ end
16
+ mock.__verify
17
+ end
18
+
19
+ def test_should_fail_when_predicate_returns_false
20
+ mock = HandCodedMock.new(false)
21
+ assert_raise(ExpectationNotMetError) do
22
+ mock.should_be_funny
23
+ end
24
+ end
25
+
26
+ def test_should_fail_when_predicate_returns_nil
27
+ mock = HandCodedMock.new(nil)
28
+ assert_raise(ExpectationNotMetError) do
29
+ mock.should_be_funny
30
+ end
31
+ mock.__verify
32
+ end
33
+
34
+ def test_should_fail_when_method_returns_something_other_than_true_false_or_nil
35
+ mock = HandCodedMock.new(5)
36
+ assert_nothing_raised do
37
+ mock.should_be_funny
38
+ end
39
+ mock.__verify
40
+ end
41
+
42
+ def test_should_raise_when_target_does_not_respond_to_predicate
43
+ assert_raise(NoMethodError) do
44
+ 5.should_be_funny
45
+ end
46
+ end
47
+
48
+ # should_be_funny(args)
49
+
50
+ def test_should_pass_when_predicate_accepts_args_and_returns_true
51
+ mock = HandCodedMock.new(true)
52
+ assert_nothing_raised do
53
+ mock.should_be_hungry(1, 2, 3)
54
+ end
55
+ mock.__verify
56
+ end
57
+
58
+ def test_should_fail_when_predicate_accepts_args_and_returns_false
59
+ mock = HandCodedMock.new(false)
60
+ assert_raise(ExpectationNotMetError) do
61
+ mock.should_be_hungry(1, 2, 3)
62
+ end
63
+ mock.__verify
64
+ end
65
+
66
+ # should_exist => exists?
67
+
68
+ def test_should_support_plural_form
69
+ mock = HandCodedMock.new(true)
70
+ assert_nothing_raised do
71
+ mock.should_exist
72
+ end
73
+ end
74
+
75
+ def test_should_support_multi_word_predicates_with_should
76
+ assert_nothing_raised do
77
+ HandCodedMock.new(true).should_multi_word_predicate
78
+ end
79
+ end
80
+
81
+ def test_should_support_multi_word_predicates_with_should_be
82
+ assert_nothing_raised do
83
+ HandCodedMock.new(true).should_be_multi_word_predicate
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ class ShouldNotBeArbitraryPredicateTest < Test::Unit::TestCase
90
+
91
+ # should_not_be_funny
92
+
93
+ def test_should_pass_when_predicate_returns_false
94
+ mock = HandCodedMock.new(false)
95
+ assert_nothing_raised do
96
+ mock.should_not_be_funny
97
+ end
98
+ mock.__verify
99
+ end
100
+
101
+ def test_should_fail_when_predicate_returns_true
102
+ mock = HandCodedMock.new(true)
103
+ assert_raise(ExpectationNotMetError) do
104
+ mock.should_not_be_funny
105
+ end
106
+ mock.__verify
107
+ end
108
+
109
+ def test_should_pass_when_predicate_returns_nil
110
+ mock = HandCodedMock.new(nil)
111
+ assert_nothing_raised do
112
+ mock.should_not_be_funny
113
+ end
114
+ mock.__verify
115
+ end
116
+
117
+ def test_should_fail_when_method_returns_something_other_than_true_false_or_nil
118
+ mock = HandCodedMock.new(5)
119
+ assert_raise(ExpectationNotMetError) do
120
+ mock.should_not_be_funny
121
+ end
122
+ mock.__verify
123
+ end
124
+
125
+ def test_should_raise_when_target_does_not_respond_to_predicate
126
+ assert_raise(NoMethodError) do
127
+ 5.should_not_be_funny
128
+ end
129
+ end
130
+
131
+ # should_be_funny(args)
132
+
133
+ def test_should_fail_when_predicate_accepts_args_and_returns_true
134
+ mock = HandCodedMock.new(true)
135
+ assert_raise(ExpectationNotMetError) do
136
+ mock.should_not_be_hungry(1, 2, 3)
137
+ end
138
+ mock.__verify
139
+ end
140
+
141
+ def test_should_pass_when_predicate_accepts_args_and_returns_false
142
+ mock = HandCodedMock.new(false)
143
+ assert_nothing_raised do
144
+ mock.should_not_be_hungry(1, 2, 3)
145
+ end
146
+ mock.__verify
147
+ end
148
+
149
+ def test_should_support_multi_word_predicates_with_should
150
+ assert_nothing_raised do
151
+ HandCodedMock.new(false).should_not_multi_word_predicate
152
+ end
153
+ end
154
+
155
+ def test_should_support_multi_word_predicates_with_should_be
156
+ assert_nothing_raised do
157
+ HandCodedMock.new(false).should_not_be_multi_word_predicate
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ContainmentTest < Test::Unit::TestCase
7
7
 
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Expectations
5
+ class DiffTest < Test::Unit::TestCase
6
+ def test_should_output_unified_diff_of_two_strings
7
+ expected = <<-EOF
8
+ foo
9
+ bar
10
+ zap
11
+ this
12
+ is
13
+ soo
14
+ very
15
+ very
16
+ equal
17
+ insert
18
+ a
19
+ line
20
+ EOF
21
+
22
+ actual = <<-EOF
23
+ foo
24
+ zap
25
+ bar
26
+ this
27
+ is
28
+ soo
29
+ very
30
+ very
31
+ equal
32
+ insert
33
+ a
34
+ another
35
+ line
36
+ EOF
37
+
38
+ expected_diff = <<-EOF
39
+
40
+
41
+ @@ -1,6 +1,6 @@
42
+ foo
43
+ -bar
44
+ zap
45
+ +bar
46
+ this
47
+ is
48
+ soo
49
+ @@ -9,5 +9,6 @@
50
+ equal
51
+ insert
52
+ a
53
+ +another
54
+ line
55
+ EOF
56
+
57
+ diff = ShouldBase.new.diff_as_string(expected, actual)
58
+ assert_equal expected_diff, diff
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ShouldBeTest < Test::Unit::TestCase
7
7
 
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ShouldEqualTest < Test::Unit::TestCase
7
7
 
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ShouldRaiseTest < Test::Unit::TestCase
7
7
 
@@ -18,7 +18,7 @@ module Spec
18
18
  end
19
19
 
20
20
  def test_should_fail_when_exact_exception_is_raised_with_wrong_message
21
- assert_raises(Spec::Api::ExpectationNotMetError) do
21
+ assert_raises(Spec::Expectations::ExpectationNotMetError) do
22
22
  lambda { raise StandardError.new("chunky bacon") }.should_raise StandardError, "rotten tomatoes"
23
23
  end
24
24
  end
@@ -55,7 +55,7 @@ module Spec
55
55
  end
56
56
 
57
57
  def test_should_faile_when_exact_exception_is_raised_with_message
58
- assert_raises(Spec::Api::ExpectationNotMetError) do
58
+ assert_raises(Spec::Expectations::ExpectationNotMetError) do
59
59
  lambda { raise StandardError.new("abc") }.should_not_raise StandardError, "abc"
60
60
  end
61
61
  end
@@ -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
@@ -1,19 +1,19 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ShouldMatchTest < Test::Unit::TestCase
7
7
 
8
8
  def test_should_not_raise_when_objects_match
9
9
  assert_nothing_raised do
10
- "hi aslak".should_match /aslak/
10
+ "hi aslak".should_match(/aslak/)
11
11
  end
12
12
  end
13
13
 
14
14
  def test_should_raise_when_objects_do_not_match
15
15
  assert_raise(ExpectationNotMetError) do
16
- "hi aslak".should_match /steve/
16
+ "hi aslak".should_match(/steve/)
17
17
  end
18
18
  end
19
19
  end
@@ -21,13 +21,13 @@ module Spec
21
21
  class ShouldNotMatchTest < Test::Unit::TestCase
22
22
  def test_should_not_raise_when_objects_do_not_match
23
23
  assert_nothing_raised do
24
- "hi aslak".should_not_match /steve/
24
+ "hi aslak".should_not_match(/steve/)
25
25
  end
26
26
  end
27
27
 
28
28
  def test_should_raise_when_objects_match
29
29
  assert_raise(ExpectationNotMetError) do
30
- "hi aslak".should_not_match /aslak/
30
+ "hi aslak".should_not_match(/aslak/)
31
31
  end
32
32
  end
33
33
  end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
3
  module Spec
4
- module Api
4
+ module Expectations
5
5
  module Helper
6
6
  class ShouldHaveTest < Test::Unit::TestCase
7
7
 
@@ -56,6 +56,15 @@ module Spec
56
56
  @owner.should_have_exactly(3).items_in_collection_with_size_method
57
57
  end
58
58
  end
59
+
60
+ def test_should_not_raise_when_expecting_actual_size_with_args
61
+ assert_nothing_raised do
62
+ @owner.should_have(3).items_for('a')
63
+ @owner.should_have_exactly(3).items_for('a')
64
+ @owner.should_have(1).items_for('b')
65
+ @owner.should_have_exactly(1).items_for('b')
66
+ end
67
+ end
59
68
  end
60
69
 
61
70
  class ShouldHaveAtLeastTest < Test::Unit::TestCase