NSpec
NSpec copied to clipboard
Optional output when executing before/ act/ after hook
This feature request is the outcome of a previous (closed) issue: #40 . Main idea is to be able to show some output besides context descriptions and specifications, in order to get a report somehow similar to Gherkin-style one.
In practice, this feature translates to add a void desc(string)
helper method to nspec
, which can be called within a before
, act
and after
hook in order to print the passed string in test report, before/after corresponding context specifications.
Here are some initial steps into how to implement this feature (taken from original issue):
- you'll want to add the core public
desc
method in this class and a private method calledAddDescription
: https://github.com/mattflo/NSpec/blob/master/NSpec/nspec.cs - in the
AddDescription
method, you'll want to add aDescription
instance (you'll have to create aDescribe
class...you mayyy not need a full blown class, but not sure) to the current context. It will be really similar to this method: https://github.com/mattflo/NSpec/blob/master/NSpec/nspec.cs#L255 - now that a
Description
(one more) is associated with aContext
, you can print it out by expanding on this class: https://github.com/mattflo/NSpec/blob/master/NSpec/Domain/ConsoleFormatter.cs#L10 - testing: to ensure the feature works, is probably best verified by executing the process and reading the console output. We have a suite of tests that do something similar, just add a test case here to verify that
desc
is working to your liking: https://github.com/mattflo/NSpec/blob/master/NSpecSpecs/describe_output.cs#L27 - writing descriptions in before, after and it blocks should be really similar
- when you start looking at providing descriptions in a nested context: You may find that you'll need to somehow track the current "block" that's in scope (for example: [this] message is associated with an example, [this other] message is associated with a before, [this other] message is associated with an after).
- you may need to create some construct to keep track of what block the description will belong to. Here is where the context actually execute, you may have to add additional functionality here: https://github.com/mattflo/NSpec/blob/master/NSpec/Domain/Context.cs#L149
Maybe this feature can be considered as "implemented" by a similar one from PR #132 ?