David Chelimsky

random thoughtlessness


Updated on 5/2/2007

In RSpec-0.8 if you say …


… the expectation passes if File.exist?(path). Here’s how that should look in RSpec-0.9, with the underscore removed:

<code>File.should exist(path)

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’ve supplied #exist out of the box, but you can add your own with a simple declaration.

Here’s how you do this for an individual behaviour:

<code>describe Fish do
predicate_matchers[:swim] = :can_swim?
it "should swim" do
  Fish.new.should swim

And here’s how you define them globally, so they are available in every example in your suite:

<code>Spec::Runner.configure do |config|
config.predicate_matchers[:swim] = :can_swim?