App-unbelievable

 view release on metacpan or  search on metacpan

eg/content/porting-a-dancer-plugin-to-dancer2.md  view on Meta::CPAN

my $response = dancer_response GET => '/';  # dancer_response() is from Dancer::Test
is( $response->{content}, 1 );
```

Dancer2, on the other hand, uses the [Plack]({{< mcpan "Plack" >}}) ecosystem for testing instead of its own helpers.  To work in that ecosystem, I changed the
above test as described in the
[Dancer2 manual’s “testing” section]({{< mcpan "Dancer2::Manual#TESTING" >}}):

```perl
use Plack::Test;                        # Additional testing modules
use HTTP::Request::Common;
{
    package TestApp;     # Still a simple application, but now with a name
    use Dancer2;
    use Dancer2::Plugin::MobileDevice;

    get '/' => sub { return is_mobile_device; };
}

my $dut = Plack::Test->create(TestApp->to_app);     # a fake Web server
my $response = $dut->request(GET '/', 'User-Agent' => 'iPhone');

eg/content/porting-a-dancer-plugin-to-dancer2.md  view on Meta::CPAN


**Port hooks:**

- Add a `BUILD` function
- Move the hook functions into `BUILD`, or refer to them from `BUILD`
- Wrap each hook function in a `$self->dsl->hook` call

**Port tests:**

- Import[Plack::Test]({{< mcpan "Plack::Test" >}}}) and
  [HTTP::Request::Common]({{< mcpan "HTTP::Request::Common" >}})
  instead of Dancer::Test
- Give the application under test a `package` statement
- Create a Plack::Test instance representing the application
- Create requests using HTTP::Request::Common methods
- Change `$response->{content}` to `$response->content`

eg/cpanfile  view on Meta::CPAN

requires "Dancer2" => "0.208001";

recommends "YAML"             => "0";
recommends "URL::Encode::XS"  => "0";
recommends "CGI::Deurl::XS"   => "0";
recommends "HTTP::Parser::XS" => "0";

on "test" => sub {
    requires "Test::More"            => "0";
    requires "HTTP::Request::Common" => "0";
};

eg/t/002_index_route.t  view on Meta::CPAN

use strict;
use warnings;

use Site;
use Test::More tests => 2;
use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;

my $app = Site->to_app;
ok( is_coderef($app), 'Got app' );

my $test = Plack::Test->create($app);
my $res  = $test->request( GET '/' );

ok( $res->is_success, '[GET /] successful' );



( run in 0.378 second using v1.01-cache-2.11-cpan-de7293f3b23 )