Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created February 25, 2014 12:06
Show Gist options
  • Save memememomo/9207662 to your computer and use it in GitHub Desktop.
Save memememomo/9207662 to your computer and use it in GitHub Desktop.
Test::Mojoでアップロード処理をテストする ref: http://qiita.com/memememomo/items/023c00ba9fe1e3f8f658
use strict;
use warnings;
use utf8;
use Encode;
use Test::Mojo;
use Test::More;
use File::Basename;
use Mojo::Asset::File;
$ENV{MOJO_HOME} = dirname(__FILE__) . '/../';
require "$ENV{MOJO_HOME}/myapp.pl";
my $t = Test::Mojo->new;
# アップロードする画像ファイル読み込み
my $asset = Mojo::Asset::File->new(path => dirname(__FILE__) . '/31683776.gif');
$t->post_ok('/upload' => form => {
# ハッシュでアップロードするファイルの情報を指定する
image => {
filename => '31683776.gif',
'Content-Type' => 'image/gif',
content => $asset->slurp,
},
})
->status_is(302);
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment