Skip to content

Commit

Permalink
test(beforeAll): add test case for issue #190
Browse files Browse the repository at this point in the history
  • Loading branch information
GiuseppePiscopo committed May 11, 2017
1 parent a6f1ddc commit d2d72a0
Showing 1 changed file with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

namespace NSpec.Tests.WhenRunningSpecs.Exceptions
{
[TestFixture]
[Category("RunningSpecs")]
public class when_method_level_before_all_contains_exception : when_running_specs
static class MethodBeforeAllThrows
{
class MethodBeforeAllThrowsSpecClass : nspec
public class SpecClass : nspec
{
void before_all()
{
Expand All @@ -28,10 +26,23 @@ void should_also_fail_this_example()
}
}

public class ChildSpecClass : SpecClass
{
void it_should_fail_because_of_parent()
{
Assert.That(true, Is.True);
}
}
}

[TestFixture]
[Category("RunningSpecs")]
public class when_method_level_before_all_contains_exception : when_running_specs
{
[SetUp]
public void setup()
{
Run(typeof(MethodBeforeAllThrowsSpecClass));
Run(typeof(MethodBeforeAllThrows.SpecClass));
}

[Test]
Expand All @@ -45,11 +56,36 @@ public void the_first_example_should_fail_with_framework_exception()
[Test]
public void the_second_example_should_fail_with_framework_exception()
{
var example = classContext.AllExamples().Last();
var example = classContext.AllExamples().Skip(1).First();

example.Exception.Should().BeAssignableTo<ExampleFailureException>();
}
}

class BeforeAllException : Exception { }
[TestFixture]
[Category("RunningSpecs")]
public class when_parent_method_level_before_all_contains_exception : when_running_specs
{
[SetUp]
public void setup()
{
Run(typeof(MethodBeforeAllThrows.ChildSpecClass));
}

[Test]
public void the_example_level_failure_should_indicate_a_context_failure()
{
var example = TheExample("it should fail because of parent");

example.Exception.Should().BeOfType<ExampleFailureException>();
}

[Test]
public void examples_with_only_before_all_failure_should_fail_because_of_before_all()
{
var example = TheExample("it should fail because of parent");

example.Exception.InnerException.Should().BeOfType<BeforeAllException>();
}
}
}

0 comments on commit d2d72a0

Please sign in to comment.