Not too bad, not too long, name is almost ok but still not really clear "document model generator [when parsing] remarks should have remarks for type". Mainly the body of the test is almost completely unreadable on first glance.
[Test]
public void should_move_untransformable_resources_to_output_dir()
{
var resourceManager = MockRepository.GenerateMock<IUntransformableResourceManager>();
var generator = new DocumentationGenerator(StubAssemblyLoader, StubXmlLoader, StubParser, StubWriter, resourceManager, StubEventAggregator);
generator.SetAssemblies(new[] { "unimportant_file_path" });
generator.SetOutputPath("output-dir");
generator.Generate();
resourceManager.AssertWasCalled(x => x.MoveResources(null, null),
x => x.Constraints(Is.Anything(), Is.Equal("output-dir")));
}
DocumentationGenerator has too many dependencies, which makes the stub stuff a bit nasty. Other than that, if you understand how mocks work then it's pretty readable. The naming is still just ok but requires some expansion on the readers part, "documentation generator [when] generate [called] should move untransformable resources to output dir"; really I think it's the class name that lets down the name in this case.
[TestTemplate("${Namespace.Name}")]
public void ShouldOutputShortcutNamespace()
{
Convert(new ViewData { Namespace = Namespace("Example") })
.ShouldEqual("Example");
}
Nice and short, name not so great again. Relies on quite a bit of magic to parse the special attribute, and the Convert method that wraps the Spark code; don't know if magic is good or bad, but I like the brevity.
[Test]
public void GeneratesOutputForEachTypeFromTemplateWhenPatternUsed()
{
var generator = MockRepository.GenerateMock<IOutputGenerator>();
var writer = MockRepository.GenerateStub<IOutputWriter>();
var resolver = MockRepository.GenerateStub<IPatternTemplateResolver>();
var transformer = new PageWriter(generator, writer, resolver);
var namespaces = Namespaces("One", "Two");
Type<First>(namespaces[0]);
Type<Second>(namespaces[1]);
resolver.Stub(x => x.Resolve(null, null))
.IgnoreArguments()
.Return(new List<TemplateMatch>
{
new TemplateMatch("One.First.htm", "!type.spark", new ViewData()),
new TemplateMatch("Two.Second.htm", "!type.spark", new ViewData())
});
transformer.CreatePages("!type.spark", "", namespaces);
generator.AssertWasCalled(
x => x.Convert(null, null),
x => x.Constraints(Is.Equal("!type.spark"), Is.Anything())
.Repeat.Twice());
}
Wow, just wow :) Too many dependencies again. Also, not so great that in a fixture-per-class design the fixture name doesn't reflect the class under test.
[Test]
public void should_have_no_specific_type()
{
resolve("template.spark");
type_of(first_result).ShouldBeNull();
}
Name is pretty good this time, "single template should have no specific type". The body is nice and simple again, but relies on a lot of magic; again, not sure if this is good or bad. It results in simple tests, and means there's only one point that breaks for interface changes, but it does obscure what is actually being tested.
[Test]
public void OutputsEventReferenceLink()
{
var formatter = new HtmlOutputFormatter();
var method = Event<Second>("AnEvent");
formatter.FormatReferencable(method)
.ShouldEqual("<a href=\"Example/Second.htm#AnEvent\">AnEvent</a>");
}
Again, name is just ok, body is pretty readable too; relies on a bit of magic, but not much.
I think that'll do for the examples. Anybody care to offer some opinions? Bash away. Should I go with a BDD style? Should I lose the magic, or is it good? Are any of the examples better than others, or are they all bad in different ways?