2011-06-29 11 views
8

私はwwwを機械化するためのスクリプトアプリケーションを設定する正しい方法についてはわかりません。私は少なくとも1つの代替機能を試してみましたが、テストスイートを使って静かにログを記録できるように、テストで設定を渡そうとしています。スクリプトのdoを実行しているTest :: WWW :: Mechanize :: PSGIでDancerアプリケーションをテストするにはどうすればいいですか?

#!/usr/bin/perl 
use strict; 
use warnings; 
use Dancer qw(:syntax); 
use MyApp; 
use Test::More; 
use Test::WWW::Mechanize::PSGI; 
set apphandler => 'PSGI'; 
set log => 'warning'; 
set logger => 'note'; 

my $mech = Test::WWW::Mechanize::PSGI->new(
    app => dance, # app => do('bin/app.pl'), # 
); 

$mech->get_ok('/login') or diag $mech->content; 
done_testing; 

は、テストの実行を許可するようだが、ログ変数は、右に設定されていないと、それを行うには良い方法があるだろうように、同時にそうです。

更新

私はPlack PSGIためDancer::Deployment documentationからこれを取っ

#!/usr/bin/perl 
use strict; 
use warnings; 
use FindBin; 
use Cwd qw(realpath); 
use Dancer qw(:syntax); 
use MyApp; 
use Test::More; 
use Test::WWW::Mechanize::PSGI; 
set apphandler => 'PSGI'; 

my $appdir = realpath("$FindBin::Bin/.."); 
my $mech = Test::WWW::Mechanize::PSGI->new(
    app => sub { 
     my $env = shift; 
     setting(
      appname => 'MyApp', 
      appdir => $appdir, 
     ); 
     load_app 'MyApp'; 
     config->{environment} = 'test'; # setting test env specific in test.yml detected ok 
     Dancer::Config->load; 
     my $request = Dancer::Request->new(env => $env); 
     Dancer->dance($request); 
    } 
); 

$mech->get_ok('/login') or diag $mech->content; 


done_testing; 

...私は解決策に近づいかもしれないと思います。しかし、私はテストから500エラーを得ています。

t/001-login.t .. Subroutine main::pass redefined at t/001-login.t line 8 
Prototype mismatch: sub main::pass: none vs (;$) at t/001-login.t line 8 
Use of uninitialized value $_[0] in join or string at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/i686-linux/File/Spec/Unix.pm line 86. 

# [2462] debug @0.004442> [hit #1]Adding mysql_enable_utf8 to DBI connection params to enable UTF-8 support in /home/ccushing/perl5/perlbrew/perls/perl- 5.14.1/lib/site_perl/5.14.1/Dancer/Plugin/Database.pm l. 148 
# [2462] debug @0.117566> [hit #1]Adding mysql_enable_utf8 to DBI connection params to enable UTF-8 support in /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer/Plugin/Database.pm l. 148 
# [2462] error @0.148703> [hit #1]request to /login crashed: '/login/default.tt' doesn't exist or not a regular file at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer.pm line 161 in /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer/Handler.pm l. 84 
# <h2>runtime error</h2><pre class="error">&#39;/login/default.tt&#39; doesn&#39;t exist or not a regular file at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer.pm line 161 

ここではDBIエラーは関係ありませんが、エラー出力の一部が表示されます。私はなぜそれが見つけることができないのか分かりません/login/default.tt。私はそれが問題だと推測しているのは、テンプレートが問題のテンプレートのどこにあるのかわからないからです。views/login/default.ttです。このビューは、plackupで実行していてもブラウザーで正常に動作します。私は困惑している。

答えて

3

これは私が現在、私は1 hereを提出し、this test case repositoryを作成し、これはおそらくバグの結果であると考えていviewst/viewsシンボリックリンク状況の下で動作します。

#!/usr/bin/perl 
use strict; 
use warnings; 
BEGIN { 
    use Test::More; 
    use namespace::clean qw(pass); 
} 
use FindBin; 
use Cwd qw(realpath); 
use Dancer qw(:syntax); 
#use MyApp; 
use Test::WWW::Mechanize::PSGI; 
set apphandler => 'PSGI'; 

my $appdir = realpath("$FindBin::Bin/.."); 
my $mech = Test::WWW::Mechanize::PSGI->new(
    app => sub { 
     my $env = shift; 
     setting(
      appname => 'MyApp', 
      appdir => $appdir, 
     ); 
     load_app 'MyApp'; 
     config->{environment} = 'test'; 
     Dancer::Config->load; 
     my $request = Dancer::Request->new(env => $env); 
     Dancer->dance($request); 
    } 
); 

$mech->get_ok('/') or diag $mech->content; 

done_testing; 

私はロガーを設定し、ログインはenvironments/test.ymlです。

私はまだこれらのエラーが発生していますが、それらが修正されているのを確認したいのですが、原因がわかりません。

Use of uninitialized value $_[0] in join or string at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/i686-linux/File/Spec/Unix.pm line 86. 
Use of uninitialized value $path in -e at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer/FileUtils.pm line 46. 
Use of uninitialized value in index at /home/ccushing/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Dancer/Renderer.pm line 160. 

うまくいけば、誰かが私がハンマーをすることができたよりも良い答えを私に提供できることを願っています。

+0

これは今のところうまくいけば誰かがより良いものを提供できるようになるため、私自身の反応を受け入れます。 – xenoterracide

関連する問題