NSpec icon indicating copy to clipboard operation
NSpec copied to clipboard

Optional output when executing before/ act/ after hook

Open BrainCrumbz opened this issue 9 years ago • 1 comments

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 called AddDescription: https://github.com/mattflo/NSpec/blob/master/NSpec/nspec.cs
  • in the AddDescription method, you'll want to add a Description instance (you'll have to create a Describe 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 a Context, 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

BrainCrumbz avatar Dec 28 '15 20:12 BrainCrumbz

Maybe this feature can be considered as "implemented" by a similar one from PR #132 ?

BrainCrumbz avatar Aug 12 '16 06:08 BrainCrumbz