Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created September 30, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjlsergeant/c609cedd2748b07ce5ee to your computer and use it in GitHub Desktop.
Save pjlsergeant/c609cedd2748b07ce5ee to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use Test::BDD::Cucumber::StepFile;
use Test::Mojo;
# Instantiates a new Test::Mojo object, and save it in the scenario-level stash.
# Rather than do this per-scenario, we'll store a copy in the feature-level and
# re-use that.
Given qr!an? ([\w:]+) app! => sub {
S->{'t'} = C->stash->{'feature'}->{'test_mojo'} //= Test::Mojo->new( $1 );
};
Given qr/I load the (.+?) (admin )?page/ => sub {
my ( $page_name, $is_admin ) = @{ C->matches };
# Guess at the intended URL
my $path = $is_admin ? '/admin/' : '/page/';
$page_name =~ tr/ /_/;
S->{'t'}->get_ok( lc ($path . $page_name) )->status_is(200);
};
When qr/I submit the (.+) form/ => sub {
my $form_name = $1;
my $data = C->data;
};
Then qr/I should ( not|)(find|see) (an?|the) (\w+) (\w+)/ => sub {
my $type = $1 ? 'element_exists_not' : 'element_exists';
my $attribute_type = $3 eq 'a' ? 'class' : 'id';
my $attribute_value = $4;
my $element_type = $5;
S->{'t'}->$type(
sprintf( "%s[%s=%s",
$element_type, $attribute_type, $attribute_value )
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment