Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: Can Test::MockObject mock a file?

by tobyink (Canon)
on Sep 20, 2020 at 08:20 UTC ( #11121958=note: print w/replies, xml ) Need Help??


in reply to Re^4: Can Test::MockObject mock a file?
in thread Can Test::MockObject mock a file?

You could make it less repetitive, but looks good apart from that.

#!perl use strict; use warnings; use v5.10.0; use Test::More tests => "5"; use FindBin qw($Bin); BEGIN { use_ok( 'Fancy::Open', qw(fancy_open) ) or die "Fancy::Open is not available\n"; } diag( "Testing Fancy::Open $Fancy::Open::VERSION, Perl $], $^X" ); my $file = "$Bin/test-open.txt"; my @wanted = qw( red orange yellow spring green teal cyan azure blue violet magenta pink white black gray ); is_deeply( [ Fancy::Open::fancy_open($file) ], [ @wanted ], "testing a plain array" ); is_deeply( [ Fancy::Open::fancy_open($file, { 'before' => 'solid ' }) ], [ map "solid $_", @wanted ], "testing an array with before option" ); is_deeply( [ Fancy::Open::fancy_open($file, { 'after' => ' bead' }) ], [ map "$_ bead", @wanted ], "testing an array with after option" ); is_deeply( [ Fancy::Open::fancy_open($file, { 'before' => 'solid ', 'after' => +' bead' }) ], [ map "solid $_ bead", @wanted ], "testing an array with before and after options" ); done_testing();

You might also want to test it on a file that ends with a "\n" and a file that doesn't end with a "\n", and see if the behaviour differs between them. Having checked your module, I don't think it will, but it might be useful to have a test for it, so you don't accidentally change that in the future without realizing it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-10-28 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?