spec/spec/matchers/have_spec.rb in rspec-1.0.4 vs spec/spec/matchers/have_spec.rb in rspec-1.0.5
- old
+ new
@@ -45,10 +45,23 @@
owner.should have(2).items_in_collection_with_size_method
}.should fail_with("expected 2 items_in_collection_with_size_method, got 3")
end
end
+describe "should have(n).items where result responds to items but returns something other than a collection" do
+ it "should provide a meaningful error" do
+ owner = Class.new do
+ def items
+ Object.new
+ end
+ end.new
+ lambda do
+ owner.should have(3).items
+ end.should raise_error(RuntimeError, "expected items to be a collection but it does not respond to #length or #size")
+ end
+end
+
describe "should_not have(n).items" do
include HaveSpecHelper
it "should pass if target has a collection of items with < n members" do
owner = create_collection_owner_with(3)
@@ -254,6 +267,6 @@
describe "have(n).things on an object which is not a collection nor contains one" do
it "should fail" do
lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
end
-end
\ No newline at end of file
+end