<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>David Chelimsky: predicate_matchers</title>
    <link>http://blog.davidchelimsky.net/articles/2007/04/30/predicate_matchers</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>on software in process and practice</description>
    <item>
      <title>predicate_matchers</title>
      <description>&lt;p&gt;&lt;span style="color:red;font-weight:bold;"&gt;Updated on 5/2/2007&lt;/span&gt;&lt;/p&gt;


	&lt;p&gt;In RSpec-0.8 if you say &amp;#8230;&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;File.should_exist(path)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;... the expectation passes if File.exist?(path). Here&amp;#8217;s how that should look in RSpec-0.9, with the underscore removed:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;File.should exist(path)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Supporting this for any arbitrary predicate would require more method_missing magic than we were willing to stomach, so we added a means of easily declaring methods like this yourself. We&amp;#8217;ve supplied #exist out of the box, but you can add your own with a simple declaration.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s how you do this for an individual behaviour:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;describe Fish do
  predicate_matchers[:swim] = :can_swim?
  it "should swim" do
    Fish.new.should swim
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And here&amp;#8217;s how you define them globally, so they are available in every example in your suite:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;Spec::Runner.configure do |config|
  config.predicate_matchers[:swim] = :can_swim?
end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 30 Apr 2007 20:00:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:dbb0644c-b518-4e11-b0b3-100cb47293f3</guid>
      <author>David</author>
      <link>http://blog.davidchelimsky.net/articles/2007/04/30/predicate_matchers</link>
      <category>rspec</category>
      <category>ruby</category>
      <trackback:ping>http://blog.davidchelimsky.net/articles/trackback/233</trackback:ping>
    </item>
    <item>
      <title>"predicate_matchers" by David</title>
      <description>&lt;p&gt;I went ahead and changed this. A couple of others had the same reaction you did. It&amp;#8217;s in the trunk now and will be released as part of rspec 0.9.2 within the next day or so.&lt;/p&gt;


	&lt;p&gt;Cheers&lt;/p&gt;</description>
      <pubDate>Thu, 03 May 2007 01:30:35 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fc1da18f-2693-4860-98bf-d2caf2f3117a</guid>
      <link>http://blog.davidchelimsky.net/articles/2007/04/30/predicate_matchers#comment-241</link>
    </item>
    <item>
      <title>"predicate_matchers" by David</title>
      <description>&lt;p&gt;No &amp;#8211; this is correct &amp;#8211; at least it&amp;#8217;s how it works. Aslak and I debated which should be the key and which the value and felt this way made more sense. Perhaps we were wrong!&lt;/p&gt;


	&lt;p&gt;Any other opinions?&lt;/p&gt;</description>
      <pubDate>Tue, 01 May 2007 08:50:12 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:40b12e0e-4546-4041-876f-cfbb4d3cdf60</guid>
      <link>http://blog.davidchelimsky.net/articles/2007/04/30/predicate_matchers#comment-237</link>
    </item>
    <item>
      <title>"predicate_matchers" by Tim</title>
      <description>&lt;p&gt;Is that backward or do I misunderstand?
     predicate_matchers[:can_swim?] = :swim
and not:
     predicate_matchers[:swim] = [:can_swim?]&lt;/p&gt;


	&lt;p&gt;Is the hash keyed by the word used in the test (&amp;#8220;swim&amp;#8221;) so that you have to do a &amp;#8220;backward&amp;#8221; search?  Or is it the other way round?  Maybe it&amp;#8217;s my ruby-ignorance showing, but it sure looks backward.&lt;/p&gt;</description>
      <pubDate>Tue, 01 May 2007 00:34:10 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:6c6d4688-eb47-4734-b0fd-7bde698275e4</guid>
      <link>http://blog.davidchelimsky.net/articles/2007/04/30/predicate_matchers#comment-234</link>
    </item>
  </channel>
</rss>
