App-GitGot

 view release on metacpan or  search on metacpan

t/05-fork.t  view on Meta::CPAN

#! perl

use 5.014;                      # strict, unicode_strings
use warnings;
use autodie;

use lib 't/lib';
use Test::BASE;
use Test::File;
use Test::MockObject;
use Test::More;

BEGIN {
  my $mock = Test::MockObject->new();
  $mock->fake_module(
    'Net::GitHub::V3::Repositories' ,
    'fork' => sub { 1 } ,
  );
  $mock->fake_new( 'Net::GitHub' );
  $mock->mock( repos => sub { $mock } );
  $mock->mock( create_fork => sub {{ ssl_url => 'yeahboi' }} );
}

use App::Cmd::Tester;
use App::GitGot;
use Path::Tiny;
use YAML              qw/ LoadFile /;

my $dir    = Test::BASE::create_tempdir_and_chdir();
my $config = path( "$dir/gitgot" );
file_not_exists_ok $config , 'config does not exist';

$ENV{HOME} = $dir;

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: Need the URL of a repo to fork/ ,
    'need to give a URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ,
                                            'http://not.github.org/' ]);
  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr|ERROR: Can't parse 'http://not.github.org/'| ,
      'need repo URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

Test::BASE::create_github_identity_file();

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config , 'http://not.github.org/' ]);



( run in 1.288 second using v1.01-cache-2.11-cpan-39bf76dae61 )