rspec 1.2.9 → 1.3.1

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 (91) hide show
  1. data/History.rdoc +51 -1
  2. data/License.txt +1 -1
  3. data/Manifest.txt +11 -4
  4. data/README.rdoc +10 -24
  5. data/Rakefile +17 -13
  6. data/Upgrade.rdoc +63 -2
  7. data/examples/passing/shared_example_group_example.rb +0 -36
  8. data/examples/passing/simple_matcher_example.rb +3 -3
  9. data/features/formatters/nested_formatter.feature +32 -0
  10. data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
  11. data/features/interop/test_but_not_test_unit.feature +1 -1
  12. data/features/interop/test_case_with_should_methods.feature +1 -1
  13. data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
  14. data/features/matchers/define_wrapped_matcher.feature +28 -1
  15. data/features/matchers/match_unless_raises.feature +60 -0
  16. data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
  17. data/features/mocks/block_local_expectations.feature +62 -0
  18. data/features/step_definitions/running_rspec_steps.rb +9 -0
  19. data/features/step_definitions/stubbing_steps.rb +16 -0
  20. data/features/support/env.rb +1 -0
  21. data/features/support/matchers/smart_match.rb +23 -4
  22. data/geminstaller.yml +29 -0
  23. data/lib/autotest/rspec.rb +14 -7
  24. data/lib/spec/deprecation.rb +2 -1
  25. data/lib/spec/dsl/main.rb +2 -1
  26. data/lib/spec/example/example_group_methods.rb +6 -1
  27. data/lib/spec/example/example_methods.rb +4 -0
  28. data/lib/spec/example/subject.rb +9 -3
  29. data/lib/spec/interop/test/unit/testsuite_adapter.rb +2 -0
  30. data/lib/spec/interop/test.rb +1 -1
  31. data/lib/spec/matchers/be.rb +167 -128
  32. data/lib/spec/matchers/has.rb +3 -3
  33. data/lib/spec/matchers/have.rb +1 -0
  34. data/lib/spec/matchers/matcher.rb +55 -10
  35. data/lib/spec/matchers/method_missing.rb +2 -2
  36. data/lib/spec/matchers/operator_matcher.rb +6 -1
  37. data/lib/spec/matchers/pretty.rb +2 -2
  38. data/lib/spec/matchers/raise_exception.rb +131 -0
  39. data/lib/spec/matchers/simple_matcher.rb +2 -1
  40. data/lib/spec/matchers/throw_symbol.rb +18 -22
  41. data/lib/spec/matchers.rb +21 -2
  42. data/lib/spec/mocks/message_expectation.rb +63 -48
  43. data/lib/spec/mocks/methods.rb +13 -8
  44. data/lib/spec/mocks/proxy.rb +45 -22
  45. data/lib/spec/runner/backtrace_tweaker.rb +3 -2
  46. data/lib/spec/runner/configuration.rb +8 -0
  47. data/lib/spec/runner/differs/default.rb +1 -1
  48. data/lib/spec/runner/drb_command_line.rb +8 -2
  49. data/lib/spec/runner/example_group_runner.rb +1 -2
  50. data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
  51. data/lib/spec/runner/option_parser.rb +2 -0
  52. data/lib/spec/runner/options.rb +8 -2
  53. data/lib/spec/stubs/cucumber.rb +2 -2
  54. data/lib/spec/version.rb +2 -2
  55. data/spec/autotest/autotest_helper.rb +1 -1
  56. data/spec/autotest/discover_spec.rb +2 -2
  57. data/spec/autotest/failed_results_re_spec.rb +2 -2
  58. data/spec/autotest/rspec_spec.rb +21 -6
  59. data/spec/spec/dsl/main_spec.rb +10 -2
  60. data/spec/spec/example/example_group_methods_spec.rb +21 -1
  61. data/spec/spec/example/example_group_proxy_spec.rb +1 -1
  62. data/spec/spec/example/example_group_spec.rb +1 -12
  63. data/spec/spec/example/example_matcher_spec.rb +3 -4
  64. data/spec/spec/example/subject_spec.rb +7 -0
  65. data/spec/spec/expectations/wrap_expectation_spec.rb +2 -1
  66. data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
  67. data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
  68. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
  69. data/spec/spec/matchers/be_spec.rb +159 -10
  70. data/spec/spec/matchers/has_spec.rb +109 -0
  71. data/spec/spec/matchers/have_spec.rb +278 -293
  72. data/spec/spec/matchers/match_array_spec.rb +8 -1
  73. data/spec/spec/matchers/matcher_spec.rb +70 -9
  74. data/spec/spec/matchers/raise_exception_spec.rb +345 -0
  75. data/spec/spec/matchers/simple_matcher_spec.rb +51 -44
  76. data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
  77. data/spec/spec/mocks/and_yield_spec.rb +117 -0
  78. data/spec/spec/mocks/bug_report_496_spec.rb +2 -4
  79. data/spec/spec/mocks/mock_spec.rb +2 -2
  80. data/spec/spec/runner/command_line_spec.rb +26 -5
  81. data/spec/spec/runner/drb_command_line_spec.rb +39 -0
  82. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
  83. data/spec/spec/runner/option_parser_spec.rb +12 -6
  84. data/spec/spec/runner/options_spec.rb +7 -0
  85. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
  86. data/spec/spec_helper.rb +2 -1
  87. metadata +107 -38
  88. data/lib/spec/matchers/raise_error.rb +0 -129
  89. data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
  90. data/spec/spec/matchers/raise_error_spec.rb +0 -333
  91. /data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
@@ -1,4 +1,4 @@
1
- require 'spec/autotest/autotest_helper'
1
+ require 'autotest/autotest_helper'
2
2
 
3
3
  describe "failed_results_re" do
4
4
  it "should match a failure" do
@@ -28,4 +28,4 @@ describe "failed_results_re" do
28
28
  $1.should == "this example"
29
29
  $2.should == "reason\n/path.rb:37:"
30
30
  end
31
- end
31
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/autotest/autotest_helper'
1
+ require 'autotest/autotest_helper'
2
2
 
3
3
  describe Autotest::Rspec do
4
4
  describe "adding spec.opts --options" do
@@ -26,17 +26,21 @@ describe Autotest::Rspec do
26
26
  @ruby = @rspec_autotest.ruby
27
27
  @spec_cmd = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec'))
28
28
  @options = @rspec_autotest.add_options_if_present
29
+ files = %w[file_one file_two]
29
30
  @files_to_test = {
30
- :spec => ["file_one", "file_two"]
31
+ files[0] => [],
32
+ files[1] => []
31
33
  }
32
34
  # this is not the inner representation of Autotest!
33
- @rspec_autotest.stub!(:files_to_test).and_return @files_to_test
34
- @files_to_test.stub!(:keys).and_return @files_to_test[:spec]
35
- @to_test = @files_to_test.keys.flatten.join ' '
35
+ @rspec_autotest.files_to_test = @files_to_test
36
+ @to_test = files.map { |f| File.expand_path(f) }.join ' '
36
37
  end
37
38
 
38
39
  it "should make the appropriate test command" do
39
- @rspec_autotest.make_test_cmd(@files_to_test).should == "#{@ruby} #{@spec_cmd} --autospec #{@to_test} #{@options}"
40
+ cmd = @rspec_autotest.make_test_cmd(@files_to_test)
41
+ (cmd =~ /#{@ruby} #{@spec_cmd} --autospec (.*) #{@options}/).should be_true
42
+ $1.should =~ /#{File.expand_path('file_one')}/
43
+ $1.should =~ /#{File.expand_path('file_two')}/
40
44
  end
41
45
 
42
46
  it "should return a blank command for no files" do
@@ -108,4 +112,15 @@ describe Autotest::Rspec do
108
112
  @rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file)
109
113
  end
110
114
  end
115
+
116
+ describe "normalizing file names" do
117
+ it "should ensure that a single file appears in files_to_test only once" do
118
+ @rspec_autotest = Autotest::Rspec.new
119
+ @files_to_test = {}
120
+ ['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
121
+ @files_to_test[file] = []
122
+ end
123
+ @rspec_autotest.normalize(@files_to_test).should have(1).file
124
+ end
125
+ end
111
126
  end
@@ -57,7 +57,6 @@ module Spec
57
57
  end
58
58
  end
59
59
 
60
-
61
60
  describe "#share_as" do
62
61
  def self.next_group_name
63
62
  @group_number ||= 0
@@ -68,6 +67,15 @@ module Spec
68
67
  def group_name
69
68
  @group_name ||= self.class.next_group_name
70
69
  end
70
+
71
+ before(:each) do
72
+ Spec.stub(:deprecate)
73
+ end
74
+
75
+ it "is deprecated" do
76
+ Spec.should_receive(:deprecate)
77
+ share_as group_name do; end
78
+ end
71
79
 
72
80
  it "registers a shared ExampleGroup" do
73
81
  block = lambda {|a,b|}
@@ -92,4 +100,4 @@ module Spec
92
100
  end
93
101
  end
94
102
  end
95
-
103
+
@@ -732,7 +732,7 @@ module Spec
732
732
  end
733
733
  end
734
734
 
735
- describe "#define" do
735
+ describe "#let" do
736
736
  let(:counter) do
737
737
  Class.new do
738
738
  def initialize
@@ -743,6 +743,7 @@ module Spec
743
743
  end
744
744
  end.new
745
745
  end
746
+
746
747
  it "generates an instance method" do
747
748
  counter.count.should == 1
748
749
  end
@@ -752,6 +753,25 @@ module Spec
752
753
  counter.count.should == 2
753
754
  end
754
755
  end
756
+
757
+ describe "#let!" do
758
+ let!(:creator) do
759
+ class Creator
760
+ @count = 0
761
+ def self.count
762
+ @count += 1
763
+ end
764
+ end
765
+ end
766
+
767
+ it "evaluates the value non-lazily" do
768
+ lambda { Creator.count }.should_not raise_error
769
+ end
770
+
771
+ it "does not interfere between tests" do
772
+ Creator.count.should == 1
773
+ end
774
+ end
755
775
  end
756
776
  end
757
777
  end
@@ -4,7 +4,7 @@ module Spec
4
4
  module Example
5
5
  describe ExampleGroupProxy do
6
6
  before(:each) do
7
- @group = stub("example group").as_null_object
7
+ @group = stub("example group",:nested_descriptions => []).as_null_object
8
8
  end
9
9
 
10
10
  attr_reader :group
@@ -19,20 +19,9 @@ module Spec
19
19
  @@class_variable = "a class variable"
20
20
 
21
21
  it "can access class variables in examples in Ruby 1.8" do
22
- with_ruby 1.8 do
23
- @@class_variable.should == "a class variable"
24
- end
22
+ @@class_variable.should == "a class variable"
25
23
  end
26
24
 
27
- it "can NOT access class variables in examples in Ruby 1.9" do
28
- with_ruby 1.9 do
29
- lambda do
30
- @@class_variable.should == "a class variable"
31
- end.should raise_error(NameError)
32
- end
33
- end
34
-
35
-
36
25
  end
37
26
 
38
27
  class ExampleClassVariablePollutionSpec < ExampleGroup
@@ -3,10 +3,9 @@ require 'spec_helper'
3
3
  module Spec
4
4
  module Example
5
5
  describe ExampleMatcher, "#matches?" do
6
- def match_examples(examples)
7
- simple_matcher do |actual, matcher|
8
- matcher.failure_message = "expected matcher.matches?(#{description.inspect}) to return true, got false"
9
- matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true"
6
+
7
+ Spec::Matchers.define :match_examples do |examples|
8
+ match do |actual|
10
9
  actual.matches?(examples)
11
10
  end
12
11
  end
@@ -86,6 +86,13 @@ module Spec
86
86
 
87
87
  describe ".its (to access subject's attributes)" do
88
88
  with_sandboxed_options do
89
+ it "allows before(:each) blocks on subjects in outer scope" do
90
+ group = Class.new(ExampleGroupDouble).describe(Array)
91
+ group.before(:each) { subject << 1 }
92
+ child = group.its(:length) { should == 1 }
93
+ child.run(options).should == true
94
+ end
95
+
89
96
  it "passes when expectation should pass" do
90
97
  group = Class.new(ExampleGroupDouble).describe(Array)
91
98
  child = group.its(:length) { should == 0 }
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  module Spec
4
4
  module Matchers
5
5
  describe "wrap_expectation" do
6
+ before { Spec.stub(:deprecate) }
6
7
 
7
8
  def stub_matcher
8
9
  @_stub_matcher ||= simple_matcher do
@@ -27,4 +28,4 @@ module Spec
27
28
  end
28
29
  end
29
30
  end
30
- end
31
+ end
@@ -5,43 +5,43 @@ describe "ExampleGroup with test/unit/interop" do
5
5
 
6
6
  describe "with passing examples" do
7
7
  it "should output 0 failures" do
8
- output = ruby("#{resources}/spec_that_passes.rb")
8
+ output = ruby("'#{resources}/spec_that_passes.rb'")
9
9
  output.should include("1 example, 0 failures")
10
10
  end
11
11
 
12
12
  it "should return an exit code of 0" do
13
- ruby("#{resources}/spec_that_passes.rb")
13
+ ruby("'#{resources}/spec_that_passes.rb'")
14
14
  $?.should == 0
15
15
  end
16
16
  end
17
17
 
18
18
  describe "with failing examples" do
19
19
  it "should output 1 failure" do
20
- output = ruby("#{resources}/spec_that_fails.rb")
20
+ output = ruby("'#{resources}/spec_that_fails.rb'")
21
21
  output.should include("1 example, 1 failure")
22
22
  end
23
23
 
24
24
  it "should return an exit code of 256" do
25
- ruby("#{resources}/spec_that_fails.rb")
25
+ ruby("'#{resources}/spec_that_fails.rb'")
26
26
  $?.should == 256
27
27
  end
28
28
  end
29
29
 
30
30
  describe "with example that raises an error" do
31
31
  it "should output 1 failure" do
32
- output = ruby("#{resources}/spec_with_errors.rb")
32
+ output = ruby("'#{resources}/spec_with_errors.rb'")
33
33
  output.should include("1 example, 1 failure")
34
34
  end
35
35
 
36
36
  it "should return an exit code of 256" do
37
- ruby("#{resources}/spec_with_errors.rb")
37
+ ruby("'#{resources}/spec_with_errors.rb'")
38
38
  $?.should == 256
39
39
  end
40
40
  end
41
41
 
42
42
  describe "options hash" do
43
43
  it "should be exposed" do
44
- output = ruby("#{resources}/spec_with_options_hash.rb")
44
+ output = ruby("'#{resources}/spec_with_options_hash.rb'")
45
45
  output.should include("1 example, 0 failures")
46
46
  end
47
47
  end
@@ -9,42 +9,42 @@ describe "Test::Unit::TestCase" do
9
9
 
10
10
  describe "with passing test case" do
11
11
  it "should output 0 failures" do
12
- output = ruby("#{@dir}/test_case_that_passes.rb")
12
+ output = ruby("'#{@dir}/test_case_that_passes.rb'")
13
13
  output.should include("1 example, 0 failures")
14
14
  end
15
15
 
16
16
  it "should return an exit code of 0" do
17
- ruby("#{@dir}/test_case_that_passes.rb")
17
+ ruby("'#{@dir}/test_case_that_passes.rb'")
18
18
  $?.should == 0
19
19
  end
20
20
  end
21
21
 
22
22
  describe "with failing test case" do
23
23
  it "should output 1 failure" do
24
- output = ruby("#{@dir}/test_case_that_fails.rb")
24
+ output = ruby("'#{@dir}/test_case_that_fails.rb'")
25
25
  output.should include("1 example, 1 failure")
26
26
  end
27
27
 
28
28
  it "should return an exit code of 256" do
29
- ruby("#{@dir}/test_case_that_fails.rb")
29
+ ruby("'#{@dir}/test_case_that_fails.rb'")
30
30
  $?.should == 256
31
31
  end
32
32
  end
33
33
 
34
34
  describe "with test case that raises an error" do
35
35
  it "should output 1 failure" do
36
- output = ruby("#{@dir}/test_case_with_errors.rb")
36
+ output = ruby("'#{@dir}/test_case_with_errors.rb'")
37
37
  output.should include("1 example, 1 failure")
38
38
  end
39
39
 
40
40
  it "should return an exit code of 256" do
41
- ruby("#{@dir}/test_case_with_errors.rb")
41
+ ruby("'#{@dir}/test_case_with_errors.rb'")
42
42
  $?.should == 256
43
43
  end
44
44
  end
45
45
 
46
46
  it "should find all Test::Unit test methods" do
47
- output = ruby("#{@dir}/test_case_with_various_names.rb")
47
+ output = ruby("'#{@dir}/test_case_with_various_names.rb'")
48
48
  output.should include("4 examples, 0 failures")
49
49
  end
50
50
  end
@@ -4,6 +4,6 @@ describe "TestSuiteAdapter" do
4
4
  include TestUnitSpecHelper
5
5
  it "should pass" do
6
6
  dir = File.dirname(__FILE__)
7
- run_script "#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb"
7
+ run_script "'#{dir}/resources/testsuite_adapter_spec_with_test_unit.rb'"
8
8
  end
9
9
  end
@@ -117,27 +117,143 @@ describe "should_not be_predicate(*args)" do
117
117
  end
118
118
  end
119
119
 
120
+ describe "should be_predicate(&block)" do
121
+ it "should pass when actual returns true for :predicate?(&block)" do
122
+ actual = mock("actual")
123
+ delegate = mock("delegate")
124
+ actual.should_receive(:happy?).and_yield
125
+ delegate.should_receive(:check_happy).and_return(true)
126
+ actual.should be_happy { delegate.check_happy }
127
+ end
128
+
129
+ it "should fail when actual returns false for :predicate?(&block)" do
130
+ actual = mock("actual")
131
+ delegate = mock("delegate")
132
+ actual.should_receive(:happy?).and_yield
133
+ delegate.should_receive(:check_happy).and_return(false)
134
+ lambda {
135
+ actual.should be_happy { delegate.check_happy }
136
+ }.should fail_with("expected happy? to return true, got false")
137
+ end
138
+
139
+ it "should fail when actual does not respond to :predicate?" do
140
+ delegate = mock("delegate", :check_happy => true)
141
+ lambda {
142
+ Object.new.should be_happy { delegate.check_happy }
143
+ }.should raise_error(NameError)
144
+ end
145
+ end
146
+
147
+ describe "should_not be_predicate(&block)" do
148
+ it "should pass when actual returns false for :predicate?(&block)" do
149
+ actual = mock("actual")
150
+ delegate = mock("delegate")
151
+ actual.should_receive(:happy?).and_yield
152
+ delegate.should_receive(:check_happy).and_return(false)
153
+ actual.should_not be_happy { delegate.check_happy }
154
+ end
155
+
156
+ it "should fail when actual returns true for :predicate?(&block)" do
157
+ actual = mock("actual")
158
+ delegate = mock("delegate")
159
+ actual.should_receive(:happy?).and_yield
160
+ delegate.should_receive(:check_happy).and_return(true)
161
+ lambda {
162
+ actual.should_not be_happy { delegate.check_happy }
163
+ }.should fail_with("expected happy? to return false, got true")
164
+ end
165
+
166
+ it "should fail when actual does not respond to :predicate?" do
167
+ delegate = mock("delegate", :check_happy => true)
168
+ lambda {
169
+ Object.new.should_not be_happy { delegate.check_happy }
170
+ }.should raise_error(NameError)
171
+ end
172
+ end
173
+
174
+ describe "should be_predicate(*args, &block)" do
175
+ it "should pass when actual returns true for :predicate?(*args, &block)" do
176
+ actual = mock("actual")
177
+ delegate = mock("delegate")
178
+ actual.should_receive(:older_than?).with(3).and_yield(3)
179
+ delegate.should_receive(:check_older_than).with(3).and_return(true)
180
+ actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
181
+ end
182
+
183
+ it "should fail when actual returns false for :predicate?(*args, &block)" do
184
+ actual = mock("actual")
185
+ delegate = mock("delegate")
186
+ actual.should_receive(:older_than?).with(3).and_yield(3)
187
+ delegate.should_receive(:check_older_than).with(3).and_return(false)
188
+ lambda {
189
+ actual.should be_older_than(3) { |age| delegate.check_older_than(age) }
190
+ }.should fail_with("expected older_than?(3) to return true, got false")
191
+ end
192
+
193
+ it "should fail when actual does not respond to :predicate?" do
194
+ delegate = mock("delegate", :check_older_than => true)
195
+ lambda {
196
+ Object.new.should be_older_than(3) { |age| delegate.check_older_than(age) }
197
+ }.should raise_error(NameError)
198
+ end
199
+ end
200
+
201
+ describe "should_not be_predicate(*args, &block)" do
202
+ it "should pass when actual returns false for :predicate?(*args, &block)" do
203
+ actual = mock("actual")
204
+ delegate = mock("delegate")
205
+ actual.should_receive(:older_than?).with(3).and_yield(3)
206
+ delegate.should_receive(:check_older_than).with(3).and_return(false)
207
+ actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
208
+ end
209
+
210
+ it "should fail when actual returns true for :predicate?(*args, &block)" do
211
+ actual = mock("actual")
212
+ delegate = mock("delegate")
213
+ actual.should_receive(:older_than?).with(3).and_yield(3)
214
+ delegate.should_receive(:check_older_than).with(3).and_return(true)
215
+ lambda {
216
+ actual.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
217
+ }.should fail_with("expected older_than?(3) to return false, got true")
218
+ end
219
+
220
+ it "should fail when actual does not respond to :predicate?" do
221
+ delegate = mock("delegate", :check_older_than => true)
222
+ lambda {
223
+ Object.new.should_not be_older_than(3) { |age| delegate.check_older_than(age) }
224
+ }.should raise_error(NameError)
225
+ end
226
+ end
227
+
120
228
  describe "should be_true" do
121
- it "should pass when actual equal(true)" do
229
+ it "should pass when actual equal?(true)" do
122
230
  true.should be_true
123
231
  end
124
232
 
125
- it "should fail when actual equal(false)" do
233
+ it "should pass when actual is 1" do
234
+ 1.should be_true
235
+ end
236
+
237
+ it "should fail when actual equal?(false)" do
126
238
  lambda {
127
239
  false.should be_true
128
- }.should fail_with("expected true, got false")
240
+ }.should fail_with("expected false to be true")
129
241
  end
