testing for exceptions

396 views
Skip to first unread message

Bradley

unread,
Nov 24, 2009, 10:41:38 PM11/24/09
to Cukes
I'm brand new to cucumber so bear with me. I'm trying to write
features against Makandra Aegis (http://github.com/makandra/aegis)
role based permissions. When a user doesn't have access to a page, it
raises an Aegis Exception. I'm trying to test that this exception is
in fact shown, but the cucumber test fails BECAUSE the exception is
thrown.

How do I go about dealing with exceptions in cucumber?

aslak hellesoy

unread,
Nov 25, 2009, 3:50:59 AM11/25/09
to cu...@googlegroups.com
> I'm brand new to cucumber so bear with me.

Welcome!

> I'm trying to write
> features against Makandra Aegis (http://github.com/makandra/aegis)
> role based permissions.  When a user doesn't have access to a page, it
> raises an Aegis Exception.  I'm trying to test that this exception is
> in fact shown, but the cucumber test fails BECAUSE the exception is
> thrown.
>

This is done in your Cucumber step definition with your "assertion" library.

If you use RSpec:

# http://rspec.rubyforge.org/rspec/1.2.9/classes/Spec/Matchers.html#M000176
lambda { code_that_you_expect_to_fail }.should raise_error(ErrorClass,
/error message/)

If you use Test::Unit:

# http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004508
assert_raise(ErrorClass) { code_that_you_expect_to_fail }

Aslak

> How do I go about dealing with exceptions in cucumber?
>
> --
>
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>
>
>

byrnejb

unread,
Nov 25, 2009, 9:00:06 AM11/25/09
to Cukes


On Nov 25, 3:50 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:

>
> This is done in your Cucumber step definition with your "assertion" library.
>
> If you use RSpec:
>
> #http://rspec.rubyforge.org/rspec/1.2.9/classes/Spec/Matchers.html#M00...
> lambda { code_that_you_expect_to_fail }.should raise_error(ErrorClass,
> /error message/)
>
> If you use Test::Unit:
>
> #http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/As...
> assert_raise(ErrorClass) { code_that_you_expect_to_fail }
>
> Aslak
>

I learn something new (to me) and useful here every single day.

Bradley

unread,
Nov 25, 2009, 5:19:24 PM11/25/09
to Cukes
awesome, thx so much!

On Nov 25, 3:50 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> > I'm brand new to cucumber so bear with me.
>
> Welcome!
>
> > I'm trying to write
> > features against Makandra Aegis (http://github.com/makandra/aegis)
> > role based permissions.  When a user doesn't have access to a page, it
> > raises an Aegis Exception.  I'm trying to test that this exception is
> > in fact shown, but the cucumber test fails BECAUSE the exception is
> > thrown.
>
> This is done in your Cucumber step definition with your "assertion" library.
>
> If you use RSpec:
>
> #http://rspec.rubyforge.org/rspec/1.2.9/classes/Spec/Matchers.html#M00...
> lambda { code_that_you_expect_to_fail }.should raise_error(ErrorClass,
> /error message/)
>
> If you use Test::Unit:
>
> #http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/As...
Reply all
Reply to author
Forward
0 new messages