Version 0.09
[gitmo/MooseX-SimpleConfig.git] / t / 11default.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use lib '../t/lib';
8 use Test::More;
9 our @classes;
10 BEGIN {
11
12     @classes = qw/ MXDefaultConfigTest MXDefaultMultipleConfigsTest /;
13
14     eval "use YAML::Syck ()";
15     if($@) {
16         eval "use YAML ()";
17         if($@) {
18             plan skip_all => "YAML or YAML::Syck required for this test";
19         }
20     }
21
22     use_ok($_) for @classes;
23 }
24
25 # Can it load a simple YAML file with the options
26 #  based on a default in the configfile attr
27 {
28     open(my $test_yaml, '>', 'test.yaml')
29       or die "Cannot create test.yaml: $!";
30     print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n";
31     close($test_yaml);
32
33 }
34
35 foreach my $class (@classes) {
36     my $foo = eval {
37         $class->new_with_config();
38     };
39     ok(!$@, 'Did not die with good YAML configfile')
40         or diag $@;
41
42     is($foo->req_attr, 'foo', 'req_attr works');
43     is($foo->direct_attr, 123, 'direct_attr works');
44     is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
45 }
46
47 done_testing;
48
49 END { unlink('test.yaml') }