130
242
  end
131
243
 
132
244
  describe "should be_false" do
133
- it "should pass when actual equal(false)" do
245
+ it "should pass when actual equal?(false)" do
134
246
  false.should be_false
135
247
  end
136
248
 
137
- it "should fail when actual equal(true)" do
249
+ it "should pass when actual equal?(nil)" do
250
+ nil.should be_false
251
+ end
252
+
253
+ it "should fail when actual equal?(true)" do
138
254
  lambda {
139
255
  true.should be_false
140
- }.should fail_with("expected false, got true")
256
+ }.should fail_with("expected true to be false")
141
257
  end
142
258
  end
143
259
 
@@ -173,6 +289,10 @@ describe "should be <" do
173
289
  it "should fail when < operator returns false" do
174
290
  lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
175
291
  end
292
+
293
+ it "should describe itself" do
294
+ be.<(4).description.should == "be < 4"
295
+ end
176
296
  end
177
297
 
178
298
  describe "should be <=" do
@@ -236,17 +356,32 @@ describe "should_not with operators" do
236
356
  end
237
357
 
238
358
  describe "should be" do
239
- it "should pass if actual is true or a set value" do
359
+ it "should pass if actual is truthy" do
240
360
  true.should be
241
361
  1.should be
242
362
  end
243
363
 
