Testing the current time with Dancer
However unlike in the previous case, here we cannot compare the results to a fixed value as the result will be different every time we run the test.
We could mock the time generating code of the Dancer application, but for this application it would be an overkill.
So instead of that we weaken our test and compare the results to a regular expression. So we don't know that the returned string is indeed the correct date and time, but at least we can know that it looks like one.
The like keyword of Test::More provides this testing functionality.
use strict; use warnings; use Test::More; use Plack::Test; use Plack::Util; use HTTP::Request::Common; my $app = Plack::Util::load_psgi './app.psgi'; my $test = Plack::Test->create($app); my $res = $test->request(GET '/'); is $res->status_line, '200 OK', 'Status'; like $res->content, qr/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/, 'Content'; done_testing();
- Run as prove test.t