Commit f19c0341 by Gabriel Falcao

basic background functionality

parent b06f5ab2
...@@ -843,6 +843,9 @@ class Background(object): ...@@ -843,6 +843,9 @@ class Background(object):
self.original_string = original_string self.original_string = original_string
self.language = language self.language = language
def run(self, ignore_case):
return [s.run(ignore_case) for s in self.steps]
@classmethod @classmethod
def from_string(new_background, def from_string(new_background,
lines, lines,
...@@ -1072,6 +1075,9 @@ class Feature(object): ...@@ -1072,6 +1075,9 @@ class Feature(object):
if not scenario.matches_tags(tags): if not scenario.matches_tags(tags):
continue continue
if self.background:
self.background.run(ignore_case)
scenarios_ran.extend(scenario.run(ignore_case)) scenarios_ran.extend(scenario.run(ignore_case))
call_hook('after_each', 'feature', self) call_hook('after_each', 'feature', self)
......
Feature: With Header
In order to test backgrounds
As lettuce maintainer
I want to make sure it works with headers
Background:
Given the variable "X" holds 2
Scenario: multiplication changing the value
Given the variable "X" is equal to 2
When the variable "X" holds 10
Then the variable "X" times 5 is equal to 50
And the variable "X" is equal to 10
Scenario: multiplication with value set from background
Given the variable "X" is equal to 2
Then the variable "X" times 5 is equal to 10
And the variable "X" is equal to 2
...@@ -18,6 +18,7 @@ import os ...@@ -18,6 +18,7 @@ import os
import random import random
import lettuce import lettuce
from mock import Mock, patch from mock import Mock, patch
from sure import expect
from StringIO import StringIO from StringIO import StringIO
from os.path import dirname, join, abspath from os.path import dirname, join, abspath
from nose.tools import assert_equals, with_setup, assert_raises from nose.tools import assert_equals, with_setup, assert_raises
...@@ -27,7 +28,6 @@ from lettuce.terrain import world ...@@ -27,7 +28,6 @@ from lettuce.terrain import world
from lettuce import Runner from lettuce import Runner
from tests.asserts import assert_lines from tests.asserts import assert_lines
from tests.asserts import assert_stderr
from tests.asserts import prepare_stderr from tests.asserts import prepare_stderr
from tests.asserts import prepare_stdout from tests.asserts import prepare_stdout
from tests.asserts import assert_stderr_lines from tests.asserts import assert_stderr_lines
...@@ -40,6 +40,7 @@ lettuce_dir = abspath(dirname(lettuce.__file__)) ...@@ -40,6 +40,7 @@ lettuce_dir = abspath(dirname(lettuce.__file__))
ojoin = lambda *x: join(current_dir, 'output_features', *x) ojoin = lambda *x: join(current_dir, 'output_features', *x)
sjoin = lambda *x: join(current_dir, 'syntax_features', *x) sjoin = lambda *x: join(current_dir, 'syntax_features', *x)
tjoin = lambda *x: join(current_dir, 'tag_features', *x) tjoin = lambda *x: join(current_dir, 'tag_features', *x)
bjoin = lambda *x: join(current_dir, 'bg_features', *x)
lettuce_path = lambda *x: fs.relpath(join(lettuce_dir, *x)) lettuce_path = lambda *x: fs.relpath(join(lettuce_dir, *x))
...@@ -53,6 +54,7 @@ def joiner(callback, name): ...@@ -53,6 +54,7 @@ def joiner(callback, name):
feature_name = lambda name: joiner(ojoin, name) feature_name = lambda name: joiner(ojoin, name)
syntax_feature_name = lambda name: joiner(sjoin, name) syntax_feature_name = lambda name: joiner(sjoin, name)
tag_feature_name = lambda name: joiner(tjoin, name) tag_feature_name = lambda name: joiner(tjoin, name)
bg_feature_name = lambda name: joiner(bjoin, name)
@with_setup(prepare_stderr) @with_setup(prepare_stderr)
...@@ -1098,11 +1100,46 @@ def test_run_only_fast_tests(): ...@@ -1098,11 +1100,46 @@ def test_run_only_fast_tests():
"2 steps (2 passed)\n" "2 steps (2 passed)\n"
) )
def test_run_random(): def test_run_random():
"Randomise the feature order" "Randomise the feature order"
filename = tag_feature_name('timebound')
runner = Runner('some_basepath', random=True) runner = Runner('some_basepath', random=True)
assert_equals(True, runner.random) assert_equals(True, runner.random)
with patch.object(random, 'shuffle') as pshuffle: with patch.object(random, 'shuffle') as pshuffle:
runner.run() runner.run()
pshuffle.assert_called_once_with([]) pshuffle.assert_called_once_with([])
@with_setup(prepare_stdout)
def test_background_with_header():
"Running background with header"
from lettuce import step, world
@step(ur'the variable "(\w+)" holds (\d+)')
def set_variable(step, name, value):
setattr(world, name, int(value))
@step(ur'the variable "(\w+)" is equal to (\d+)')
def check_variable(step, name, expected):
expected = int(expected)
expect(world).to.have.property(name).being.equal(expected)
@step(ur'the variable "(\w+)" times (\d+) is equal to (\d+)')
def multiply_and_verify(step, name, times, expected):
times = int(times)
expected = int(expected)
(getattr(world, name) * times).should.equal(expected)
filename = bg_feature_name('header')
runner = Runner(filename, verbosity=1)
runner.run()
assert_stdout_lines(
"......."
"\n"
"1 feature (1 passed)\n"
"2 scenarios (2 passed)\n"
"7 steps (7 passed)\n"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment