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

Testing Mojo::DOM with Test::Mojo #1046

Closed
wants to merge 1 commit into from
Closed

Testing Mojo::DOM with Test::Mojo #1046

wants to merge 1 commit into from

Conversation

marcusramberg
Copy link
Member

Summary

Expose dom as an attribute on Test::Mojo to allow testing Mojo::DOM objects without involving a user agent. Revised version of #1045 with new tests instead of changing t/mojo/dom.t

my $t=Test::Mojo->new();
$t->dom(Mojo::DOM->new('<foo>bar</foo>'));
$t->is_text('foo','bar');

Motivation

This makes it easy to use Test::Mojo to test the contents of HTML/XML strings.

@@ -0,0 +1,10 @@
package TestApp;
Copy link
Member

Choose a reason for hiding this comment

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

This class doesn't really add much value, does it? Couldn't you just as well have used Mojolicious::Lite in the test file?

@kraih
Copy link
Member

kraih commented Jan 30, 2017

Looks like your pull request is borked, it contains my last commit.

@marcusramberg
Copy link
Member Author

Fixed the extra commit, and moved the test app into the t/test-mojo.t file - Will rebase and force push if the pull request is accepted.

@kraih
Copy link
Member

kraih commented Jan 30, 2017

Move it into t/mojo/test.t.

Changes Outdated
@@ -1,5 +1,6 @@

7.24 2017-01-30
- Expose dom as an attribute on Test::Mojo.
Copy link
Member

Choose a reason for hiding this comment

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

No need for a Changes entry, i'll rewrite it anyway. 😉

lib/Test/Mojo.pm Outdated
@@ -17,7 +17,8 @@ use Mojo::Util qw(decode encode);
use Test::More ();

has [qw(message success tx)];
has ua => sub { Mojo::UserAgent->new->ioloop(Mojo::IOLoop->singleton) };
has ua => sub { Mojo::UserAgent->new->ioloop(Mojo::IOLoop->singleton) };
has dom => sub { shift->tx->res->dom };
Copy link
Member

Choose a reason for hiding this comment

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

Order is not alphabetical.

lib/Test/Mojo.pm Outdated
=head2 dom

my $dom = $t->dom;
$t = $t->dom(Mojo::DOM->new);
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is borked here.

t/test-mojo.t Outdated
use Mojo::Base -strict;

BEGIN {
$ENV{MOJO_MODE} = 'testing';
Copy link
Member

Choose a reason for hiding this comment

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

The mode does not appear to be used anywhere in the test.

t/test-mojo.t Outdated
$ENV{MOJO_MODE} = 'testing';
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}
use FindBin;
Copy link
Member

Choose a reason for hiding this comment

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

FindBin does not appear to used anywhere.

Copy link
Member

@jberger jberger left a comment

Choose a reason for hiding this comment

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

As I mentioned on the previous PR, I have wanted something like this before. This is a fairly clean and consistent way to achieve it (consistent with the tx attribute).

@nicomen
Copy link

nicomen commented Jan 31, 2017

Long sought-after and clean enough. Good work ;)

@kraih
Copy link
Member

kraih commented Feb 1, 2017

I'd really like to hear more about how you're planning to use this.

@jberger
Copy link
Member

jberger commented Feb 1, 2017

My use has usually been with mixed type apis. So if there's say a json api that has a key who's value is HTML. This happens rather commonly with backend-rendered content for a single page front-end.

$t->get('/some/resource/with/html.json')
  ... # json tests

$t->dom(Mojo::DOM->new($t->tx->res->json('/contains/html')));
$t->... # html tests

at least, that's how I've wanted it in the past.

@kraih kraih requested review from tempire, amenonsen, kraih and jberger and removed request for jberger February 1, 2017 22:12
Copy link
Member

@kraih kraih left a comment

Choose a reason for hiding this comment

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

I'm neutral on this feature.

@kraih
Copy link
Member

kraih commented Feb 1, 2017

@jhthorsen, @amenonsen and @tempire still have to review.

@jhthorsen
Copy link
Member

I'm neutral. There are times when I want to poke into the "res" for manual testing or debugging, but I don't think the "dom" attribute is special for my cases.

@kraih
Copy link
Member

kraih commented Feb 2, 2017

@jhthorsen Please do a formal review, so we can see the result "Reviewers" list at the top.

Copy link
Member

@jhthorsen jhthorsen left a comment

Choose a reason for hiding this comment

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

I'm not sure if I'm a fan of having two attributes holding the Mojo::DOM object and require synchronizing. Seems to me that this functionality should be achieved in a different class, with a clear statement for what functionality it provides. But I would rather solve the problem with a simple Lite app in the test instead of requesting a change in Test::Mojo.

@kraih
Copy link
Member

kraih commented Feb 3, 2017

Guess i'm slightly 👎 on this as well, something just doesn't feel right about it.

@kraih
Copy link
Member

kraih commented Feb 5, 2017

I'm afraid this pull request did not pass the vote as it ended in a tie, which means i had to make the final decision. What ultimately made me decide against it was the fact that the feature can be easily implemented as a Test::Mojo::Role and that there was only a single rather uncommon use case presented.

@kraih kraih closed this Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants