Commit b326848d by Gabriel Falcao

first step on parsing backgrounds appropriately

parent 89e345a4
...@@ -987,8 +987,11 @@ class Feature(object): ...@@ -987,8 +987,11 @@ class Feature(object):
if not re.search(self.language.background, joined): if not re.search(self.language.background, joined):
return joined, None return joined, None
parts = strings.split_wisely(joined, self.language.background) parts = strings.split_wisely(
joined, "(%s):\s*" % self.language.background)
description = parts.pop(0) description = parts.pop(0)
if parts:
parts = "".join(parts[1:]).splitlines()
return description, parts return description, parts
...@@ -1009,6 +1012,7 @@ class Feature(object): ...@@ -1009,6 +1012,7 @@ class Feature(object):
if not re.search("^" + scenario_prefix, joined): if not re.search("^" + scenario_prefix, joined):
description, background_lines = self._extract_desc_and_bg(parts[0]) description, background_lines = self._extract_desc_and_bg(parts[0])
background = background_lines and Background.from_string( background = background_lines and Background.from_string(
background_lines, background_lines,
self, self,
......
...@@ -19,6 +19,7 @@ from lettuce import step ...@@ -19,6 +19,7 @@ from lettuce import step
from lettuce.core import Scenario from lettuce.core import Scenario
from lettuce.core import Feature from lettuce.core import Feature
from lettuce.core import Background from lettuce.core import Background
from lettuce.core import HashList
from nose.tools import assert_equals from nose.tools import assert_equals
FEATURE1 = """ FEATURE1 = """
...@@ -629,3 +630,30 @@ def test_background_parsing(): ...@@ -629,3 +630,30 @@ def test_background_parsing():
) )
expect(feature).to.have.property('background').being.a(Background) expect(feature).to.have.property('background').being.a(Background)
expect(feature.background).to.have.property('steps')
expect(feature.background.steps).to.have.length_of(2)
step1, step2 = feature.background.steps
step1.sentence.should.equal(
'Given I have the following movies in my database:')
step1.hashes.should.equal(HashList(step1, [
{
u'Available': u'6',
u'Rating': u'4 stars',
u'Name': u'Matrix Revolutions',
u'New': u'no',
},
{
u'Available': u'11',
u'Rating': u'5 stars',
u'Name': u'Iron Man 2',
u'New': u'yes',
},
]))
step2.sentence.should.equal(
'And the following clients:')
step2.hashes.should.equal(HashList(step2, [
{u'Name': u'John Doe'},
{u'Name': u'Foo Bar'},
]))
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