Browse files

Fixing error message when single-time delegates are used more than once

  • Loading branch information...
1 parent a055c91 commit 9e50295346d2b3a520c05f3f873bbf2a0e82ff1f @agross agross committed Jan 21, 2013
View
25 Source/Machine.Specifications.FailingExample/FailingContext.cs
@@ -1,19 +1,13 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace Machine.Specifications.FailingExample
{
[Subject("Scott Bellware")]
public class at_any_given_moment
{
- It will_fail = ()=>
- {
- throw new Exception("hi scott, love you, miss you.");
- };
+ It will_fail = () => { throw new Exception("hi scott, love you, miss you."); };
}
-
+
[Tags("example")]
public class context_with_multiple_establish_clauses
{
@@ -22,5 +16,16 @@ public class context_with_multiple_establish_clauses
It should = () => { };
}
-
-}
+
+ [DelegateUsage(DelegateUsage.Setup)]
+ public delegate void Given();
+
+ [Tags("example")]
+ public class context_with_multiple_given_clauses
+ {
+ Given foo = () => { };
+ Given bar = () => { };
+
+ It should = () => { };
+ }
+}
View
8 Source/Machine.Specifications.Specs/Runner/CustomDelegatesSpecs.cs
@@ -1,15 +1,13 @@
-
-
-using Machine.Specifications.Example.CustomDelegates;
+using Machine.Specifications.Example.CustomDelegates;
namespace Machine.Specifications.Specs.Runner
{
public class when_running_specs_with_custom_delegates : running_specs
{
- Because of =
+ Because of =
() => runner.RunAssembly(typeof(Account).Assembly);
- It should_run_them_all =
+ It should_run_them_all =
() => listener.SpecCount.ShouldEqual(3);
}
}
View
44 Source/Machine.Specifications.Specs/Runner/SpecificationRunnerSpecs.cs
@@ -1,5 +1,6 @@
using System;
using Machine.Specifications.Example;
+using Machine.Specifications.Example.CustomDelegates;
using Machine.Specifications.Example.Random;
using Machine.Specifications.FailingExample;
using Machine.Specifications.Runner;
@@ -32,7 +33,7 @@ public class when_running_a_context_with_no_specifications
}
[Subject("Specification Runner")]
- public class when_running_a_context_with_an_ignored_specifications
+ public class when_running_a_context_with_a_ignored_specifications
: RunnerSpecs
{
Establish context = () =>
@@ -139,11 +140,30 @@ public class when_running_a_context_with_multiple_establish_clauses
{
static Exception exception;
- Because of = () =>
- exception = Catch.Exception(Run<context_with_multiple_establish_clauses>);
+ Because of =
+ () => exception = Catch.Exception(Run<context_with_multiple_establish_clauses>);
- It should_fail = () =>
- exception.ShouldBeOfType<SpecificationUsageException>();
+ It should_fail =
+ () => exception.ShouldBeOfType<SpecificationUsageException>();
+
+ It should_report_the_reason =
+ () => exception.Message.ShouldStartWith("You cannot have more than one Establish clause in Machine.Specifications");
+ }
+
+ [Subject("Specification Runner")]
+ public class when_running_a_context_with_multiple_setup_clauses_and_custom_delegates
+ : RunnerSpecs
+ {
+ static Exception exception;
+
+ Because of =
+ () => exception = Catch.Exception(Run<context_with_multiple_given_clauses>);
+
+ It should_fail =
+ () => exception.ShouldBeOfType<SpecificationUsageException>();
+
+ It should_report_the_reason =
+ () => exception.Message.ShouldStartWith("You cannot have more than one Given clause in Machine.Specifications");
}
[Subject("Specification Runner")]
@@ -314,7 +334,7 @@ public class when_running_with_tag
static DefaultRunner runner;
static TestListener testListener;
}
-
+
[Subject("Specification Runner")]
public class when_running_with_empty_filters
{
@@ -340,7 +360,7 @@ public class when_running_with_empty_filters
static DefaultRunner runner;
static TestListener testListener;
}
-
+
[Subject("Specification Runner")]
public class when_running_with_context_filters
{
@@ -366,7 +386,7 @@ public class when_running_with_context_filters
static DefaultRunner runner;
static TestListener testListener;
}
-
+
[Subject("Specification Runner")]
public class when_running_with_specification_filters
{
@@ -447,8 +467,8 @@ public class when_running_a_context_with_nonprivate_framework_fields
It should_succeed =
() => testListener.LastResult.Passed.ShouldBeTrue();
- }
-
+ }
+
[Subject("Specification Runner")]
public class when_running_a_context_inside_a_static_class
: RunnerSpecs
@@ -458,7 +478,7 @@ public class when_running_a_context_inside_a_static_class
It should_succeed =
() => testListener.LastResult.Passed.ShouldBeTrue();
}
-
+
[Subject("Specification Runner")]
public class when_running_a_context_inside_a_static_class_that_is_nested_in_a_nonstatic_class
: RunnerSpecs
@@ -485,4 +505,4 @@ public static void Run<T>()
runner.RunMember(typeof(T).Assembly, typeof(T));
}
}
-}
+}
View
2 Source/Machine.Specifications/Factories/ContextFactory.cs
@@ -178,7 +178,7 @@ static void CollectDetailsOf<T>(Type target, Func<object> instanceResolver, ICol
if (ensureMaximumOfOne && fields.Count() > 1)
{
throw new SpecificationUsageException(String.Format("You cannot have more than one {0} clause in {1}",
- typeof(T).Name,
+ fields.First().FieldType.Name,
target.FullName));
}
var field = fields.FirstOrDefault();

0 comments on commit 9e50295

Please sign in to comment.