Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing in context information to assert methods #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

haarg
Copy link
Contributor

@haarg haarg commented Feb 16, 2017

This isn't meant to be a finished product, but a starting point for discussion.

What I'd like to be able to do is attach attribute information when doing assertions, and have that information end up in the exception object and stringification.

Copy link
Member

@autarch autarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty reasonable. I had a few comments about the details.

@@ -29,6 +29,9 @@ use Specio::OO;
stack_trace => {
init_arg => undef,
},
context => {
isa => 'HashRef',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this really needs to be a HashRef. Is there any reason not to allow any defined value? I guess this would make including it in the as_string output harder, but as it stands this output won't be very helpful if the hashref contains any references of its own.

if ($self->context and my %context = %{$self->context}) {
$str
.= ' ('
. join(', ', map { "$_: $context{$_}" } sort keys %context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just use Specio::PartialDump here, which would make even more sense if this wasn't required to be a hashref.

};

like(
$e->as_string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to also test that $e->context contains what we expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants