Added specs for the classes

This commit is contained in:
Christophe Coevoet
2014-01-04 17:14:35 +01:00
parent e261a5bfe3
commit 3059bc525c
5 changed files with 156 additions and 5 deletions

View File

@@ -8,16 +8,18 @@ php:
env: env:
- SYMFONY_VERSION='2.2.*' - SYMFONY_VERSION='2.2.*'
- SYMFONY_VERSION='2.3.*' - SYMFONY_VERSION='2.3.*'
- SYMFONY_VERSION='2.4.*'
- SYMFONY_VERSION='2.4.*@dev' - SYMFONY_VERSION='2.4.*@dev'
matrix: matrix:
allow_failures: allow_failures:
- env: "SYMFONY_VERSION='2.4.*@dev'" - env: "SYMFONY_VERSION='2.5.*@dev'"
before_script: before_script:
- curl http://getcomposer.org/installer | php - composer require --no-update symfony/symfony=$SYMFONY_VERSION
- php composer.phar require --no-update symfony/symfony=$SYMFONY_VERSION - composer install --prefer-source
- php composer.phar install --dev --prefer-source
- export PATH=./vendor/bin:$PATH - export PATH=./vendor/bin:$PATH
script: behat -fprogress script:
- phpspec run -f pretty
- behat -fprogress

View File

@@ -20,6 +20,7 @@
}, },
"require-dev": { "require-dev": {
"phpspec/phpspec": "2.0.*@dev",
"behat/mink-goutte-driver": "~1.0" "behat/mink-goutte-driver": "~1.0"
}, },

View File

@@ -0,0 +1,38 @@
<?php
namespace spec\Behat\MinkExtension\Context\Initializer;
use Behat\Behat\Context\Context;
use Behat\Mink\Mink;
use Behat\MinkExtension\Context\MinkAwareContext;
use PhpSpec\ObjectBehavior;
class MinkAwareInitializerSpec extends ObjectBehavior
{
function let(Mink $mink)
{
$this->beConstructedWith($mink, array('base_url' => 'foo'));
}
function it_is_a_context_initializer()
{
$this->shouldHaveType('Behat\Behat\Context\Initializer\ContextInitializer');
}
function it_supports_mink_aware_contexts(MinkAwareContext $context)
{
$this->supportsContext($context)->shouldBe(true);
}
function it_does_not_support_basic_contexts(Context $context)
{
$this->supportsContext($context)->shouldBe(false);
}
function it_injects_mink_and_parameters_in_mink_aware_contexts(MinkAwareContext $context, $mink)
{
$context->setMink($mink)->shouldBeCalled();
$context->setMinkParameters(array('base_url' => 'foo'))->shouldBeCalled();
$this->initializeContext($context);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace spec\Behat\MinkExtension;
use PhpSpec\ObjectBehavior;
class ExtensionSpec extends ObjectBehavior
{
function it_is_a_testwork_extension()
{
$this->shouldHaveType('Behat\Testwork\ServiceContainer\Extension');
}
function it_is_named_mink()
{
$this->getConfigKey()->shouldReturn('mink');
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace spec\Behat\MinkExtension\Listener;
use Behat\Behat\Tester\Event\ScenarioTested;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Node\ScenarioNode;
use Behat\Mink\Mink;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SessionsListenerSpec extends ObjectBehavior
{
function let(Mink $mink, ScenarioTested $event, FeatureNode $feature, ScenarioNode $scenario)
{
$this->beConstructedWith($mink, array('default_session' => 'goutte', 'javascript_session' => 'selenium2'));
$event->getFeature()->willReturn($feature);
$event->getScenario()->willReturn($scenario);
$feature->hasTag('insulated')->willReturn(false);
$feature->getTags()->willReturn(array());
$scenario->hasTag('insulated')->willReturn(false);
$scenario->getTags()->willReturn(array());
}
function it_is_an_event_subscriber()
{
$this->shouldHaveType('Symfony\Component\EventDispatcher\EventSubscriberInterface');
}
function it_resets_the_default_session_before_scenarios($event, $mink)
{
$mink->resetSessions()->shouldBeCalled();
$mink->setDefaultSessionName('goutte')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_switches_to_the_javascript_session_for_tagged_scenarios($event, $mink, $scenario)
{
$scenario->getTags()->willReturn(array('javascript'));
$mink->resetSessions()->shouldBeCalled();
$mink->setDefaultSessionName('selenium2')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_switches_to_the_javascript_session_for_tagged_features($event, $mink, $feature)
{
$feature->getTags()->willReturn(array('javascript'));
$mink->resetSessions()->shouldBeCalled();
$mink->setDefaultSessionName('selenium2')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_switches_to_a_named_session($event, $mink, $scenario)
{
$scenario->getTags()->willReturn(array('mink:test'));
$mink->resetSessions()->shouldBeCalled();
$mink->setDefaultSessionName('test')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_prefers_the_scenario_over_the_feature($event, $mink, $scenario, $feature)
{
$scenario->getTags()->willReturn(array('mink:test'));
$feature->getTags()->willReturn(array('javascript'));
$mink->resetSessions()->shouldBeCalled();
$mink->setDefaultSessionName('test')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_stops_the_sessions_for_insulated_scenarios($event, $mink, $scenario)
{
$scenario->hasTag('insulated')->willReturn(true);
$mink->stopSessions()->shouldBeCalled();
$mink->setDefaultSessionName('goutte')->shouldBeCalled();
$this->prepareDefaultMinkSession($event);
}
function it_stops_the_sessions_at_the_end_of_the_exercise($mink)
{
$mink->stopSessions()->shouldBeCalled();
$this->tearDownMinkSessions();
}
}