rspec 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/History.rdoc +31 -1
  2. data/Manifest.txt +14 -12
  3. data/Rakefile +1 -1
  4. data/Upgrade.rdoc +43 -3
  5. data/examples/failing/failing_implicit_docstrings_example.rb +5 -5
  6. data/examples/passing/implicit_docstrings_example.rb +3 -3
  7. data/features/before_and_after_blocks/before_and_after_blocks.feature +20 -21
  8. data/features/example_groups/example_group_with_should_methods.feature +20 -8
  9. data/features/example_groups/implicit_docstrings.feature +36 -20
  10. data/features/example_groups/nested_groups.feature +25 -10
  11. data/features/extensions/custom_example_group.feature +19 -0
  12. data/features/formatters/custom_formatter.feature +30 -0
  13. data/features/heckle/heckle.feature +7 -7
  14. data/features/interop/examples_and_tests_together.feature +63 -14
  15. data/features/interop/rspec_output.feature +25 -0
  16. data/features/interop/test_but_not_test_unit.feature +19 -7
  17. data/features/interop/test_case_with_should_methods.feature +37 -8
  18. data/features/matchers/{create_matcher.feature → define_matcher.feature} +54 -30
  19. data/features/matchers/{create_matcher_outside_rspec.feature → define_matcher_outside_rspec.feature} +7 -7
  20. data/features/mock_framework_integration/use_flexmock.feature +3 -3
  21. data/features/mock_framework_integration/use_mocha.feature +3 -3
  22. data/features/mock_framework_integration/use_rr.feature +3 -3
  23. data/features/mocks/mix_stubs_and_mocks.feature +4 -4
  24. data/features/pending/pending_examples.feature +18 -18
  25. data/features/runner/specify_line_number.feature +32 -0
  26. data/features/step_definitions/running_rspec_steps.rb +41 -0
  27. data/features/subject/explicit_subject.feature +4 -4
  28. data/features/subject/implicit_subject.feature +4 -4
  29. data/features/support/env.rb +64 -11
  30. data/features/support/matchers/smart_match.rb +10 -35
  31. data/lib/spec.rb +1 -0
  32. data/lib/spec/deprecation.rb +40 -0
  33. data/lib/spec/dsl/main.rb +10 -5
  34. data/lib/spec/example.rb +1 -27
  35. data/lib/spec/example/args_and_options.rb +27 -0
  36. data/lib/spec/example/before_and_after_hooks.rb +30 -21
  37. data/lib/spec/example/errors.rb +8 -18
  38. data/lib/spec/example/example_group_factory.rb +0 -4
  39. data/lib/spec/example/example_group_methods.rb +27 -41
  40. data/lib/spec/example/example_group_proxy.rb +12 -22
  41. data/lib/spec/example/example_methods.rb +8 -18
  42. data/lib/spec/example/example_proxy.rb +4 -4
  43. data/lib/spec/example/pending.rb +3 -4
  44. data/lib/spec/example/predicate_matchers.rb +1 -1
  45. data/lib/spec/example/subject.rb +2 -0
  46. data/lib/spec/expectations.rb +1 -26
  47. data/lib/spec/expectations/extensions.rb +1 -1
  48. data/lib/spec/expectations/extensions/kernel.rb +52 -0
  49. data/lib/spec/expectations/handler.rb +21 -10
  50. data/lib/spec/matchers/be.rb +3 -3
  51. data/lib/spec/matchers/be_close.rb +17 -21
  52. data/lib/spec/matchers/be_instance_of.rb +7 -26
  53. data/lib/spec/matchers/be_kind_of.rb +7 -26
  54. data/lib/spec/matchers/dsl.rb +9 -4
  55. data/lib/spec/matchers/eql.rb +24 -25
  56. data/lib/spec/matchers/equal.rb +25 -25
  57. data/lib/spec/matchers/exist.rb +5 -21
  58. data/lib/spec/matchers/include.rb +22 -44
  59. data/lib/spec/matchers/match.rb +5 -25
  60. data/lib/spec/matchers/match_array.rb +8 -4
  61. data/lib/spec/matchers/matcher.rb +13 -2
  62. data/lib/spec/matchers/pretty.rb +1 -0
  63. data/lib/spec/matchers/simple_matcher.rb +2 -2
  64. data/lib/spec/mocks/mock.rb +10 -10
  65. data/lib/spec/mocks/spec_methods.rb +1 -1
  66. data/lib/spec/runner/configuration.rb +53 -42
  67. data/lib/spec/{expectations → runner}/differs/default.rb +0 -0
  68. data/lib/spec/{expectations → runner}/differs/load-diff-lcs.rb +0 -0
  69. data/lib/spec/runner/drb_command_line.rb +1 -1
  70. data/lib/spec/runner/example_group_runner.rb +0 -12
  71. data/lib/spec/runner/formatter/base_formatter.rb +77 -30
  72. data/lib/spec/runner/formatter/base_text_formatter.rb +19 -24
  73. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +1 -1
  74. data/lib/spec/runner/formatter/html_formatter.rb +4 -6
  75. data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
  76. data/lib/spec/runner/formatter/no_op_method_missing.rb +21 -0
  77. data/lib/spec/runner/formatter/profile_formatter.rb +0 -4
  78. data/lib/spec/runner/formatter/progress_bar_formatter.rb +4 -5
  79. data/lib/spec/runner/formatter/silent_formatter.rb +10 -0
  80. data/lib/spec/runner/formatter/specdoc_formatter.rb +2 -2
  81. data/lib/spec/runner/option_parser.rb +14 -7
  82. data/lib/spec/runner/options.rb +17 -7
  83. data/lib/spec/runner/reporter.rb +69 -64
  84. data/lib/spec/version.rb +1 -1
  85. data/spec/spec/dsl/main_spec.rb +7 -0
  86. data/spec/spec/example/example_group_methods_spec.rb +16 -32
  87. data/spec/spec/example/example_group_proxy_spec.rb +25 -5
  88. data/spec/spec/example/example_group_spec.rb +2 -2
  89. data/spec/spec/example/example_methods_spec.rb +19 -24
  90. data/spec/spec/example/example_proxy_spec.rb +11 -1
  91. data/spec/spec/example/pending_module_spec.rb +2 -108
  92. data/spec/spec/example/predicate_matcher_spec.rb +23 -3
  93. data/spec/spec/expectations/extensions/object_spec.rb +9 -9
  94. data/spec/spec/expectations/fail_with_spec.rb +13 -13
  95. data/spec/spec/expectations/handler_spec.rb +44 -15
  96. data/spec/spec/matchers/be_close_spec.rb +9 -0
  97. data/spec/spec/matchers/be_instance_of_spec.rb +6 -4
  98. data/spec/spec/matchers/be_kind_of_spec.rb +5 -3
  99. data/spec/spec/matchers/be_spec.rb +1 -5
  100. data/spec/spec/matchers/compatibility_spec.rb +1 -1
  101. data/spec/spec/matchers/dsl_spec.rb +10 -1
  102. data/spec/spec/matchers/eql_spec.rb +8 -4
  103. data/spec/spec/matchers/equal_spec.rb +8 -4
  104. data/spec/spec/matchers/exist_spec.rb +1 -1
  105. data/spec/spec/matchers/include_spec.rb +1 -1
  106. data/spec/spec/matchers/match_array_spec.rb +26 -1
  107. data/spec/spec/matchers/match_spec.rb +2 -2
  108. data/spec/spec/matchers/matcher_methods_spec.rb +0 -3
  109. data/spec/spec/matchers/matcher_spec.rb +53 -0
  110. data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
  111. data/spec/spec/mocks/mock_spec.rb +6 -0
  112. data/spec/spec/runner/configuration_spec.rb +11 -1
  113. data/spec/spec/runner/drb_command_line_spec.rb +13 -1
  114. data/spec/spec/runner/example_group_runner_spec.rb +0 -7
  115. data/spec/spec/runner/formatter/base_formatter_spec.rb +19 -12
  116. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +2 -2
  117. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +4 -4
  118. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +2 -2
  119. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +31 -34
  120. data/spec/spec/runner/formatter/html_formatter_spec.rb +20 -0
  121. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -20
  122. data/spec/spec/runner/formatter/profile_formatter_spec.rb +22 -3
  123. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +24 -3
  124. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  125. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +25 -28
  126. data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +2 -2
  127. data/spec/spec/runner/option_parser_spec.rb +108 -40
  128. data/spec/spec/runner/reporter_spec.rb +16 -17
  129. data/spec/spec_helper.rb +4 -1
  130. metadata +20 -18
  131. data/features/example_groups/output.feature +0 -20
  132. data/features/step_definitions/running_rspec.rb +0 -69
  133. data/lib/spec/expectations/extensions/object.rb +0 -63
  134. data/resources/spec/example_group_with_should_methods.rb +0 -12
  135. data/resources/spec/simple_spec.rb +0 -8
  136. data/resources/test/spec_and_test_together.rb +0 -56
  137. data/resources/test/spec_including_test_but_not_unit.rb +0 -11
  138. data/resources/test/test_case_with_should_methods.rb +0 -29
