From 3059bc525cbe88afaee4a355533013d3dc8dd113 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 4 Jan 2014 17:14:35 +0100 Subject: [PATCH] Added specs for the classes --- .travis.yml | 12 ++- composer.json | 1 + .../Initializer/MinkAwareInitializerSpec.php | 38 ++++++++ spec/Behat/MinkExtension/ExtensionSpec.php | 18 ++++ .../Listener/SessionsListenerSpec.php | 92 +++++++++++++++++++ 5 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 spec/Behat/MinkExtension/Context/Initializer/MinkAwareInitializerSpec.php create mode 100644 spec/Behat/MinkExtension/ExtensionSpec.php create mode 100644 spec/Behat/MinkExtension/Listener/SessionsListenerSpec.php diff --git a/.travis.yml b/.travis.yml index eec5847..32c32a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,16 +8,18 @@ php: env: - SYMFONY_VERSION='2.2.*' - SYMFONY_VERSION='2.3.*' + - SYMFONY_VERSION='2.4.*' - SYMFONY_VERSION='2.4.*@dev' matrix: allow_failures: - - env: "SYMFONY_VERSION='2.4.*@dev'" + - env: "SYMFONY_VERSION='2.5.*@dev'" before_script: - - curl http://getcomposer.org/installer | php - - php composer.phar require --no-update symfony/symfony=$SYMFONY_VERSION - - php composer.phar install --dev --prefer-source + - composer require --no-update symfony/symfony=$SYMFONY_VERSION + - composer install --prefer-source - export PATH=./vendor/bin:$PATH -script: behat -fprogress +script: + - phpspec run -f pretty + - behat -fprogress diff --git a/composer.json b/composer.json index eccefa7..2197fab 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ }, "require-dev": { + "phpspec/phpspec": "2.0.*@dev", "behat/mink-goutte-driver": "~1.0" }, diff --git a/spec/Behat/MinkExtension/Context/Initializer/MinkAwareInitializerSpec.php b/spec/Behat/MinkExtension/Context/Initializer/MinkAwareInitializerSpec.php new file mode 100644 index 0000000..64cc14f --- /dev/null +++ b/spec/Behat/MinkExtension/Context/Initializer/MinkAwareInitializerSpec.php @@ -0,0 +1,38 @@ +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); + } +} diff --git a/spec/Behat/MinkExtension/ExtensionSpec.php b/spec/Behat/MinkExtension/ExtensionSpec.php new file mode 100644 index 0000000..0b38619 --- /dev/null +++ b/spec/Behat/MinkExtension/ExtensionSpec.php @@ -0,0 +1,18 @@ +shouldHaveType('Behat\Testwork\ServiceContainer\Extension'); + } + + function it_is_named_mink() + { + $this->getConfigKey()->shouldReturn('mink'); + } +} diff --git a/spec/Behat/MinkExtension/Listener/SessionsListenerSpec.php b/spec/Behat/MinkExtension/Listener/SessionsListenerSpec.php new file mode 100644 index 0000000..831d19a --- /dev/null +++ b/spec/Behat/MinkExtension/Listener/SessionsListenerSpec.php @@ -0,0 +1,92 @@ +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(); + } +}