[rspec-users] Continuing a "specify" block after failure

aslak hellesoy aslak.hellesoy at gmail.com
Mon Feb 26 16:43:57 EST 2007


On 2/26/07, leenoori <leenoori at quepica.com> wrote:
> I have some high-level acceptance tests that read a bunch of files,
> process them, and then confirm that the processed output matches the
> expected output. That is, for each file "a.input" I have a
> corresponding file "a.expected" and I basically want to churn through
> all of them producing "a.processed" and making sure that
> "a.processed" equals "a.expected"
>
> The way I currently have this is:
>
> context 'transforming files' do
>    specify 'actual output should match expected output' do
>      @files.each do |file|
>        file.input.process.should == file.expected
>      end
>    end
> end
>
> The problem with this is that a failure on one file prevents all the
> others from being tested. What would be the "best practice" way to
> overcome this shortcoming?
>
> The solution I used with Test::Unit was to add an "ErrorCollector" as
> described here:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320
>
> Basically it catches exceptions as they are raised, sending messages
> to the Test::Unit machinery so that the problems can be counted and
> reported, but continues processing.
>
> Would a similar technique be a good idea for RSpec?

No, because it's already supported by what you suggest below.

> Or should I just
> restructure my specs?

Yes

> By that I mean something like the following
> (although not sure if it will work):
>

It will, with a minor modification - you should make sure the name of
each specify
block is different, otherwise you'll have a hard time knowing shich one failed.

> context 'transforming files' do
>    files.each do |file|
>      specify 'actual output should match expected output' do
>        file.input.process.should == file.expected
>      end
>    end
> end
>

I have just checked in an example that illustrates this:

http://rubyforge.org/viewvc/trunk/rspec/examples/dynamic_spec.rb?revision=1537&root=rspec

Aslak

> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list