Patches item #13907, was opened at 2007-09-13 15:34
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=13907&group_id=797
Category: expectation module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Bret Pettichord (bret)
Assigned to: Nobody (None)
Summary: Would like "exist" to be in Spec::Matchers (like the others)
Initial Comment:
I had submitted a patch http://rubyforge.org/tracker/?func=detail&group_id=797&aid=10473&atid=3152, but it was refactored in a way that reduced its scope. Specifically, I would like "should exist" to work in any class that includes Spec::Matchers, not just the it-blocks.
Attached please find an additional test that fails with the current version of Rspec (as well as prior versions), but passes with my originally submitted implementation of "exist". For convenience, i have included that implementation in this test, so that the test actually passes if you apply the patch. To reproduced the failure, you'll have to remove this added class.
The right solution is probably more complicated, but i never quite understood how my original solution was refactored, so i'm not sure what the best solution would be.
Thank you for your consideration. With Watir, we regularly extract test code out of the specs, and therefore this ability is valuable to us. We have not seen this problem with the other methods in Spec::Matchers.
Bret
Index: C:/work/rspec-rspec/spec/spec/matchers/exist_spec.rb
===================================================================
--- C:/work/rspec-rspec/spec/spec/matchers/exist_spec.rb (revision 2561)
+++ C:/work/rspec-rspec/spec/spec/matchers/exist_spec.rb (working copy)
@@ -45,4 +45,47 @@
should fail
end
end
+
+# Additional Test
+module Spec
+ module Matchers
+ class Exist
+ def matches? actual
+ @actual = actual
+ @actual.exist?
+ end
+ def failure_message
+ "expected #{@actual.inspect} to exist, but it doesn't."
+ end
+ def negative_failure_message
+ "expected #{@actual.inspect} to not exist, but it does."
+ end
+ end
+ def exist; Exist.new; end
+ end
+end
+
+class SubstanceTester
+ include Spec::Matchers
+ def initialize substance
+ @substance = substance
+ end
+ def assert_exists
+ @substance.should exist
+ end
+end
+
+describe "should exist, outside of a behavior" do
+ before(:each) do
+ @real = Substance.new true, 'something real'
+ @imaginary = Substance.new false, 'something imaginary'
+ end
+ it "should still pass if target exists" do
+ real_tester = SubstanceTester.new @real
+ real_tester.assert_exists
+ end
+end
+
+
+
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=13907&group_id=797