Having an environments/test.yml
I want to have some test specific stuff in an environment/test.yml (db username and password, memcache prefixes etc etc). Sounds simple enough except that in order to get it to work I had to write something like this package Dancer::TestEnviroment; use strict; use Cwd; sub import { my $class = shift; $ENV{DANCER_ENVIRONMENT} = 'test'; $ENV{DANCER_CONFDIR} = getcwd; unless ($INC{Dancer}) { require Dancer; Dancer->import(@_); } Dancer::setting(appdir => getcwd); Dancer::Config->load; } 1; and the use that from the top of ever one of my test files. Which seems a little ... long winded. Am I doing something wrong? Is there an easier way to do this?
Hi, i am sure I cannot give you a perfect answer, but apparently I can give you a quick answer. It depends on how you deploy. I assume test is something used during development. I develop using the standalone version. If you do that then environment should be loaded with this on the shell.
bin/app.pl --environment=test
maurice On Tue, Apr 12, 2011 at 4:44 PM, Simon Wistow <simon@thegestalt.org> wrote:
I want to have some test specific stuff in an environment/test.yml (db username and password, memcache prefixes etc etc). Sounds simple enough except that in order to get it to work I had to write something like this
package Dancer::TestEnviroment; use strict; use Cwd;
sub import { my $class = shift;
$ENV{DANCER_ENVIRONMENT} = 'test'; $ENV{DANCER_CONFDIR} = getcwd; unless ($INC{Dancer}) { require Dancer; Dancer->import(@_); } Dancer::setting(appdir => getcwd); Dancer::Config->load; }
1;
and the use that from the top of ever one of my test files. Which seems a little ... long winded.
Am I doing something wrong? Is there an easier way to do this?
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Tue, Apr 12, 2011 at 07:46:16PM -0400, Maurice Mengel said:
It depends on how you deploy. I assume test is something used during development. I develop using the standalone version. If you do that then environment should be loaded with this on the shell.
I currently have three environments production - used for when the app is deployed (memcached for sessions etc) development - used for local development (cookies for sessions etc) test - used when running stuff under t/ so using app.pl really isn't an option
On Wed, Apr 13, 2011 at 12:55:03AM +0100, me said:
so using app.pl really isn't an option
I should clarify that. I have a bunch of unit tests which tend to be run either as ./Build test or perl -Ilib t/foo.t Writing Dancer::TestEnvironment meant I didn't have to keep doing DANCER_ENVIRONMENT=test ./Build test and DANCER_ENVIRONMENT=test perl -Ilib t/foo.t didn't work since it looks for conf files under t/[*] Simon [*] which, I suppose has a certain amount of merit but in that case I'd want to change things so that running under Build test *also* looked under t/ It would also mean that I couldn't have my common config under config.yml unless I duplicated config.yml in t/config.yml
participants (2)
-
Maurice Mengel -
Simon Wistow