rspec 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/{CHANGES → History.txt} +116 -64
  2. data/Manifest.txt +403 -0
  3. data/{MIT-LICENSE → README.txt} +43 -0
  4. data/Rakefile +39 -212
  5. data/{TODO → TODO.txt} +0 -0
  6. data/bin/autospec +4 -0
  7. data/bin/spec +1 -1
  8. data/examples/pure/yielding_example.rb +33 -0
  9. data/examples/stories/game-of-life/.loadpath +5 -0
  10. data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
  11. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
  12. data/init.rb +9 -0
  13. data/lib/autotest/discover.rb +1 -1
  14. data/lib/autotest/rspec.rb +3 -29
  15. data/lib/spec.rb +10 -12
  16. data/lib/spec/adapters.rb +1 -0
  17. data/lib/spec/adapters/ruby_engine.rb +26 -0
  18. data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
  19. data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
  20. data/lib/spec/example/errors.rb +6 -0
  21. data/lib/spec/example/example_group_methods.rb +17 -14
  22. data/lib/spec/example/example_matcher.rb +2 -0
  23. data/lib/spec/example/example_methods.rb +4 -9
  24. data/lib/spec/example/module_inclusion_warnings.rb +2 -1
  25. data/lib/spec/expectations/extensions/object.rb +2 -2
  26. data/lib/spec/expectations/handler.rb +8 -16
  27. data/lib/spec/extensions/main.rb +2 -17
  28. data/lib/spec/matchers.rb +8 -2
  29. data/lib/spec/matchers/be.rb +0 -3
  30. data/lib/spec/matchers/change.rb +44 -40
  31. data/lib/spec/matchers/has.rb +1 -1
  32. data/lib/spec/matchers/have.rb +17 -12
  33. data/lib/spec/matchers/operator_matcher.rb +10 -4
  34. data/lib/spec/matchers/simple_matcher.rb +113 -10
  35. data/lib/spec/mocks.rb +1 -1
  36. data/lib/spec/mocks/argument_constraints.rb +185 -0
  37. data/lib/spec/mocks/argument_expectation.rb +35 -173
  38. data/lib/spec/mocks/framework.rb +1 -1
  39. data/lib/spec/mocks/message_expectation.rb +30 -5
  40. data/lib/spec/mocks/methods.rb +14 -2
  41. data/lib/spec/mocks/mock.rb +4 -0
  42. data/lib/spec/mocks/proxy.rb +46 -5
  43. data/lib/spec/mocks/spec_methods.rb +9 -1
  44. data/lib/spec/rake/spectask.rb +14 -22
  45. data/lib/spec/rake/verify_rcov.rb +3 -3
  46. data/lib/spec/runner.rb +18 -6
  47. data/lib/spec/runner/backtrace_tweaker.rb +6 -7
  48. data/lib/spec/runner/command_line.rb +6 -17
  49. data/lib/spec/runner/drb_command_line.rb +1 -1
  50. data/lib/spec/runner/formatter/base_formatter.rb +3 -1
  51. data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
  52. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  53. data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
  54. data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
  55. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  56. data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
  57. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
  58. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
  59. data/lib/spec/runner/heckle_runner.rb +2 -2
  60. data/lib/spec/runner/option_parser.rb +2 -1
  61. data/lib/spec/runner/options.rb +18 -9
  62. data/lib/spec/runner/reporter.rb +24 -4
  63. data/lib/spec/runner/spec_parser.rb +1 -1
  64. data/lib/spec/story/runner.rb +1 -2
  65. data/lib/spec/story/runner/story_mediator.rb +14 -0
  66. data/lib/spec/story/runner/story_parser.rb +20 -0
  67. data/lib/spec/story/step.rb +40 -28
  68. data/lib/spec/story/step_mother.rb +2 -1
  69. data/lib/spec/story/world.rb +6 -2
  70. data/lib/spec/version.rb +13 -22
  71. data/rake_tasks/failing_examples_with_html.rake +1 -1
  72. data/rake_tasks/verify_rcov.rake +2 -2
  73. data/rspec.gemspec +33 -0
  74. data/spec/autotest/rspec_spec.rb +90 -141
  75. data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
  76. data/spec/spec/example/base_formatter_spec.rb +112 -0
  77. data/spec/spec/example/example_group_factory_spec.rb +2 -2
  78. data/spec/spec/example/example_group_methods_spec.rb +55 -4
  79. data/spec/spec/example/example_group_spec.rb +4 -3
  80. data/spec/spec/example/example_methods_spec.rb +18 -14
  81. data/spec/spec/example/pending_module_spec.rb +38 -0
  82. data/spec/spec/example/shared_example_group_spec.rb +1 -1
  83. data/spec/spec/expectations/extensions/object_spec.rb +0 -12
  84. data/spec/spec/extensions/main_spec.rb +3 -8
  85. data/spec/spec/matchers/change_spec.rb +16 -6
  86. data/spec/spec/matchers/handler_spec.rb +58 -37
  87. data/spec/spec/matchers/has_spec.rb +10 -0
  88. data/spec/spec/matchers/have_spec.rb +105 -2
  89. data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
  90. data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
  91. data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
  92. data/spec/spec/mocks/bug_report_496.rb +17 -0
  93. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
  94. data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
  95. data/spec/spec/mocks/mock_spec.rb +55 -10
  96. data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
  97. data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
  98. data/spec/spec/mocks/options_hash_spec.rb +18 -28
  99. data/spec/spec/mocks/partial_mock_spec.rb +2 -0
  100. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
  101. data/spec/spec/mocks/stub_spec.rb +7 -0
  102. data/spec/spec/runner/command_line_spec.rb +5 -12
  103. data/spec/spec/runner/drb_command_line_spec.rb +13 -6
  104. data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
  105. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
  106. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
  107. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
  108. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
  109. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
  110. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
  111. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
  112. data/spec/spec/runner/heckle_runner_spec.rb +8 -8
  113. data/spec/spec/runner/option_parser_spec.rb +21 -6
  114. data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
  115. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
  116. data/spec/spec/runner/reporter_spec.rb +51 -5
  117. data/spec/spec/runner/spec_parser_spec.rb +4 -4
  118. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
  119. data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
  120. data/spec/spec/story/runner/story_parser_spec.rb +23 -6
  121. data/spec/spec/story/scenario_spec.rb +1 -3
  122. data/spec/spec/story/step_mother_spec.rb +12 -0
  123. data/spec/spec/story/step_spec.rb +57 -4
  124. data/spec/spec/story/story_spec.rb +1 -3
  125. data/spec/spec/story/world_spec.rb +1 -1
  126. data/spec/spec_helper.rb +21 -68
  127. data/stories/all.rb +1 -1
  128. data/stories/configuration/before_blocks.story +21 -0
  129. data/stories/configuration/stories.rb +7 -0
  130. data/stories/example_groups/stories.rb +3 -4
  131. data/stories/resources/spec/before_blocks_example.rb +32 -0
  132. data/stories/stories/multiline_steps.story +23 -0
  133. data/stories/stories/steps/multiline_steps.rb +13 -0
  134. data/stories/stories/stories.rb +6 -0
  135. data/story_server/prototype/javascripts/builder.js +136 -0
  136. data/story_server/prototype/javascripts/controls.js +972 -0
  137. data/story_server/prototype/javascripts/dragdrop.js +976 -0
  138. data/story_server/prototype/javascripts/effects.js +1117 -0
  139. data/story_server/prototype/javascripts/prototype.js +4140 -0
  140. data/story_server/prototype/javascripts/rspec.js +149 -0
  141. data/story_server/prototype/javascripts/scriptaculous.js +58 -0
  142. data/story_server/prototype/javascripts/slider.js +276 -0
  143. data/story_server/prototype/javascripts/sound.js +55 -0
  144. data/story_server/prototype/javascripts/unittest.js +568 -0
  145. data/story_server/prototype/lib/server.rb +24 -0
  146. data/story_server/prototype/stories.html +176 -0
  147. data/story_server/prototype/stylesheets/rspec.css +136 -0
  148. data/story_server/prototype/stylesheets/test.css +90 -0
  149. metadata +166 -166
  150. data/README +0 -36
  151. data/UPGRADE +0 -7
  152. data/bin/spec_translator +0 -8
  153. data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
  154. data/lib/spec/translator.rb +0 -114
  155. data/spec/spec/example/example_spec.rb +0 -53
  156. data/spec/spec/runner/execution_context_spec.rb +0 -37
  157. data/spec/spec/translator_spec.rb +0 -265
@@ -48,53 +48,73 @@ end
48
48
 
49
49
  module Spec
50
50
  module Expectations
51
- describe ExpectationMatcherHandler, ".handle_matcher" do
52
- it "should ask the matcher if it matches" do
53
- matcher = mock("matcher")
54
- actual = Object.new
55
- matcher.should_receive(:matches?).with(actual).and_return(true)
56
- ExpectationMatcherHandler.handle_matcher(actual, matcher)
57
- end
58
-
59
- it "should explain when the matcher parameter is not a matcher" do
60
- begin
61
- nonmatcher = mock("nonmatcher")
51
+ describe ExpectationMatcherHandler do
52
+ describe "#handle_matcher" do
53
+ it "should ask the matcher if it matches" do
54
+ matcher = mock("matcher")
62
55
  actual = Object.new
63
- ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
64
- rescue Spec::Expectations::InvalidMatcherError => e
56
+ matcher.should_receive(:matches?).with(actual).and_return(true)
57
+ ExpectationMatcherHandler.handle_matcher(actual, matcher)
65
58
  end
59
+
60
+ it "should explain when the matcher parameter is not a matcher" do
61
+ begin
62
+ nonmatcher = mock("nonmatcher")
63
+ actual = Object.new
64
+ ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
65
+ rescue Spec::Expectations::InvalidMatcherError => e
66
+ end
66
67
 
67
- e.message.should =~ /^Expected a matcher, got /
68
+ e.message.should =~ /^Expected a matcher, got /
69
+ end
70
+
71
+ it "should return the match value" do
72
+ matcher = mock("matcher")
73
+ actual = Object.new
74
+ matcher.should_receive(:matches?).with(actual).and_return(:this_value)
75
+ ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
76
+ end
68
77
  end
69
78
  end
70
79
 
71
- describe NegativeExpectationMatcherHandler, ".handle_matcher" do
72
- it "should explain when matcher does not support should_not" do
73
- matcher = mock("matcher")
74
- matcher.stub!(:matches?)
75
- actual = Object.new
76
- lambda {
77
- NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
78
- }.should fail_with(/Matcher does not support should_not.\n/)
79
- end
80
-
81
- it "should ask the matcher if it matches" do
82
- matcher = mock("matcher")
83
- actual = Object.new
84
- matcher.stub!(:negative_failure_message)
85
- matcher.should_receive(:matches?).with(actual).and_return(false)
86
- NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
87
- end
80
+ describe NegativeExpectationMatcherHandler do
81
+ describe "#handle_matcher" do
82
+ it "should explain when matcher does not support should_not" do
83
+ matcher = mock("matcher")
84
+ matcher.stub!(:matches?)
85
+ actual = Object.new
86
+ lambda {
87
+ NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
88
+ }.should fail_with(/Matcher does not support should_not.\n/)
89
+ end
88
90
 
89
- it "should explain when the matcher parameter is not a matcher" do
90
- begin
91
- nonmatcher = mock("nonmatcher")
91
+ it "should ask the matcher if it matches" do
92
+ matcher = mock("matcher")
92
93
  actual = Object.new
93
- NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
94
- rescue Spec::Expectations::InvalidMatcherError => e
94
+ matcher.stub!(:negative_failure_message)
95
+ matcher.should_receive(:matches?).with(actual).and_return(false)
96
+ NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
97
+ end
98
+
99
+ it "should explain when the matcher parameter is not a matcher" do
100
+ begin
101
+ nonmatcher = mock("nonmatcher")
102
+ actual = Object.new
103
+ NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
104
+ rescue Spec::Expectations::InvalidMatcherError => e
105
+ end
106
+
107
+ e.message.should =~ /^Expected a matcher, got /
95
108
  end
96
109
 
97
- e.message.should =~ /^Expected a matcher, got /
110
+
111
+ it "should return the match value" do
112
+ matcher = mock("matcher")
113
+ actual = Object.new
114
+ matcher.should_receive(:matches?).with(actual).and_return(false)
115
+ matcher.stub!(:negative_failure_message).and_return("ignore")
116
+ NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
117
+ end
98
118
  end
99
119
  end
100
120
 
@@ -124,6 +144,7 @@ module Spec
124
144
  }.should fail_with(/Matcher does not support should_not.\n/)
125
145
  end
126
146
 
147
+
127
148
  end
128
149
  end
129
150
  end
@@ -51,3 +51,13 @@ describe "should_not have_sym(*args)" do
51
51
  lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
52
52
  end
53
53
  end
54
+
55
+ describe Spec::Matchers::Has do
56
+ it "should work when the target implements #send" do
57
+ o = {:a => "A"}
58
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
59
+ lambda {
60
+ o.should have_key(:a)
61
+ }.should_not raise_error
62
+ end
63
+ end
@@ -47,11 +47,40 @@ describe "should have(n).items" do
47
47
  end
48
48
  end
49
49
 
50
+ describe 'should have(1).item when ActiveSupport::Inflector is defined' do
51
+ include HaveSpecHelper
52
+
53
+ before(:each) do
54
+ unless defined?(ActiveSupport::Inflector)
55
+ @active_support_was_not_defined
56
+ module ActiveSupport
57
+ class Inflector
58
+ def self.pluralize(string)
59
+ string.to_s + 's'
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ it 'should pluralize the collection name' do
67
+ owner = create_collection_owner_with(1)
68
+ owner.should have(1).item
69
+ end
70
+
71
+ after(:each) do
72
+ if @active_support_was_not_defined
73
+ Object.send :remove_const, :ActiveSupport
74
+ end
75
+ end
76
+ end
77
+
50
78
  describe 'should have(1).item when Inflector is defined' do
51
79
  include HaveSpecHelper
52
80
 
53
- before do
54
- unless Object.const_defined?(:Inflector)
81
+ before(:each) do
82
+ unless defined?(Inflector)
83
+ @inflector_was_not_defined
55
84
  class Inflector
56
85
  def self.pluralize(string)
57
86
  string.to_s + 's'
@@ -64,6 +93,12 @@ describe 'should have(1).item when Inflector is defined' do
64
93
  owner = create_collection_owner_with(1)
65
94
  owner.should have(1).item
66
95
  end
96
+
97
+ after(:each) do
98
+ if @inflector_was_not_defined
99
+ Object.send :remove_const, :Inflector
100
+ end
101
+ end
67
102
  end
68
103
 
69
104
  describe "should have(n).items where result responds to items but returns something other than a collection" do
@@ -289,3 +324,71 @@ describe "have(n).things on an object which is not a collection nor contains one
289
324
  lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
290
325
  end
291
326
  end
327
+
328
+ describe Spec::Matchers::Have, "for a collection owner that implements #send" do
329
+ include HaveSpecHelper
330
+
331
+ before(:each) do
332
+ @collection = Object.new
333
+ def @collection.floozles; [1,2] end
334
+ def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
335
+ end
336
+
337
+ it "should work in the straightforward case" do
338
+ lambda {
339
+ @collection.should have(2).floozles
340
+ }.should_not raise_error
341
+ end
342
+
343
+ it "should work when doing automatic pluralization" do
344
+ lambda {
345
+ @collection.should have_at_least(1).floozle
346
+ }.should_not raise_error
347
+ end
348
+
349
+ it "should blow up when the owner doesn't respond to that method" do
350
+ lambda {
351
+ @collection.should have(99).problems
352
+ }.should raise_error(NoMethodError, /problems/)
353
+ end
354
+ end
355
+
356
+ module Spec
357
+ module Matchers
358
+ describe Have do
359
+ it "should have method_missing as private" do
360
+ Have.private_instance_methods.should include("method_missing")
361
+ end
362
+
363
+ describe "respond_to?" do
364
+ before :each do
365
+ @have = Have.new(:foo)
366
+ @a_method_which_have_defines = Have.instance_methods.first
367
+ @a_method_which_object_defines = Object.instance_methods.first
368
+ end
369
+
370
+ it "should be true for a method which Have defines" do
371
+ @have.should respond_to(@a_method_which_have_defines)
372
+ end
373
+
374
+ it "should be true for a method that it's superclass (Object) defines" do
375
+ @have.should respond_to(@a_method_which_object_defines)
376
+ end
377
+
378
+ it "should be false for a method which neither Object nor nor Have defines" do
379
+ @have.should_not respond_to(:foo_bar_baz)
380
+ end
381
+
382
+ it "should be false if the owner doesn't respond to the method" do
383
+ have = Have.new(99)
384
+ have.should_not respond_to(:problems)
385
+ end
386
+
387
+ it "should be true if the owner responds to the method" do
388
+ have = Have.new(:a_symbol)
389
+ have.should respond_to(:to_sym)
390
+ end
391
+ end
392
+ end
393
+ end
394
+ end
@@ -10,12 +10,17 @@ describe "should ==" do
10
10
  subject.should == "apple"
11
11
  end
12
12
 
13
+ it "should return true on success" do
14
+ subject = "apple"
15
+ (subject.should == "apple").should be_true
16
+ end
17
+
13
18
  it "should fail when target.==(actual) returns false" do
14
19
  subject = "apple"
15
20
  Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
16
21
  subject.should == "orange"
17
22
  end
18
-
23
+
19
24
  end
20
25
 
21
26
  describe "should_not ==" do
@@ -26,12 +31,17 @@ describe "should_not ==" do
26
31
  subject.should_not == "apple"
27
32
  end
28
33
 
34
+ it "should return true on success" do
35
+ subject = "apple"
36
+ (subject.should_not == "orange").should be_true
37
+ end
38
+
29
39
  it "should fail when target.==(actual) returns false" do
30
40
  subject = "apple"
31
41
  Spec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
32
42
  subject.should_not == "apple"
33
43
  end
34
-
44
+
35
45
  end
36
46
 
37
47
  describe "should ===" do
@@ -156,3 +166,26 @@ describe "should <=" do
156
166
 
157
167
  end
158
168
 
169
+ describe Spec::Matchers::PositiveOperatorMatcher do
170
+
171
+ it "should work when the target has implemented #send" do
172
+ o = Object.new
173
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
174
+ lambda {
175
+ o.should == o
176
+ }.should_not raise_error
177
+ end
178
+
179
+ end
180
+
181
+ describe Spec::Matchers::NegativeOperatorMatcher do
182
+
183
+ it "should work when the target has implemented #send" do
184
+ o = Object.new
185
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
186
+ lambda {
187
+ o.should_not == :foo
188
+ }.should_not raise_error
189
+ end
190
+
191
+ end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  module Spec
4
4
  module Matchers
5
5
  describe SimpleMatcher do
6
- it "should match pass match arg to block" do
6
+ it "should pass match arg to block" do
7
7
  actual = nil
8
8
  matcher = simple_matcher("message") do |given| actual = given end
9
9
  matcher.matches?("foo")
@@ -22,10 +22,72 @@ module Spec
22
22
  matcher.negative_failure_message.should =~ /expected not to get \"thing\", but got \"other\"/
23
23
  end
24
24
 
25
- it "should provide a description" do
25
+ it "should provide the given description" do
26
26
  matcher = simple_matcher("thing") do end
