Commit 9d8bca20 by Gabriel Falcão

steps aware of its definitions. closes #10

parent fb94c23d
...@@ -34,6 +34,15 @@ def parse_data_list(lines): ...@@ -34,6 +34,15 @@ def parse_data_list(lines):
return keys, data_list return keys, data_list
class StepDefinition(object):
def __init__(self, function):
self.function = function
self.file = function.func_code.co_filename
self.line = function.func_code.co_firstlineno + 1
def __call__(self, *args, **kw):
return self.function(*args, **kw)
class Step(object): class Step(object):
has_definition = False has_definition = False
...@@ -59,17 +68,18 @@ class Step(object): ...@@ -59,17 +68,18 @@ class Step(object):
if matched: if matched:
break break
return matched, func return matched, StepDefinition(func)
def run(self, ignore_case): def run(self, ignore_case):
matched, func = self._get_match(ignore_case) matched, step_definition = self._get_match(ignore_case)
if not matched: if not matched:
raise NoDefinitionFound(self) raise NoDefinitionFound(self)
else: else:
self.has_definition = True self.has_definition = True
self.defined_at = step_definition
try: try:
func() step_definition()
except Exception, e: except Exception, e:
self.why = ReasonToFail(e) self.why = ReasonToFail(e)
raise raise
......
...@@ -132,3 +132,18 @@ def test_doesnt_ignore_case(): ...@@ -132,3 +132,18 @@ def test_doesnt_ignore_case():
assert_equals(len(scenario_result.steps_undefined), 2) assert_equals(len(scenario_result.steps_undefined), 2)
assert_equals(scenario_result.total_steps, 3) assert_equals(scenario_result.total_steps, 3)
assert not all([s.has_definition for s in scenario_result.scenario.steps]) assert not all([s.has_definition for s in scenario_result.scenario.steps])
def test_steps_are_aware_of_its_definitions():
"Steps are aware of its definitions line numbers and file names"
f = Feature.from_string(FEATURE1)
feature_result = f.run()
scenario_result = feature_result.scenario_results[0]
for step in scenario_result.steps_passed:
assert step.has_definition
step1 = scenario_result.steps_passed[0]
assert_equals(step1.defined_at.line, 48)
assert_equals(step1.defined_at.file, __file__.rstrip("c"))
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