Commit 0b2fa475 by Gabriel Falcão

Merge pull request #303 from enewton/master

Fix for issue #242 "xunit dies on undefined steps" WITH TESTS!
parents b510787b f5042fc1
...@@ -56,10 +56,12 @@ def enable(filename=None): ...@@ -56,10 +56,12 @@ def enable(filename=None):
tc = doc.createElement("testcase") tc = doc.createElement("testcase")
tc.setAttribute("classname", classname) tc.setAttribute("classname", classname)
tc.setAttribute("name", step.sentence) tc.setAttribute("name", step.sentence)
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started)))) if step.ran:
tc.setAttribute("time", str(total_seconds((datetime.now() - step.started))))
if not step.ran: else:
tc.setAttribute("time", str(0))
skip=doc.createElement("skipped") skip=doc.createElement("skipped")
skip.setAttribute("type", "UndefinedStep(%s)" % step.sentence)
tc.appendChild(skip) tc.appendChild(skip)
if step.failed: if step.failed:
......
Feature: Scenario with no steps
As a programmer
In order practise TDD
I want to write some scenarios before writing the steps
Scenario: Do nothing
Given I do nothing
...@@ -86,6 +86,7 @@ def test_xunit_output_with_one_error(): ...@@ -86,6 +86,7 @@ def test_xunit_output_with_one_error():
assert_equals(1, len(called), "Function not called") assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old xunit_output.wrt_output = old
@with_setup(prepare_stdout, registry.clear) @with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_different_filename(): def test_xunit_output_with_different_filename():
'Test xunit output with different filename' 'Test xunit output with different filename'
...@@ -105,3 +106,26 @@ def test_xunit_output_with_different_filename(): ...@@ -105,3 +106,26 @@ def test_xunit_output_with_different_filename():
xunit_output.wrt_output = old xunit_output.wrt_output = old
@with_setup(prepare_stdout, registry.clear)
def test_xunit_output_with_no_steps():
'Test xunit output with no steps'
called = []
def assert_correct_xml(filename, content):
print filename
print content
called.append(True)
assert_xsd_valid(filename, content)
root = etree.fromstring(content)
assert_equals(root.get("tests"), "1")
assert_equals(root.find("testcase").get("name"), "Given I do nothing")
assert_equals(len(root.getchildren()), 1)
assert_equals(root.find("testcase/skipped").get("type"), "UndefinedStep(Given I do nothing)")
assert_equals(float(root.find("testcase").get("time")), 0)
old = xunit_output.wrt_output
xunit_output.wrt_output = assert_correct_xml
runner = Runner(feature_name('no_steps_defined'), enable_xunit=True)
runner.run()
assert_equals(1, len(called), "Function not called")
xunit_output.wrt_output = old
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