244
364
  it "should fail if actual is false" do
245
- lambda {false.should be}.should fail_with("expected true, got false")
365
+ lambda {false.should be}.should fail_with("expected false to evaluate to true")
246
366
  end
247
367
 
248
368
  it "should fail if actual is nil" do
249
- lambda {nil.should be}.should fail_with("expected true, got nil")
369
+ lambda {nil.should be}.should fail_with("expected nil to evaluate to true")
370
+ end
371
+
372
+ it "should describe itself" do
373
+ be.description.should == "be"
374
+ end
375
+ end
376
+
377
+ describe "should_not be" do
378
+ it "should pass if actual is falsy" do
379
+ false.should_not be
380
+ nil.should_not be
381
+ end
382
+
383
+ it "should fail on true" do
384
+ lambda {true.should_not be}.should fail_with("expected true to evaluate to false")
250
385
  end
251
386
  end
252
387
 
@@ -254,9 +389,23 @@ describe "should be(value)" do
254
389
  it "should pass if actual.equal?(value)" do
255
390
  5.should be(5)
256
391
  end
392
+
257
393
  it "should fail if !actual.equal?(value)" do
258
394
  lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
259
395
  end
396
+
397
+ it "should describe itself" do
398
+ be(5).description.should == "be 5"
399
+ end
400
+ end
401
+
402
+ describe "should_not be(value)" do
403
+ it "should pass if !actual.equal?(value)" do
404
+ 5.should_not be(6)
405
+ end
406
+ it "should fail if !actual.equal?(value)" do
407
+ lambda { 5.should_not be(5) }.should fail_with("expected not 5, got 5")
408
+ end
260
409
  end
261
410
 
262
411
  describe "'should be' with operator" do
@@ -308,4 +457,4 @@ describe "be_an_instance_of" do
308
457
  it "fails when class is higher up hierarchy" do
309
458
  5.should_not be_an_instance_of(Numeric)
310
459
  end
311
- end
460
+ end
@@ -70,6 +70,115 @@ describe "should_not have_sym(*args)" do
70
70
  end
71
71
  end
72
72
 
73
+ describe "should have_sym(&block)" do
74
+ it "should pass when actual returns true for :has_sym?(&block)" do
75
+ actual = mock("actual")
76
+ delegate = mock("delegate")
77
+ actual.should_receive(:has_foo?).and_yield
78
+ delegate.should_receive(:check_has_foo).and_return(true)
79
+ actual.should have_foo { delegate.check_has_foo }
80
+ end
81
+
82
+ it "should fail when actual returns false for :has_sym?(&block)" do
83
+ actual = mock("actual")
84
+ delegate = mock("delegate")
85
+ actual.should_receive(:has_foo?).and_yield
86
+ delegate.should_receive(:check_has_foo).and_return(false)
87
+ lambda {
88
+ actual.should have_foo { delegate.check_has_foo }
89
+ }.should fail_with("expected #has_foo?(nil) to return true, got false")
90
+ end
91
+
92
+ it "should fail when actual does not respond to :has_sym?" do
93
+ delegate = mock("delegate", :check_has_foo => true)
94
+ lambda {
95
+ Object.new.should have_foo { delegate.check_has_foo }
96
+ }.should raise_error(NameError)
97
+ end
98
+ end
99
+
100
+ describe "should_not have_sym(&block)" do
101
+ it "should pass when actual returns false for :has_sym?(&block)" do
102
+ actual = mock("actual")
103
+ delegate = mock("delegate")
104
+ actual.should_receive(:has_foo?).and_yield
105
+ delegate.should_receive(:check_has_foo).and_return(false)
106
+ actual.should_not have_foo { delegate.check_has_foo }
107
+ end
108
+
109
+ it "should fail when actual returns true for :has_sym?(&block)" do
110
+ actual = mock("actual")
111
+ delegate = mock("delegate")
112
+ actual.should_receive(:has_foo?).and_yield
113
+ delegate.should_receive(:check_has_foo).and_return(true)
114
+ lambda {
115
+ actual.should_not have_foo { delegate.check_has_foo }
116
+ }.should fail_with("expected #has_foo?(nil) to return false, got true")
117
+ end
118
+
119
+ it "should fail when actual does not respond to :has_sym?" do
120
+ delegate = mock("delegate", :check_has_foo => true)
121
+ lambda {
122
+ Object.new.should_not have_foo { delegate.check_has_foo }
123
+ }.should raise_error(NameError)
124
+ end
125
+ end
126
+
127
+ describe "should have_sym(*args, &block)" do
128
+ it "should pass when actual returns true for :has_sym?(*args, &block)" do
129
+ actual = mock("actual")
130
+ delegate = mock("delegate")
131
+ actual.should_receive(:has_foo?).with(:a).and_yield(:a)
132
+ delegate.should_receive(:check_has_foo).with(:a).and_return(true)
133
+ actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
134
+ end
135
+
136
+ it "should fail when actual returns false for :has_sym?(*args, &block)" do
137
+ actual = mock("actual")
138
+ delegate = mock("delegate")
139
+ actual.should_receive(:has_foo?).with(:a).and_yield(:a)
140
+ delegate.should_receive(:check_has_foo).with(:a).and_return(false)
141
+ lambda {
142
+ actual.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
143
+ }.should fail_with("expected #has_foo?(:a) to return true, got false")
144
+ end
145
+
146
+ it "should fail when actual does not respond to :has_sym?" do
147
+ delegate = mock("delegate", :check_has_foo => true)
148
+ lambda {
149
+ Object.new.should have_foo(:a) { |foo| delegate.check_has_foo(foo) }
150
+ }.should raise_error(NameError)
151
+ end
152
+ end
153
+
154
+ describe "should_not have_sym(*args, &block)" do
155
+ it "should pass when actual returns false for :has_sym?(*args, &block)" do
156
+ actual = mock("actual")
157
+ delegate = mock("delegate")
158
+ actual.should_receive(:has_foo?).with(:a).and_yield(:a)
159
+ delegate.should_receive(:check_has_foo).with(:a).and_return(false)
160
+ actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
161
+ end
162
+
163
+ it "should fail when actual returns true for :has_sym?(*args, &block)" do
164
+ actual = mock("actual")
165
+ delegate = mock("delegate")
166
+ actual.should_receive(:has_foo?).with(:a).and_yield(:a)
167
+ delegate.should_receive(:check_has_foo).with(:a).and_return(true)
168
+ lambda {
169
+ actual.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
170
+ }.should fail_with("expected #has_foo?(:a) to return false, got true")
171
+ end
172
+
173
+ it "should fail when actual does not respond to :has_sym?" do
174
+ delegate = mock("delegate", :check_has_foo => true)
175
+ lambda {
176
+ Object.new.should_not have_foo(:a) { |foo| delegate.check_has_foo(foo) }
177
+ }.should raise_error(NameError)
178
+ end
179
+ end
180
+
181
+
73
182
  describe "has" do
74
183
  it "should work when the target implements #send" do
75
184
  o = {:a => "A"}