Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request gabrielfalcao#177 from rbu/make-undefined-steps-fail
Make Step.behave_as fail when calling an undefined step
  • Loading branch information
gabrielfalcao committed Aug 25, 2011
2 parents fed9837 + ccf9c8e commit 293dd2c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lettuce/core.py
Expand Up @@ -356,15 +356,15 @@ def elsewhere(step):
for step in steps:
step.scenario = self.scenario

(_, _, steps_failed, _, _) = self.run_all(steps)
if not steps_failed:
(_, _, steps_failed, steps_undefined, _) = self.run_all(steps)
if not steps_failed and not steps_undefined:
self.passed = True
self.failed = False
return self.passed
else:
self.passed = False
self.failed = True
assert not steps_failed, steps_failed[0].why.exception
self.passed = False
self.failed = True
assert not steps_failed, steps_failed[0].why.exception
assert not steps_undefined, "Undefined step: %s" % steps_undefined[0].sentence

def run(self, ignore_case):
"""Runs a step, trying to resolve it on available step
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_step_runner.py
Expand Up @@ -436,6 +436,30 @@ def test_failing_behave_as_step_fails():

assert runnable_step.failed

@with_setup(step_runner_environ)
def test_undefined_behave_as_step_doesnt_pass():
'When a step definition calls an undefined step definition with behave_as, that step should not be marked as success.'
runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
try:
runnable_step.run(True)
assert False, "Undefined step should raise exception"
except:
pass

assert_false(runnable_step.passed)

@with_setup(step_runner_environ)
def test_undefined_behave_as_step_fails():
'When a step definition calls an undefined step definition with behave_as, that step should be marked a failure.'
runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
try:
runnable_step.run(True)
assert False, "Undefined step should raise exception"
except Exception, e:
pass

assert runnable_step.failed

@with_setup(step_runner_environ)
def test_failing_behave_as_step_raises_assertion():
'When a step definition calls another (failing) step definition with behave_as, that step should be marked a failure.'
Expand Down

0 comments on commit 293dd2c

Please sign in to comment.