fixed prefix removal. Readme updated

This commit is contained in:
Oleg Podsadny 2013-03-31 03:42:42 +02:00
parent 616975bd80
commit fedbd06a5e
2 changed files with 47 additions and 5 deletions

View File

@ -1,9 +1,18 @@
pytestbdd - The BDD library for py.test runner.
===============================================
BDD library for the py.test runner
===================================
Install pytestbdd
=================
pip install pytestbdd
Example
=======
publish_article.feature:
Example:
Scenario: Publishing the article
Given I'm an author user
And I have an article
@ -11,4 +20,35 @@ Example:
And I press the publish button
Then I should not see the error message
And the article should be published # Note: will query the database
test_publish_article.py:
from pytestbdd import scenario, given, when, then
test_publish = scenario('publish_article.feature', 'Publishing the article')
@given('I have an article')
def article(author)
return create_test_article(author=author)
@when('I go to the article page')
def go_to_article(article, browser):
browser.visit(urljoin(browser.url, '/manage/articles/{0}/'.format(article.id)))
@when('I press the publish button')
def publish_article(browser):
browser.find_by_css('button[name=publish]').first.click()
@then('I should not see the error message')
def no_error_message(browser):
with pytest.raises(ElementDoesNotExist):
browser.find_by_css('.message.error').first
@then('And the article should be published')
def article_is_published(article):
article.refresh() # Refresh the object in the SQLAlchemy session
assert article.is_published

View File

@ -69,7 +69,7 @@ def remove_prefix(line):
"""
for prefix in STEP_PREFIXES:
if line.startswith(prefix):
return line[:len(prefix)].strip()
return line[len(prefix):].strip()
return line
@ -94,6 +94,8 @@ class Feature(object):
continue
mode = get_step_type(line) or mode
# Remove Given, When, Then, And
line = remove_prefix(line)
if mode == SCENARIO:
self.scenarios[line] = scenario = Scenario(line)