Re: [Mojolicious] Re: Testing internal method

2020-04-27 Thread Alberto Mijares
On Mon, Apr 27, 2020 at 11:46 PM Glen  wrote:
>
> He's implying that you wouldn't test this internal method with Test::Mojo; 
> Test::Mojo is for testing endpoints.


Thank you, guys.

This was the explanation I was needing.

Tests running now.


Alberto Mijares

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CAGZBXN-d8r%2BaeJ63nN_Ns56SWS%3DzTmjjOCx%2Bn%3DvdpP4JCV%3DPsw%40mail.gmail.com.


Re: [Mojolicious] Re: Testing internal method

2020-04-27 Thread Stefan Adams
I think Scott and Glen are both pointing out that your method in your
controller class that is not associated with a route ("filter") is not a
method of your controller, but instead in the "model" portion of MVC.  It
might help you to move that code outside of the controller class, and then
it'll make much more sense to test it normally with Test::More instead of
Test::Mojo.

# lib/App/Controller/This.pm
package App::Controller::This;
use Mojo::Base 'Mojolicious::Controller';
sub list {
  my $self = shift;
  my $model = App::Model->new;
  my $value = $self->req->json('/value');
  $self->render(json => {value => $model->filter(@$value)});
}

# lib/App/Model.pm
package App::Model;
use Mojo::Base -base;
sub filter {
  my $self = shift;
  my $final;
  /something/ and push @$final, $_ for @_;
  return $final;
}

And then you can test your filter method normally:

# t/basic.t
use Test::More;
use Test::Mojo;

# Test the controller / action and the use of any models
my $t = Test::Mojo->new('App');
$t->get_ok('/list' => json => {value => ['abc', 'def something ghi', 'jkl',
'mno something pqr']})
   ->status_is(200)
   ->json_is('/value', ['def something ghi', 'mno something pqr']);

# Test just the model
my $model = App::Model->new;
isa_ok $model, 'App::Model';
is_deeply $model->filter('abc', 'def something ghi', 'jkl', 'mno something
pqr'), ['def something ghi', 'mno something pqr'];

On Mon, Apr 27, 2020 at 10:46 PM Glen  wrote:

> He's implying that you wouldn't test this internal method with Test::Mojo; 
> Test::Mojo
> is for testing endpoints.
>
> If you want to test a specific method that is not an endpoint, load the
> module manually and test it with Test::More.
>
> On Apr 27, 2020, 11:32 PM -0400, Alberto Mijares ,
> wrote:
>
>
>
> On Mon, Apr 27, 2020, 7:09 PM Scott Wiersdorf 
> wrote:
>
>> Test::Mojo can help you test your views and controllers, as well as your
>> internal helpers:
>>
>>
>> https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Testing.pod#Testing-application-helpers
>>
>
> Thank you Scott.
>
> I did read the documentation before writing this email and saw what you
> are pointing out. The thing is: it's not clear enough for me.
>
> Given the example in my original post, could you give me a more detailed
> explanation? I don't know how to trigger this specific method.
>
> Thanks in advance for your help.
>
> Alberto Mijares
>
>
>> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/CAGZBXN9VBvBFZdkmpaJOPHFJ5V5h98GdqmsqjH%2B7wN6bRNpAuQ%40mail.gmail.com
> 
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/985dbe91-4202-406e-9b28-dd44922933a7%40Spark
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFSRKsEpxnRvmP1MJ9mHpQVZq9SqhUUiywOS3zuROj5nDQ%40mail.gmail.com.


Re: [Mojolicious] Re: Testing internal method

2020-04-27 Thread Glen
He's implying that you wouldn't test this internal method with Test::Mojo; 
Test::Mojo is for testing endpoints.

If you want to test a specific method that is not an endpoint, load the module 
manually and test it with Test::More.

On Apr 27, 2020, 11:32 PM -0400, Alberto Mijares , wrote:
>
>
> > On Mon, Apr 27, 2020, 7:09 PM Scott Wiersdorf  
> > wrote:
> > > Test::Mojo can help you test your views and controllers, as well as your 
> > > internal helpers:
> > >
> > > https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Testing.pod#Testing-application-helpers
>
> Thank you Scott.
>
> I did read the documentation before writing this email and saw what you are 
> pointing out. The thing is: it's not clear enough for me.
>
> Given the example in my original post, could you give me a more detailed 
> explanation? I don't know how to trigger this specific method.
>
> Thanks in advance for your help.
>
> Alberto Mijares
>
> > >
> --
> You received this message because you are subscribed to the Google Groups 
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/mojolicious/CAGZBXN9VBvBFZdkmpaJOPHFJ5V5h98GdqmsqjH%2B7wN6bRNpAuQ%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/985dbe91-4202-406e-9b28-dd44922933a7%40Spark.


Re: [Mojolicious] Re: Testing internal method

2020-04-27 Thread Alberto Mijares
On Mon, Apr 27, 2020, 7:09 PM Scott Wiersdorf 
wrote:

> Test::Mojo can help you test your views and controllers, as well as your
> internal helpers:
>
>
> https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Testing.pod#Testing-application-helpers
>

Thank you Scott.

I did read the documentation before writing this email and saw what you are
pointing out. The thing is: it's not clear enough for me.

Given the example in my original post, could you give me a more detailed
explanation? I don't know how to trigger this specific method.

Thanks in advance for your help.

Alberto Mijares


>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CAGZBXN9VBvBFZdkmpaJOPHFJ5V5h98GdqmsqjH%2B7wN6bRNpAuQ%40mail.gmail.com.


[Mojolicious] Re: Testing internal method

2020-04-27 Thread Scott Wiersdorf
Test::Mojo can help you test your views and controllers, as well as your 
internal helpers:

https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Testing.pod#Testing-application-helpers

If you are wanting to test your application *model* (i.e., non-Mojolicious 
code), you should probably use standard Test::More to create an object, 
exercise its methods, etc.

Scott

On Monday, April 27, 2020 at 4:55:43 PM UTC-6, Alberto Mijares wrote:
>
> Hi guys, 
>
> I've been reading about testing and can't figure out how to test 
> internal methods; meaning those methods not directly associated to a 
> route. 
>
> I'm sure most of you know what I'm talking about but just for the 
> record. Let's say you have in App::Controller::This 
>
> sub list { 
> my $self = shift; 
> $self->render(text => $self->filter($value)); 
> } 
>
> sub filter { 
> my $self = shift; 
> for @list {push (@final, $line) if ($line =~ /something/);} 
> return \@final 
> } 
>
> And in lib/App.pm you have 
>
> $c->get('/list)->to('this#list'); 
>
> So, I want to test returned values from App::Controller::This->filter. 
>
> Thanks in advance for your help. 
>
>
> Alberto Mijares 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/6fd72956-78ed-4922-bf30-e3cad431e5e0%40googlegroups.com.