Skip to content

Commit

Permalink
test cpanify command too
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 22, 2015
1 parent c5c359a commit f7eca60
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
3 changes: 1 addition & 2 deletions lib/Mojolicious/Command/cpanify.pm
Expand Up @@ -3,7 +3,6 @@ use Mojo::Base 'Mojolicious::Command';

use File::Basename 'basename';
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case);
use Mojo::UserAgent;

has description => 'Upload distribution to CPAN';
has usage => sub { shift->extract_usage };
Expand All @@ -16,7 +15,7 @@ sub run {
'u|user=s' => \(my $user = '');
die $self->usage unless my $file = shift @args;

my $tx = Mojo::UserAgent->new->tap(sub { $_->proxy->detect })->post(
my $tx = $self->app->ua->tap(sub { $_->proxy->detect })->post(
"https://$user:$password\@pause.perl.org/pause/authenquery" => form => {
HIDDENNAME => $user,
CAN_MULTIPART => 1,
Expand Down
80 changes: 48 additions & 32 deletions t/mojolicious/commands.t
Expand Up @@ -125,6 +125,37 @@ $buffer = '';
like $buffer, qr/Usage: APPLICATION generate lite_app \[NAME\]/,
'right output';

# get
require Mojolicious::Command::get;
my $get = Mojolicious::Command::get->new;
ok $get->description, 'has a description';
like $get->usage, qr/get/, 'has usage information';
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/');
}
like $buffer, qr/Your Mojo is working!/, 'right output';
$get->app->plugins->once(
before_dispatch => sub { shift->render(text => '<p>works</p>') });
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/html', 'p', 'text');
}
like $buffer, qr/works/, 'right output';
$get->app->plugins->once(
before_dispatch => sub { shift->render(json => {works => 'too'}) });
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/json', '/works');
}
like $buffer, qr/too/, 'right output';

# cgi
require Mojolicious::Command::cgi;
my $cgi = Mojolicious::Command::cgi->new;
Expand All @@ -136,6 +167,21 @@ require Mojolicious::Command::cpanify;
my $cpanify = Mojolicious::Command::cpanify->new;
ok $cpanify->description, 'has a description';
like $cpanify->usage, qr/cpanify/, 'has usage information';
$cpanify->app->ua->unsubscribe('start')->once(
start => sub {
my ($ua, $tx) = @_;
$tx->req->proxy(0)->url($ua->server->url->path('/'));
}
);
$cpanify->app->plugins->once(
before_dispatch => sub { shift->render(data => '', status => 200) });
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$cpanify->run('-u', 'sri', '-p', 's3cret', __FILE__);
}
like $buffer, qr/Upload successful!/, 'right output';

# daemon
require Mojolicious::Command::daemon;
Expand Down Expand Up @@ -258,37 +304,6 @@ ok -e $app->rel_file('Mojolicious-Plugin-MyPlugin/Makefile.PL'),
'Makefile.PL exists';
chdir $cwd;

# get
require Mojolicious::Command::get;
my $get = Mojolicious::Command::get->new;
ok $get->description, 'has a description';
like $get->usage, qr/get/, 'has usage information';
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/');
}
like $buffer, qr/Your Mojo is working!/, 'right output';
$get->app->plugins->once(
before_dispatch => sub { shift->render(text => '<p>works</p>') });
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/html', 'p', 'text');
}
like $buffer, qr/works/, 'right output';
$get->app->plugins->once(
before_dispatch => sub { shift->render(json => {works => 'too'}) });
$buffer = '';
{
open my $handle, '>', \$buffer;
local *STDOUT = $handle;
$get->run('/json', '/works');
}
like $buffer, qr/too/, 'right output';

# inflate
require Mojolicious::Command::inflate;
my $inflate = Mojolicious::Command::inflate->new;
Expand Down Expand Up @@ -340,7 +355,7 @@ require Mojolicious::Command::version;
my $version = Mojolicious::Command::version->new;
ok $version->description, 'has a description';
like $version->usage, qr/version/, 'has usage information';
$version->app->ua->unsubscribe('start')->once(
$version->app->ua->once(
start => sub {
my ($ua, $tx) = @_;
$tx->req->proxy(0)->url($ua->server->url->path('/'));
Expand All @@ -354,6 +369,7 @@ $buffer = '';
local *STDOUT = $handle;
$version->run;
}
like $buffer, qr/Perl/, 'right output';
like $buffer, qr/You might want to update your Mojolicious to 1000!/,
'right output';

Expand Down

0 comments on commit f7eca60

Please sign in to comment.