@@ -12,17 +12,24 @@ describe Spec::Expectations, "#fail_with with no diff" do
12
12
  }.should fail_with("the message")
13
13
  end
14
14
 
15
- it "should handle an Array" do
16
- lambda {
17
- Spec::Expectations.fail_with ["the message","expected","actual"]
18
- }.should fail_with("the message")
19
- end
20
-
21
15
  after(:each) do
22
16
  Spec::Expectations.differ = @old_differ
23
17
  end
24
18
  end
25
19
 
20
+ describe Spec::Expectations, "#fail_with with Array" do
21
+ before(:each) do
22
+ Spec.stub!(:warn)
23
+ end
24
+
25
+ it "is deprecated" do
26
+ Spec.should_receive(:warn)
27
+ lambda {
28
+ Spec::Expectations.fail_with ["message", "expected", "actual"]
29
+ }.should raise_error
30
+ end
31
+ end
32
+
26
33
  describe Spec::Expectations, "#fail_with with diff" do
27
34
  before(:each) do
28
35
  @old_differ = Spec::Expectations.differ
@@ -58,13 +65,6 @@ describe Spec::Expectations, "#fail_with with diff" do
58
65
  }.should fail_with("the message")
59
66
  end
60
67
 
61
- it "should call differ if expected/actual are presented in an Array with message" do
62
- @differ.should_receive(:diff_as_string).with("actual","expected").and_return("diff")
63
- lambda {
64
- Spec::Expectations.fail_with(["the message", "expected", "actual"])
65
- }.should fail_with(/the message\nDiff:diff/)
66
- end
67
-
68
68
  after(:each) do
69
69
  Spec::Expectations.differ = @old_differ
70
70
  end
@@ -7,9 +7,7 @@ module ExampleExpectations
7
7
  if args.last.is_a? Hash
8
8
  @expected = args.last[:expected]
9
9
  end
10
- if block_given?
11
- @expected = block.call
12
- end
10
+ @expected = block.call if block
13
11
  @block = block
14
12
  end
15
13
 
@@ -48,20 +46,20 @@ end
48
46
 
49
47
  module Spec
50
48
  module Expectations
51
- describe ExpectationMatcherHandler do
49
+ describe PositiveExpectationHandler do
52
50
  describe "#handle_matcher" do
53
51
  it "asks the matcher if it matches" do
54
52
  matcher = mock("matcher")
55
53
  actual = Object.new
56
54
  matcher.should_receive(:matches?).with(actual).and_return(true)
57
- Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
55
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
58
56
  end
59
57
 
60
58
  it "returns the match value" do
61
59
  matcher = mock("matcher")
62
60
  actual = Object.new
63
61
  matcher.should_receive(:matches?).with(actual).and_return(:this_value)
64
- Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
62
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher).should == :this_value
65
63
  end
66
64
 
67
65
  it "calls failure_message_for_should if the matcher implements it" do
@@ -70,8 +68,22 @@ module Spec
70
68
 
71
69
  ::Spec::Expectations.should_receive(:fail_with).with("message")
72
70
 
73
- Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
71
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
72
+ end
73
+
74
+ it "calls fail if matcher.diffable?" do
75
+ matcher = mock("matcher",
76
+ :diffable? => true,
77
+ :failure_message_for_should => "message",
78
+ :matches? => false,
79
+ :expected => [1],
80
+ :actual => 2
81
+ )
82
+ actual = Object.new
83
+
84
+ ::Spec::Expectations.should_receive(:fail_with).with("message", 1, 2)
74
85
 
86
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
75
87
  end
76
88
 
77
89
  it "calls failure_message if the matcher does not implement failure_message_for_should" do
@@ -80,19 +92,19 @@ module Spec
80
92
 
81
93
  ::Spec::Expectations.should_receive(:fail_with).with("message")
82
94
 
83
- Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
95
+ Spec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
84
96
 
85
97
  end
86
98
  end
87
99
  end
88
100
 
89
- describe NegativeExpectationMatcherHandler do
101
+ describe NegativeExpectationHandler do
90
102
  describe "#handle_matcher" do
91
103
  it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
92
104
  matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
93
105
  actual = Object.new
94
106
  matcher.should_receive(:does_not_match?).with(actual).and_return(true)
95
- Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
107
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
96
108
  end
97
109
 
98
110
  it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
@@ -100,7 +112,7 @@ module Spec
100
112
  actual = Object.new
101
113
  matcher.stub!(:negative_failure_message)
102
114
  matcher.should_receive(:matches?).with(actual).and_return(false)
103
- Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
115
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
104
116
  end
105
117
 
106
118
  it "returns the match value" do
@@ -108,7 +120,7 @@ module Spec
108
120
  actual = Object.new
109
121
  matcher.should_receive(:matches?).with(actual).and_return(false)
110
122
  matcher.stub!(:negative_failure_message).and_return("ignore")
111
- Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
123
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher).should be_false
112
124
  end
113
125
 
114
126
 
@@ -118,7 +130,7 @@ module Spec
118
130
 
119
131
  ::Spec::Expectations.should_receive(:fail_with).with("message")
120
132
 
121
- Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
133
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
122
134
 
123
135
  end
124
136
 
@@ -128,13 +140,30 @@ module Spec
128
140
 
129
141
  ::Spec::Expectations.should_receive(:fail_with).with("message")
130
142
 
131
- Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
143
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
144
+
145
+ end
146
+
147
+
148
+ it "calls fail if matcher.diffable?" do
149
+ matcher = mock("matcher",
150
+ :diffable? => true,
151
+ :failure_message_for_should_not => "message",
152
+ :matches? => true,
153
+ :expected => [1],
154
+ :actual => 2
155
+ )
156
+ actual = Object.new
157
+
158
+ ::Spec::Expectations.should_receive(:fail_with).with("message", 1, 2)
132
159
 
160
+ Spec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
133
161
  end
162
+
134
163
  end
135
164
  end
136
165
 
137
- describe ExpectationMatcherHandler do
166
+ describe PositiveExpectationHandler do
138
167
  include ExampleExpectations
139
168
 
140
169
  it "should handle submitted args" do
@@ -31,6 +31,15 @@ module Spec
31
31
  #then
32
32
  matcher.failure_message_for_should.should == "expected 5.0 +/- (< 0.5), got 5.51"
33
33
  end
34
+
35
+ it "provides a failure message for should tno" do
36
+ #given
37
+ matcher = be_close(5.0, 0.5)
38
+ #when
39
+ matcher.matches?(5.49)
40
+ #then
41
+ matcher.failure_message_for_should_not.should == "expected 5.0 +/- (< 0.5), got 5.49"
42
+ end
34
43
  it "provides a description" do
35
44
  matcher = be_close(5.0, 0.5)
36
45
  matcher.matches?(5.1)
@@ -2,22 +2,24 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Matchers
5
- [:be_instance_of, :be_an_instance_of].each do |method|
5
+ [:be_an_instance_of, :be_instance_of].each do |method|
6
6
  describe "actual.should #{method}(expected)" do
7
7
  it "passes if actual is instance of expected class" do
8
8
  5.should send(method, Fixnum)
9
9
  end
10
10
 
11
11
  it "fails if actual is instance of subclass of expected class" do
12
- lambda { 5.should send(method, Numeric) }.should fail_with(%Q{expected instance of Numeric, got 5})
12
+ lambda { 5.should send(method, Numeric) }.should fail_with(%Q{expected 5 to be an instance of Numeric})
13
13
  end
14
14
 
15
15
  it "fails with failure message for should unless actual is instance of expected class" do
16
- lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected instance of Array, got "foo"})
16
+ lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected "foo" to be an instance of Array})
17
17
  end
18
18
 
19
19
  it "provides a description" do
20
- Spec::Matchers::BeInstanceOf.new(Class).description.should == "be an instance of Class"
20
+ matcher = be_an_instance_of(Fixnum)
21
+ matcher.matches?(Numeric)
22
+ matcher.description.should == "be an instance of Fixnum"
21
23
  end
22
24
  end
23
25
 
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Matchers
5
- [:be_kind_of, :be_a_kind_of].each do |method|
5
+ [:be_a_kind_of, :be_kind_of].each do |method|
6
6
  describe "actual.should #{method}(expected)" do
7
7
  it "passes if actual is instance of expected class" do
8
8
  5.should send(method, Fixnum)
@@ -13,11 +13,13 @@ module Spec
13
13
  end
14
14
 
15
15
  it "fails with failure message for should unless actual is kind of expected class" do
16
- lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected kind of Array, got "foo"})
16
+ lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected "foo" to be a kind of Array})
17
17
  end
18
18
 
19
19
  it "provides a description" do
20
- Spec::Matchers::BeKindOf.new(Class).description.should == "be a kind of Class"
20
+ matcher = be_a_kind_of(String)
21
+ matcher.matches?("this")
22
+ matcher.description.should == "be a kind of String"
21
23
  end
22
24
  end
23
25
 
@@ -219,7 +219,7 @@ describe "should_not with operators" do
219
219
  it "should coach user to stop using operators with should_not" do
220
220
  lambda {
221
221
  5.should_not be < 6
222
- }.should raise_error(/not only FAILED,\nit reads really poorly./m)
222
+ }.should raise_error(/not only FAILED,\nit is a bit confusing./m)
223
223
  end
224
224
  end
225
225
 
@@ -259,10 +259,6 @@ end
259
259
 
260
260
  describe "arbitrary predicate with DelegateClass" do
261
261
  it "should access methods defined in the delegating class (LH[#48])" do
262
- pending(%{
263
- Looks like DelegateClass is delegating #should to the
264
- delegate. Not sure how to fix this one. Or if we even should."
265
- })
266
262
  require 'delegate'
267
263
  class ArrayDelegate < DelegateClass(Array)
268
264
  def initialize(array)
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
- Spec::Matchers.create :have_public_instance_method do |method|
3
+ Spec::Matchers.define :have_public_instance_method do |method|
4
4
  match do |klass|
5
5
  klass.public_instance_methods.include?(method)
6
6
  end
@@ -4,13 +4,22 @@ module Spec
4
4
  module Matchers
5
5
  module DSL
6
6
  describe "#create" do
7
+ it "is deprecated" do
8
+ Spec.should_receive(:deprecate)
9
+ mod = Module.new
10
+ mod.extend Spec::Matchers::DSL
11
+ mod.create(:foo)
12
+ end
13
+ end
14
+
15
+ describe "#define" do
7
16
  it "creates a method that initializes a new matcher with the submitted name and expected arg" do
8
17
  # FIXME - this expects new to be called, but we need something
9
18
  # more robust - that expects new to be called with a specific
10
19
  # block (lambda, proc, whatever)
11
20
  mod = Module.new
12
21
  mod.extend Spec::Matchers::DSL
13
- mod.create(:foo)
22
+ mod.define(:foo)
14
23
 
15
24
  obj = Object.new
16
25
  obj.extend mod
@@ -4,25 +4,29 @@ module Spec
4
4
  module Matchers
5
5
  describe "eql" do
6
6
  it "should match when actual.eql?(expected)" do
7
- eql(1).matches?(1).should be_true
7
+ 1.should eql(1)
8
8
  end
9
+
9
10
  it "should not match when !actual.eql?(expected)" do
10
- eql(1).matches?(2).should be_false
11
+ 1.should_not eql(2)
11
12
  end
13
+
12
14
  it "should describe itself" do
13
15
  matcher = eql(1)
14
16
  matcher.matches?(1)
15
17
  matcher.description.should == "eql 1"
16
18
  end
19
+
17
20
  it "should provide message, expected and actual on #failure_message" do
18
21
  matcher = eql("1")
19
22
  matcher.matches?(1)
20
- matcher.failure_message_for_should.should == ["expected \"1\", got 1 (using .eql?)", "1", 1]
23
+ matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n\n(compared using eql?)\n"
21
24
  end
25
+
22
26
  it "should provide message, expected and actual on #negative_failure_message" do
23
27
  matcher = eql(1)
24
28
  matcher.matches?(1)
25
- matcher.failure_message_for_should_not.should == ["expected 1 not to equal 1 (using .eql?)", 1, 1]
29
+ matcher.failure_message_for_should_not.should == "\nexpected 1 not to equal 1\n\n(compared using eql?)\n"
26
30
  end
27
31
  end
28
32
  end
@@ -4,25 +4,29 @@ module Spec
4
4
  module Matchers
5
5
  describe "equal" do
6
6
  it "should match when actual.equal?(expected)" do
7
- equal(1).matches?(1).should be_true
7
+ 1.should equal(1)
8
8
  end
9
+
9
10
  it "should not match when !actual.equal?(expected)" do
10
- equal("1").matches?("1").should be_false
11
+ 1.should_not equal("1")
11
12
  end
13
+
12
14
  it "should describe itself" do
13
15
  matcher = equal(1)
14
16
  matcher.matches?(1)
15
17
  matcher.description.should == "equal 1"
16
18
  end
19
+
17
20
  it "should provide message, expected and actual on #failure_message" do
18
21
  matcher = equal("1")
19
22
  matcher.matches?(1)
20
- matcher.failure_message_for_should.should == ["expected \"1\", got 1 (using .equal?)", "1", 1]
23
+ matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n \n(compared using equal?)\n"
21
24
  end
25
+
22
26
  it "should provide message, expected and actual on #negative_failure_message" do
23
27
  matcher = equal(1)
24
28
  matcher.matches?(1)
25
- matcher.failure_message_for_should_not.should == ["expected 1 not to equal 1 (using .equal?)", 1, 1]
29
+ matcher.failure_message_for_should_not.should == "\nexpected 1 not to equal 1\n\n(compared using equal?)\n"
26
30
  end
27
31
  end
28
32
  end
@@ -41,7 +41,7 @@ describe "should exist" do
41
41
  end
42
42
 
43
43
  it "describes itself" do
44
- exist.description.should == "exists"
44
+ exist.description.should == "exist"
45
45
  end
46
46
 
47
47
  it "passes should_not exist if target doesn't exist" do
@@ -35,7 +35,7 @@ describe "should include(with, multiple, args)" do
35
35
  it "should fail if target does not include any one of the items" do
36
36
  lambda {
37
37
  [1,2,3].should include(1,2,4)
38
- }.should fail_with("expected [1, 2, 3] to include 1, 2 and 4")
38
+ }.should fail_with("expected [1, 2, 3] to include 1, 2, and 4")
39
39
  end
40
40
 
41
41
  it 'should pass if target is a Hash missing any item as a key' do
@@ -1,5 +1,19 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
+ class UnsortableObject
4
+ def initialize(id)
5
+ @id = id
6
+ end
7
+
8
+ def inspect
9
+ @id.to_s
10
+ end
11
+
12
+ def ==(other)
13
+ false
14
+ end
15
+ end
16
+
3
17
  describe "array.should =~ other_array" do
4
18
  it "should pass if target contains all items" do
5
19
  [1,2,3].should =~ [1,2,3]
@@ -41,7 +55,7 @@ the extra elements were: [4]
41
55
  MESSAGE
42
56
  end
43
57
 
44
- it "should sort items in the error message" do
58
+ it "should sort items in the error message if they all respond to <=>" do
45
59
  lambda {
46
60
  [6,2,1,5].should =~ [4,1,2,3]
47
61
  }.should fail_with(<<-MESSAGE)
@@ -52,6 +66,17 @@ the extra elements were: [5, 6]
52
66
  MESSAGE
53
67
  end
54
68
 
69
+ it "should not sort items in the error message if they don't all respond to <=>" do
70
+ lambda {
71
+ [UnsortableObject.new(2), UnsortableObject.new(1)].should =~ [UnsortableObject.new(4), UnsortableObject.new(3)]
72
+ }.should fail_with(<<-MESSAGE)
73
+ expected collection contained: [4, 3]
74
+ actual collection contained: [2, 1]
75
+ the missing elements were: [4, 3]
76
+ the extra elements were: [2, 1]
77
+ MESSAGE
78
+ end
79
+
55
80
  it "should accurately report extra elements when there are duplicates" do
56
81
  lambda {
57
82
  [1,1,1,5].should =~ [1,5]
@@ -14,7 +14,7 @@ describe "should match(expected)" do
14
14
  it "should provide message, expected and actual on failure" do
15
15
  matcher = match(/rings/)
16
16
  matcher.matches?("string")
17
- matcher.failure_message_for_should.should == ["expected \"string\" to match /rings/", /rings/, "string"]
17
+ matcher.failure_message_for_should.should == "expected \"string\" to match /rings/"
18
18
  end
19
19
  end
20
20
 
@@ -32,6 +32,6 @@ describe "should_not match(expected)" do
32
32
  it "should provide message, expected and actual on failure" do
33
33
  matcher = match(/tri/)
34
34
  matcher.matches?("string")
35
- matcher.failure_message_for_should_not.should == ["expected \"string\" not to match /tri/", /tri/, "string"]
35
+ matcher.failure_message_for_should_not.should == "expected \"string\" not to match /tri/"
36
36
  end
37
37
  end