[rspec-devel] [ rspec-Patches-13907 ] Would like "exist" to be in Spec::Matchers (like the others)

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 18 20:07:25 EST 2007


Patches item #13907, was opened at 2007-09-13 20: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: Closed
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
+
+
+
     


----------------------------------------------------------------------

Comment By: Chad Humphries (spicycode)
Date: 2007-11-19 00:55

Message:
Moved to http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/9-would-like-exist-to-be-in-spec-matchers-like-the-others

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-09-16 08:05

Message:
I added the failing example to r2566 (set to pending). We got rid of the matcher when we added a default set of predicate matchers that included exist. We only added that to the ExampleApi, so we'd need to move the whole predicate matchers bit over to Spec::Matchers to get it to work. This is now on the radar but not first priority. If you can figure out how to do that, feel free to submit another patch. Otherwise, we'll get to it eventually.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=13907&group_id=797


More information about the rspec-devel mailing list