27
27
  matcher.description.should =="thing"
28
28
  end
29
+
30
+ it "should fail if a wrapped 'should' fails" do
31
+ matcher = simple_matcher("should fail") do
32
+ 2.should == 3
33
+ end
34
+ lambda do
35
+ matcher.matches?("anything").should be_true
36
+ end.should fail_with(/expected: 3/)
37
+ end
38
+ end
39
+
40
+ describe "with arity of 2" do
41
+ it "should provide the matcher so you can access its messages" do
42
+ provided_matcher = nil
43
+ matcher = simple_matcher("thing") do |given, matcher|
44
+ provided_matcher = matcher
45
+ end
46
+ matcher.matches?("anything")
47
+ provided_matcher.should equal(matcher)
48
+ end
49
+
50
+ it "should support a custom failure message" do
51
+ matcher = simple_matcher("thing") do |given, matcher|
52
+ matcher.failure_message = "custom message"
53
+ end
54
+ matcher.matches?("other")
55
+ matcher.failure_message.should == "custom message"
56
+ end
57
+
58
+ it "should complain when asked for a failure message if you don't give it a description or a message" do
59
+ matcher = simple_matcher do |given, matcher| end
60
+ matcher.matches?("other")
61
+ matcher.failure_message.should =~ /No description provided/
62
+ end
63
+
64
+ it "should support a custom negative failure message" do
65
+ matcher = simple_matcher("thing") do |given, matcher|
66
+ matcher.negative_failure_message = "custom message"
67
+ end
68
+ matcher.matches?("other")
69
+ matcher.negative_failure_message.should == "custom message"
70
+ end
71
+
72
+ it "should complain when asked for a negative failure message if you don't give it a description or a message" do
73
+ matcher = simple_matcher do |given, matcher| end
74
+ matcher.matches?("other")
75
+ matcher.negative_failure_message.should =~ /No description provided/
76
+ end
77
+
78
+ it "should support a custom description" do
79
+ matcher = simple_matcher("thing") do |given, matcher|
80
+ matcher.description = "custom message"
81
+ end
82
+ matcher.matches?("description")
83
+ matcher.description.should == "custom message"
84
+ end
85
+
86
+ it "should tell you no description was provided when it doesn't receive one" do
87
+ matcher = simple_matcher do end
88
+ matcher.description.should =~ /No description provided/
89
+ end
29
90
  end
91
+
30
92
  end
31
93
  end
@@ -23,6 +23,13 @@ module Spec
23
23
  it "should pass if any number of times method is not called" do
24
24
  @mock.should_receive(:random_call).any_number_of_times
25
25
  end
26
+
27
+ it "should return the mocked value when called after a similar stub" do
28
+ @mock.stub!(:message).and_return :stub_value
29
+ @mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
30
+ @mock.message.should == :mock_value
31
+ @mock.message.should == :mock_value
32
+ end
26
33
  end
27
34
 
28
35
  end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ class BaseClass
4
+ end
5
+
6
+ class SubClass < BaseClass
7
+ end
8
+
9
+ describe "a message expectation on a base class object" do
10
+ it "should correctly pick up message sent to it subclass" do
11
+ pending("fix for http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/496") do
12
+ BaseClass.should_receive(:new).once
13
+ SubClass.new
14
+ end
15
+ end
16
+ end
17
+
@@ -82,6 +82,13 @@ module Spec
82
82
  @mock.msg({})
83
83
  end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (hash_including(:a=>1)) but received it with ({})")
84
84
  end
85
+
86
+ it "should fail with block constraints" do
87
+ lambda do
88
+ @mock.should_receive(:msg).with {|arg| arg.should == :received }
89
+ @mock.msg :no_msg_for_you
90
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
91
+ end
85
92
 
86
93
  end
87
94
 
@@ -116,7 +123,6 @@ module Spec
116
123
  @mock.random_call(123)
117
124
  end.should raise_error(MockExpectationError)
118
125
  end
119
-
120
126
 
121
127
  end
122
128
  end