Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Testing a Dancer2 app with locally installed modules

by GertMT (Friar)
on Oct 27, 2020 at 21:44 UTC ( #11123236=perlquestion: print w/replies, xml ) Need Help??

GertMT has asked for the wisdom of the Perl Monks concerning the following question:

Just decided to get more into testing (i've read it is almost guaranteed my code will improve..). I created a new Dancer2 app. The modules I use are installed locally via a cpanfile and a `carton install` command. Everything works though I cannot get the testing to work as I get warnings like:

Can't locate Dancer2/Plugin/Database.pm in @INC (you may need to insta +ll the Dancer2::Plugin::Database module)
bin/app.psgi looks like:
#!/usr/bin/env perl use strict; use warnings; use File::Basename; use File::Spec; use lib File::Spec->catdir( File::Basename::dirname( File::Spec->rel2a +bs($0) ), '..', 'local/lib/perl5' ); use lib File::Spec->catdir( File::Basename::dirname( File::Spec->rel2a +bs($0) ), '..', 'lib' ); use jwsDancer; jwsDancer->to_app;
lib/jwsDancer.pm
package jwsDancer; use Dancer2; use Dancer2::Plugin::Database; use Dancer2::FileUtils qw/path read_file_content/; use Cwd qw(abs_path); use lib dirname( dirname abs_path $0) . '/../../lib'; get '/' => sub { template 'index' => { 'title' => 'a web page' }; true;

For now I'm just trying to use the test that is generated by scaffolding a Dancer2 app via

prove -lv t/002_index_route.t

Can anyone give a hint what I should do to have the locally installed modules (in local/lib/perl5) work as well in the testing environment?

Replies are listed 'Best First'.
Re: Testing a Dancer2 app with locally installed modules
by Anonymous Monk on Oct 28, 2020 at 03:01 UTC

    Why aren't you using boilerplate?

    hardcode

    $ perldoc prove |grep include -I Library paths to include.

      jwsDancer\bin\myprove.pl

      use FindBin; chdir "$FindBin::Bin/.."; # jwsDancer/bin/.. system $^X, '-S', 'prove', "-I$FindBin::Bin/../lib", # jwsDancer/bin/../lib "-I$FindBin::Bin/../../local/lib/perl5", # jwsDancer/bin/../../local/lib/perl5 @ARGV;

        Thank you Anonymous Monk!

        Apparently the code in lib/jwsDancer.pm contained an error.

        With the script as you suggested in bin/myprove.pl I got it to work changing the path slightly (erroneously it went up one directory too far).

        use FindBin; chdir "$FindBin::Bin/.."; # jwsDancer/bin/.. system $^X, '-S', 'prove', "-I$FindBin::Bin/../lib", # jwsDancer/bin/../lib "-I$FindBin::Bin/../local/lib/perl5", # jwsDancer/bin/../local/lib/perl5 @ARGV;

        All tests run smoothly with modules locally installed and a command like: perl bin/myprove.pl -lv t/*

        Gert

      If I may ask, what actually would have been considered using boilerplate?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11123236]
Approved by hippo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-12-04 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (58 votes). Check out past polls.

    Notices?