jnicklas / turnip

Gherkin extension for RSpec
972 stars 112 forks source link

Improve documentation formatter to show each step on a new line #228

Closed aramvisser closed 2 years ago

aramvisser commented 4 years ago

When debugging failed tests, I like to run rspec with --format documentation to see as much info as possible when running tests. While using Turnip I was missing a way to see exactly which step failed.

So I created a new formatter based on the default RSpec documentation formatter to show each step on it's own line.

Before: turnip_documentation_formatter_before

After: turnip_documentation_formatter

The most obvious change is that each step is now on it's own line. This is to see in exactly which step an error occurs.

At the bottom where all failures are listed the actual step where the error occured is highlighted again, as a quick reminder.

Any examples not using Turnip will still use the default documentation style.

Some remarks:

aramvisser commented 4 years ago

I see there are some errors with RSpec 3.7 and 3.8. I'll get a fix for that soon.

ranska commented 4 years ago

Very nice improvement :+1:

aramvisser commented 4 years ago

@gongo Would you mind taking a look at this pull request?

I know changing the default output could have consequences for others users who rely on the current output staying the same. So I can understand if this pull request is not wanted. Either it's not in line with this project or maintenance might be too much.

In that case, would it be possible to at least include the changes made to /lib/turnip/rspec.rb? Namely sending events to the RSpec reporter and adding the steps to the example metadata.

That doesn't change anything for current turnip users, but it does allow me to improve on the documentation output as a new project.

If you would be okay with that, I'll create a new pull request for just those changes.

Thanks for your time.

gongo commented 4 years ago

Hi @aramvisser . Sorry for the late reply šŸ™ Thanks for the Pull Request! Very nice feature!


I want the formatter to be a separate gem. (e.g. https://github.com/gongo/turnip_formatter ). However, --documentation formatter is a standard formatter in RSpec, I don't feel there's anything strange about turnip itself has this format. šŸ˜„

Please let me think about it for a bit.

leoc commented 4 years ago

This is super interesting. Is this printing each step as it is performed or after the whole scenario is performed? I would love to get a feel of which step takes which amount of time relative to the scenario.

EDIT: I have a project, where I want to track the git commit/tag of the last change of a feature/scenario/step definitions so I wrote a little patch to hook into steps and nested steps. I have looked briefly into the pull requests code, and I wonder whether these hooks may be added to turnip too, for tracking sub-steps called via step()

Here is my monkey patch: https://gist.github.com/leoc/12caa2cc6abb508954121cd277c9b004

sobrinho commented 2 years ago

@aramvisser would you mind rebasing the branch against master?

There are merge conflicts right now.

cc @jnicklas

aramvisser commented 2 years ago

@sobrinho I released this project as a new extension at https://github.com/aramvisser/turnip_documentation_formatter

It should work on the latest version of RSpec and Turnip, but hasn't been tested beyond that.

I'll add some better tests for it soon to make it work on officially supported versions. Also it monkey patches Turnip in some areas to make it work. I want to try to move those patches in Turnip itself, since I think they could be useful for other projects as well.

sobrinho commented 2 years ago

@jnicklas @aramvisser I would like to see this as default (merged) into turnip, it makes the doc much better.