[rspec-users] inverse examples? (should fail)

David Chelimsky dchelimsky at gmail.com
Sat Jun 23 12:47:37 EDT 2007


On 6/23/07, Chris Anderson <jchris at mfdz.com> wrote:
> The new "pending" example feature reminds me of a feature I've been
> bouncing around in my head, to aid in refactoring. Often, when I'm
> changing existing behaviour, I know that certain aspects of the old
> behaviour should change. Imagine changing the "it" method to perhaps
> "not" or "old" or "removed"... The behaviour would be to raise a spec
> error if the example DOES NOT fail. So if
>
> it "should do something that's been deprecated" do
>   my_object.should_receive(:deprecated_message)
>   action
> end
>
> passes, than
>
> old "should do something that's been deprecated" do
>   my_object.should_receive(:deprecated_message)
>   action
> end
>
> ought to fail.
>
> It seems like this might be a good first line of defense when starting
> a big refactor.
>
> I'm not sure about the wording - maybe there's a better way of
> expressing it - perhaps as a second argument to the spec (but that
> would be a little less fun to pepper throughout a document).
>
> it "should do something that's been deprecated", :inverse => true do
>   my_object.should_receive(:deprecated_message)
>   action
> end
>
> Thoughts? Does this exist already and I haven't noticed it?

It doesn't exist in rspec, but something like it does in rspec_ext:

http://rashkovskii.com/articles/2007/1/25/rspec-specify_negatively
http://rubyforge.org/projects/rspec-ext/

I haven't used that, so I don't know if it works with the latest
version or not, but you can give it a shot.

As for including this in rspec, I'm not really understanding it's
value. How would saying something should fail, and failing it if it
doesn't, help you (unless you're writing another behaviour definition
framework ;) )?

>
> --
> Chris Anderson
> http://jchris.mfdz.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list