-
Notifications
You must be signed in to change notification settings - Fork 576
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
Conversation
t/mojolicious/lib/TestApp.pm
Outdated
@@ -0,0 +1,10 @@ | |||
package TestApp; |
There was a problem hiding this comment.
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?
Looks like your pull request is borked, it contains my last commit. |
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. |
Move it into |
Changes
Outdated
@@ -1,5 +1,6 @@ | |||
|
|||
7.24 2017-01-30 | |||
- Expose dom as an attribute on Test::Mojo. |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
…ctly with Test::Mojo
There was a problem hiding this 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).
Long sought-after and clean enough. Good work ;) |
I'd really like to hear more about how you're planning to use this. |
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. |
There was a problem hiding this 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.
@jhthorsen, @amenonsen and @tempire still have to review. |
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. |
@jhthorsen Please do a formal review, so we can see the result "Reviewers" list at the top. |
There was a problem hiding this 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.
Guess i'm slightly 👎 on this as well, something just doesn't feel right about it. |
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 |
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
Motivation
This makes it easy to use Test::Mojo to test the contents of HTML/XML strings.