Skip to content

Commit

Permalink
Custom delegate types
Browse files Browse the repository at this point in the history
- Allowing users to to create custom delegate (It, Should, etc.)
delegates using the DelegateUsageAttribute.
- Adding 'leader' support (It => "it", Behaves_like => "behaves like").
- Adding leaders to output in certain places.
  • Loading branch information
Jonathan Dickinson authored and agross committed Jan 20, 2013
1 parent b770ab3 commit ff0827e
Show file tree
Hide file tree
Showing 29 changed files with 262 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Source/Machine.Specifications.ConsoleRunner/RunListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ static DateTime FormattableTimeSpan(long milliseconds)
return DateTime.MinValue + TimeSpan.FromMilliseconds(milliseconds);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class when_the_run_has_finished
var assembly = new AssemblyInfo("assembly", "location");
var context = new ContextInfo("conext", "concern", "System.Type", "System", "mscorlib");
var specification = new SpecificationInfo("spec", "System.Type", "field");
var specification = new SpecificationInfo("it", "spec", "System.Type", "field");
Listener.OnRunStart();
Listener.OnAssemblyStart(assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ public class when_a_report_with_unordered_items_is_rendered : ReportSpecs
Report = Run(Assembly("assembly 2",
Concern("a 2 concern 2",
Context("a 2 c 2 context 2",
Spec("a 2 c 2 c 2 specification 2", Result.Pass()),
Spec("a 2 c 2 c 2 specification 1", Result.Ignored())
Spec("it", "a 2 c 2 c 2 specification 2", Result.Pass()),
Spec("it", "a 2 c 2 c 2 specification 1", Result.Ignored())
),
Context("a 2 c 2 context 1",
Spec("a 2 c 2 c 1 specification 2",
Spec("it", "a 2 c 2 c 1 specification 2",
Result.Failure(PrepareException())),
Spec("a 2 c 2 c 1 specification 1", Result.NotImplemented())
Spec("it", "a 2 c 2 c 1 specification 1", Result.NotImplemented())
)
),
Concern("a 2 concern 1",
Context("a 2 c 1 context 2",
Spec("a 2 c 1 c 2 specification 2",
Spec("it", "a 2 c 1 c 2 specification 2",
Result.Supplement(Result.Pass(),
"the supplement",
new Dictionary<string, string>
Expand All @@ -72,34 +72,34 @@ public class when_a_report_with_unordered_items_is_rendered : ReportSpecs
{ "img-should-fail-copy", @"C:\some\html\image-should-fail-copy" },
{ "html-should-fail-copy", @"C:\some\html\file-should-fail-copy" }
})),
Spec("a 2 c 1 c 2 specification 1", Result.Pass())
Spec("it", "a 2 c 1 c 2 specification 1", Result.Pass())
),
Context("a 2 c 1 context 1",
Spec("a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("a 2 c 1 c 1 specification 1",
Spec("it", "a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 2 c 1 c 1 specification 1",
Result.Failure(PrepareException()))
)
)),
Assembly("assembly 1",
Concern("a 1 concern 2",
Context("a 1 c 2 context 2",
Spec("a 1 c 2 c 2 specification 2", Result.NotImplemented()),
Spec("a 1 c 2 c 2 specification 1", Result.Pass())
Spec("it", "a 1 c 2 c 2 specification 2", Result.NotImplemented()),
Spec("it", "a 1 c 2 c 2 specification 1", Result.Pass())
),
Context("a 1 c 2 context 1",
Spec("a 1 c 2 c 1 specification 2", Result.Pass()),
Spec("a 1 c 2 c 1 specification 1",
Spec("it", "a 1 c 2 c 1 specification 2", Result.Pass()),
Spec("it", "a 1 c 2 c 1 specification 1",
Result.Failure(PrepareException()))
)
),
Concern("a 1 concern 1",
Context("a 1 c 1 context 2",
Spec("a 1 c 1 c 2 specification 2", Result.Pass()),
Spec("a 1 c 1 c 2 specification 1", Result.NotImplemented())
Spec("it", "a 1 c 1 c 2 specification 2", Result.Pass()),
Spec("it", "a 1 c 1 c 2 specification 1", Result.NotImplemented())
),
Context("a 1 c 1 context 1",
Spec("a 1 c 1 c 1 specification 2", Result.Pass()),
Spec("a 1 c 1 c 1 specification 1", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 1 c 1 c 1 specification 1", Result.Pass())
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions Source/Machine.Specifications.Reporting.Specs/ReportSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ protected static Context Context(string name, params Specification[] specificati
return new Context(name, specifications);
}

protected static Specification Spec(string name, Result result)
protected static Specification Spec(string leader, string name, Result result)
{
return new Specification(name, result) { Id = Guid.NewGuid().ToString() };
return new Specification(leader, name, result) { Id = Guid.NewGuid().ToString() };
}

protected static Exception PrepareException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ public class when_failed_specifications_are_linked : ReportSpecs
{
Linker = new FailedSpecificationLinker();
First = Spec("a 1 c 1 c 1 specification 1", Result.Failure(new Exception()));
Second = Spec("a 2 c 1 c 1 specification 1", Result.Failure(new Exception()));
Last = Spec("a 2 c 1 c 2 specification 1", Result.Failure(new Exception()));
First = Spec("it", "a 1 c 1 c 1 specification 1", Result.Failure(new Exception()));
Second = Spec("it", "a 2 c 1 c 1 specification 1", Result.Failure(new Exception()));
Last = Spec("it", "a 2 c 1 c 2 specification 1", Result.Failure(new Exception()));
Report = Run(Assembly("assembly 1",
Concern("a 1 concern 1",
Context("a 1 c 1 context 1",
First,
Spec("a 1 c 1 c 1 specification 2", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass())
)
)
),
Assembly("assembly 2",
Concern("a 2 concern 1",
Context("a 2 c 1 context 1",
Spec("a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 2 c 1 c 1 specification 2", Result.Pass()),
Second),
Context("a 2 c 1 context 2",
Last,
Spec("a 2 c 1 c 2 specification 2", Result.Pass()))))
Spec("it", "a 2 c 1 c 2 specification 2", Result.Pass()))))
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class when_no_supplements_need_to_be_prepared_for_the_html_report : Repor
Report = Run(Assembly("assembly 1",
Concern("a 1 concern 1",
Context("a 1 c 1 context 1",
Spec("a 1 c 1 c 1 specification 2", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass())
)
)
));
Expand All @@ -53,7 +53,7 @@ public class when_file_based_result_supplements_are_prepared_for_the_html_report
Preparation = new FileBasedResultSupplementPreparation(MockRepository.GenerateStub<IFileSystem>());
Preparation.Initialize(new VisitorContext { ResourcePathCreator = () => @"C:\report\resources" });
Images = Spec("a 1 c 1 c 1 specification 1",
Images = Spec("it", "a 1 c 1 c 1 specification 1",
Result.Supplement(Result.Pass(),
"Images",
new Dictionary<string, string>
Expand All @@ -62,7 +62,7 @@ public class when_file_based_result_supplements_are_prepared_for_the_html_report
{ "img-another-image", @"C:\some\other\image.png" }
}));
HtmlFiles = Spec("a 2 c 1 c 1 specification 1",
HtmlFiles = Spec("it", "a 2 c 1 c 1 specification 1",
Result.Supplement(Result.Pass(),
"HTML",
new Dictionary<string, string>
Expand All @@ -71,7 +71,7 @@ public class when_file_based_result_supplements_are_prepared_for_the_html_report
{ "html-another-file", @"C:\some\other\file.html" }
}));
Texts = Spec("a 2 c 1 c 2 specification 1",
Texts = Spec("it", "a 2 c 1 c 2 specification 1",
Result.Supplement(Result.Pass(),
"Text",
new Dictionary<string, string>
Expand All @@ -84,18 +84,18 @@ public class when_file_based_result_supplements_are_prepared_for_the_html_report
Concern("a 1 concern 1",
Context("a 1 c 1 context 1",
Images,
Spec("a 1 c 1 c 1 specification 2", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass())
)
)
),
Assembly("assembly 2",
Concern("a 2 concern 1",
Context("a 2 c 1 context 1",
Spec("a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 2 c 1 c 1 specification 2", Result.Pass()),
HtmlFiles),
Context("a 2 c 1 context 2",
Texts,
Spec("a 2 c 1 c 2 specification 2", Result.Pass())))));
Spec("it", "a 2 c 1 c 2 specification 2", Result.Pass())))));
};

Because of = () => Preparation.Visit(Report);
Expand Down Expand Up @@ -128,7 +128,7 @@ public class when_copying_file_based_result_supplements_fails : ReportSpecs
Preparation = new FileBasedResultSupplementPreparation(fileSystem);
Preparation.Initialize(new VisitorContext { ResourcePathCreator = () => @"C:\report\resources" });
Failing = Spec("a 1 c 1 c 1 specification 1",
Failing = Spec("it", "a 1 c 1 c 1 specification 1",
Result.Supplement(Result.Pass(),
"Failing Images and Text",
new Dictionary<string, string>
Expand Down Expand Up @@ -186,7 +186,7 @@ public class when_copying_file_based_result_supplements_fails_and_the_error_mess
Preparation = new FileBasedResultSupplementPreparation(fileSystem);
Preparation.Initialize(new VisitorContext { ResourcePathCreator = () => @"C:\report\resources" });
Failing = Spec("a 1 c 1 c 1 specification 1",
Failing = Spec("it", "a 1 c 1 c 1 specification 1",
Result.Supplement(Result.Pass(),
"Failing Images and Text",
new Dictionary<string, string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ public class when_ignored_specifications_are_linked : ReportSpecs
{
Linker = new IgnoredSpecificationLinker();
First = Spec("a 1 c 1 c 1 specification 1", Result.Ignored());
Second = Spec("a 2 c 1 c 1 specification 1", Result.Ignored());
Last = Spec("a 2 c 1 c 2 specification 1", Result.Ignored());
First = Spec("it", "a 1 c 1 c 1 specification 1", Result.Ignored());
Second = Spec("it", "a 2 c 1 c 1 specification 1", Result.Ignored());
Last = Spec("it", "a 2 c 1 c 2 specification 1", Result.Ignored());
Report = Run(Assembly("assembly 1",
Concern("a 1 concern 1",
Context("a 1 c 1 context 1",
First,
Spec("a 1 c 1 c 1 specification 2", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass())
)
)
),
Assembly("assembly 2",
Concern("a 2 concern 1",
Context("a 2 c 1 context 1",
Spec("a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 2 c 1 c 1 specification 2", Result.Pass()),
Second),
Context("a 2 c 1 context 2",
Last,
Spec("a 2 c 1 c 2 specification 2", Result.Pass()))))
Spec("it", "a 2 c 1 c 2 specification 2", Result.Pass()))))
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ public class when_unimplemented_specifications_are_linked : ReportSpecs
{
Linker = new NotImplementedSpecificationLinker();
First = Spec("a 1 c 1 c 1 specification 1", Result.NotImplemented());
Second = Spec("a 2 c 1 c 1 specification 1", Result.NotImplemented());
Last = Spec("a 2 c 1 c 2 specification 1", Result.NotImplemented());
First = Spec("it", "a 1 c 1 c 1 specification 1", Result.NotImplemented());
Second = Spec("it", "a 2 c 1 c 1 specification 1", Result.NotImplemented());
Last = Spec("it", "a 2 c 1 c 2 specification 1", Result.NotImplemented());
Report = Run(Assembly("assembly 1",
Concern("a 1 concern 1",
Context("a 1 c 1 context 1",
First,
Spec("a 1 c 1 c 1 specification 2", Result.Pass())
Spec("it", "a 1 c 1 c 1 specification 2", Result.Pass())
)
)
),
Assembly("assembly 2",
Concern("a 2 concern 1",
Context("a 2 c 1 context 1",
Spec("a 2 c 1 c 1 specification 2", Result.Pass()),
Spec("it", "a 2 c 1 c 1 specification 2", Result.Pass()),
Second),
Context("a 2 c 1 context 2",
Last,
Spec("a 2 c 1 c 2 specification 2", Result.Pass()))))
Spec("it", "a 2 c 1 c 2 specification 2", Result.Pass()))))
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Context ToNode(this ContextInfo contextInfo, IEnumerable<Specifica

public static Specification ToNode(this SpecificationInfo specification, Result result)
{
return new Specification(specification.Name, result);
return new Specification(specification.Leader, specification.Name, result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ private void RenderSpecifications(XmlWriter reportBuilder, ContextInfo context)
break;
}
reportBuilder.WriteStartElement("specification");
reportBuilder.WriteAttributeString("leader", specification.Leader);
reportBuilder.WriteAttributeString("name", specification.Name);
reportBuilder.WriteAttributeString("field-name", specification.FieldName);
reportBuilder.WriteAttributeString("status", status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ public class Specification : ISpecificationNode, ILinkTarget, ILinkToCanFail, IL
{
readonly ExceptionResult _exception;
readonly string _name;
readonly string _leader;
readonly Status _status;
readonly IDictionary<string, IDictionary<string, string>> _supplements;

public Specification(string name, Result result)
public Specification(string leader, string name, Result result)
{
_leader = leader;
_status = result.Status;
_exception = result.Exception;
_supplements = result.Supplements;
Expand All @@ -23,6 +25,11 @@ public string Id
set;
}

public string Leader
{
get { return _leader; }
}

public Status Status
{
get { return _status; }
Expand Down
3 changes: 3 additions & 0 deletions Source/Machine.Specifications.Specs/AssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class when_checking_if_a_collection_contains_only_elements_that_match_a_f

Because of = () => { Exception = Catch.Exception(() => Ints.ShouldEachConformTo(x => x % 2 == 0)); };

// Horribly inconsistent here. It seems like this spec might fail because linq expressions returns ((x % 2) = 0)
// for the original ((x % 2) == 0).

It should_print_the_func_description =
() => Exception.Message.ShouldContain("Should contain only elements conforming to: x => ((x % 2) = 0)");

Expand Down
Loading

0 comments on commit ff0827e

Please sign in to comment.