Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Indent messages correctly in DocumentationFormatter. #2649

Merged
merged 10 commits into from
Sep 10, 2019

Conversation

ioquatix
Copy link
Contributor

When using example.reporter.message, it would be nice if the messages were indented correctly, so that it's clear it relates to the current spec being executed.

@benoittgt
Copy link
Member

Hello Samuel and thanks for this PR.

Don't you think we should test this?

Cheers

@JonRowe
Copy link
Member

JonRowe commented Jul 13, 2019

Thanks Samuel! Yep I'd like to see a test for this and an indication of the change to the output as a sample!

@ioquatix
Copy link
Contributor Author

I am happy to add a test. However there is no current test for this.

If we add a test, we are setting in stone how it should behave. Is that okay? Maybe we want to change this behaviour again in the future.

@ioquatix
Copy link
Contributor Author

Okay, I've added a spec.

I don't want to make this any more complicated, however it does make me wonder if the message should come after the example name. While right now we are retaining the current behaviour which is probably good, maybe there is another discussion to be had regarding how to output the messages.

@benoittgt
Copy link
Member

If we add a test, we are setting in stone how it should behave. Is that okay? Maybe we want to change this behaviour again in the future.

Then we will change the test :) No problem for me.

maybe there is another discussion to be had regarding how to output the messages.

Yes maybe. I think it's ok for a first version.

Copy link
Member

@benoittgt benoittgt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks Samuel

@ioquatix
Copy link
Contributor Author

Are we good to merge?

@ioquatix
Copy link
Contributor Author

Sorry, missed adding it in #finished.

@benoittgt
Copy link
Member

benoittgt commented Jul 15, 2019

I much more happy with the new expected output now.

@ioquatix
Copy link
Contributor Author

I agree, it's nicer, it's just a bigger change and affects the underlying assumptions about what message output does. I wasn't so confident to make a big change.

@ioquatix
Copy link
Contributor Author

ioquatix commented Jul 15, 2019

How can a developer, at a glance tell which example it relates to?

I think the main criteria you should consider is, give that currently it is:

root
  example1
message
  example2

Is it already so hard to read that

root
  example1
  example2
    message

couldn't really make it any worse than it already is, then merging this PR only makes the situation better, and no worse for any existing use case.

@JonRowe
Copy link
Member

JonRowe commented Jul 15, 2019

My comment referred to the original implementation, not the one I've suggested as being mergeable.

@ioquatix
Copy link
Contributor Author

My comment referred to the original implementation, not the one I've suggested as being mergeable.

Okay, fair enough, well I've implemented what you asked but travis has exploded, strangely enough all tests passing locally, not sure what's going on.

@JonRowe
Copy link
Member

JonRowe commented Jul 15, 2019

The cucumber is failing because message is used to report messages before the suite too, so oddly, I think there needs to be another flush before the examples run

@ioquatix
Copy link
Contributor Author

@JonRowe why is it not failing for me locally, do I need to install cucumber?

@JonRowe
Copy link
Member

JonRowe commented Jul 15, 2019

cucumber is installed if you've done a bundle install, but you need to run it, its not part of our spec suite

@ioquatix
Copy link
Contributor Author

@JonRowe

image

Is this what you are thinking?

@ioquatix
Copy link
Contributor Author

rake cucumber?

@JonRowe
Copy link
Member

JonRowe commented Jul 15, 2019

That should be one way

@ioquatix
Copy link
Contributor Author

I tried it but it still fails.

@ioquatix
Copy link
Contributor Author

How about this?

        def message(notification)
          @messages << notification.message

          flush_messages if @group_level.zero?
        end

@ioquatix
Copy link
Contributor Author

@JonRowe Okay it's implemented and ready for your review.

@ioquatix
Copy link
Contributor Author

@JonRowe any chance we can merge this? Everything you requested was implemented.

Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be so nitpicky @ioquatix, I think we should change this slightly. If we keep track of wether we are in an example (causing the buffering to happen) but print immediately or not I feel the behaviour is cleaner. It means that outside of an example (groups, setup etc) its immediately printed at the current indent level, but if an example is running its buffered and indented further.

@ioquatix
Copy link
Contributor Author

@JonRowe are you happy with this now?

@ioquatix
Copy link
Contributor Author

ioquatix commented Sep 6, 2019

@JonRowe Any update?

@benoittgt
Copy link
Member

Sorry for the delay. Actual code looks good to me. Thanks Samuel

@JonRowe
Copy link
Member

JonRowe commented Sep 9, 2019

Sorry for the delay, lots on my plate atm

@ioquatix
Copy link
Contributor Author

ioquatix commented Sep 9, 2019

@JonRowe I made a few minor changes to your suggestions.

  • I prefered @example_started which matches the name of the method.
  • I didn't put the state transition @example_started = false into flush_messages as I felt like users of flush_messages might get confused that it also changes the state of the example buffering. i.e. maybe it gets called more than once per example or something else.

Is there any chance example_started gets called more than once without example_passed or example_failed being called?

Also, do we need @example_started = false in example_pending?

:example_passed, :example_pending, :example_failed

def initialize(output)
super
@group_level = 0

@example_started = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not the name of the method, its the state of the example, I prefer running as it indicated the state now, not what it was.

end

private

def flush_messages
if @messages.any?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to check for this, you can just iterate and clear, its a no op on an empty array.

@JonRowe
Copy link
Member

JonRowe commented Sep 10, 2019

Is there any chance example_started gets called more than once without example_passed or example_failed being called?

Also, do we need @example_started = false in example_pending?

Example started is called once at the start of an example, one of the three result methods should be called always so yes you need it in pending.

@ioquatix
Copy link
Contributor Author

Okay changes made.

@JonRowe
Copy link
Member

JonRowe commented Sep 10, 2019

Will merge when green

@ioquatix
Copy link
Contributor Author

Awesome, look forward to seeing this in my specs :)

@ioquatix
Copy link
Contributor Author

Also thanks for all your feedback, and doubly so if you've been preoccupied with something else!

@JonRowe JonRowe merged commit e570a0c into rspec:master Sep 10, 2019
JonRowe added a commit that referenced this pull request Sep 10, 2019
@ioquatix ioquatix deleted the patch-1 branch September 10, 2019 10:44
@benoittgt
Copy link
Member

Just a notice. Samuel did a video while working on this PR. https://youtu.be/tj4Bz_HaDIk 👌

MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Indent messages correctly in DocumentationFormatter.
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
Indent messages correctly in DocumentationFormatter.

---
This commit was imported from rspec/rspec-core@e570a0c.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants