Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate failures Integration #1946

Merged
merged 20 commits into from May 16, 2015
Merged

Aggregate failures Integration #1946

merged 20 commits into from May 16, 2015

Conversation

myronmarston
Copy link
Member

This is the start of the rspec-core work for the new aggregate_failures feature. The part I'm working on now is getting the aggregated failure to format how we want. To facilitate this, I've extracted a new ExceptionFormatter class that is able to format exceptions according to how rspec-core typically does it for its built-in formatters. We'll then be able to apply this to each of the aggregated failures.

More to come, but I wanted to push what I had and get the travis build going.

module Core
module Formatters
# @private
class ExceptionFormatter
Copy link
Member

Choose a reason for hiding this comment

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

Is ExceptionFormatter a good name for this? It's not a "Formatter" in RSpec's sense (even though it does do formatting), we use the term printer elsewhere for this sort of thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was a good name, in spite of the fact that it's not a "Formatter" in the RSpec sense....but ExceptionPrinter is fine by me if you prefer it.

Copy link
Member

Choose a reason for hiding this comment

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

I think I do just so nobody naively thinks it's a formatter in its own right :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it is labeled @private, so it's not really intended to be available or visible to users...

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I know, but so are the deprecation and bisect formatters etc and they're real formatters. Thanks for making the change though, ❤️

@myronmarston
Copy link
Member Author

@JonRowe, I renamed the ExceptionFormatter class to ExceptionPrinter. However, I realized that we do use Formatter for at least one case that's not a formatter in the RSpec sense: BacktraceFormatter. Apart from the normal specific meaning of "formatter" in RSpec, I think "formatter" is a better term than "printer" for what that class does, and I'm tempted to keep the original name. Thoughts?

@JonRowe
Copy link
Member

JonRowe commented Apr 29, 2015

Personally I think we should rename BacktraceFormatter, I'm still heavily on the "formatter has a specific meaning" within our lingo here... How about something like FormatException or ExceptionDisplay

@myronmarston myronmarston force-pushed the aggregate-failures branch 6 times, most recently from 3bb1b61 to d0e02ee Compare May 2, 2015 14:53
@myronmarston
Copy link
Member Author

Personally I think we should rename BacktraceFormatter, I'm still heavily on the "formatter has a specific meaning" within our lingo here... How about something like FormatException or ExceptionDisplay

I decided on ExceptionPresenter -- after all, that class is responsible for the presentation of the exception. You OK with that? I went ahead and renamed it....

@JonRowe
Copy link
Member

JonRowe commented May 2, 2015

Perfect ❤️

@myronmarston myronmarston force-pushed the aggregate-failures branch 5 times, most recently from 5d9eb71 to 7d38d28 Compare May 5, 2015 16:20
@myronmarston myronmarston changed the title [WIP] Aggregate failures Aggregate failures Integration May 12, 2015
@myronmarston
Copy link
Member Author

OK, this PR is ready for review as well. It builds on top of rspec/rspec-expectations#733 and integrates that feature. The code changes here provide a couple things:

  • Improved failure output from aggregate_failures failures.
  • Lots and lots of refactoring for the exception presentation logic to support this.
  • :aggregate_failures metadata definition.

Note that this PR can't be merged until rspec/rspec-expectations#733 is, and that one has a @wip cuke, which passes against this rspec-core branch but fails against rspec-core's master branch. So there's a bit of a circular dependency here, at least in terms of the testing, and I'm not sure what to do about it -- see the discussion about the cuke in rspec/rspec-expectations#733 for more info.

There's also an open question around what :aggregate_failures metadata should do when rspec-expectations is not loaded. My currently implementation will yield a NoMethodError (aggregate_failures) which might be OK and is the simplest, but I could see us doing something a bit nicer too...

/cc @rspec/rspec (especially @xaviershay)

@@ -218,6 +218,14 @@
end
end

it 'uses only one thread local variable', :run_last do
Copy link
Member

Choose a reason for hiding this comment

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

huh, cute.

@xaviershay
Copy link
Member

There's also an open question around what :aggregate_failures metadata should do when rspec-expectations is not loaded.

I'm allowed to define arbitrary metadata, right? So in that case, not being able to "overload" aggregate_failures if I'm not bringing it in from somewhere else seems like a breach of contract.

Or actually, we're now defining this as a reserved word in rspec-core itself (if we weren't this would be a cyclic dependency I think), therefore we should probably raise something along the lines of "no plugin implements this behaviour" or something.

Not really worth a lot of effort though I don't think.

@xaviershay
Copy link
Member

All this presentation stuff is gnarly. Good cleanups overall.

@myronmarston
Copy link
Member Author

Not really worth a lot of effort though I don't think.

Yep, I'm leading towards "do nothing" for now. We can always do something later -- handling this case a bit more gracefully for users who use rspec-core but not rspec-expectations won't be a breaking API change so there's no urgency to get it in now.

All this presentation stuff is gnarly. Good cleanups overall.

Yeah, it kinda fried my brain :(. I still feel like it's really messy but I don't really want to put the effort into further refactorings now unless there's an obvious easy, big win someone has in mind.

# namespace.
def self.thread_local_metadata
Thread.current[:_rspec] ||= { :shared_example_group_inclusions => [] }
RSpec::Support.thread_local_data[:current_example] = example
Copy link
Member

Choose a reason for hiding this comment

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

Oh neat :)

@myronmarston
Copy link
Member Author

OK, I think this is ready for a final review (and hopefully a merge!). Since @xaviershay's review, I added a cuke (viewable here), and added some improvements so that nested failure aggregation blocks format well.

Want to do a final review, @xaviershay?

I do still have to remove the [Temp] commit that pins this to the rspec-expectations branch, of course. I'll do that after we merge that PR.

@xaviershay
Copy link
Member

ship it!

This will make it easier to extract an `ExceptionFormatter`.
- Simplifies the notification classes.
- Provides something we can use to format multiple
  expectation failures packaged as a single exception
  for `aggregate_failures`.
We need to combine some of these cases (such
as when we get a `MultipleExpectationsNotMetError`
in a pending spec), and to do that we need to combine
the options, so having the options listed in the same
method is a stepping stone towards that.
To get this to work properly, we have to compose the
exception presenter options for pending and for
MultipleExpectationsNotMetError.
It is already listed on the aggregate failure backtrace,
and would be redundant to list it on each sub-failure.
This should hopefully make the travis build go green...
- The presence of backticks within that part was causing rendering
  problems on relish.
- Different rubies have different output there so we already ignore
  that part when comparing the expected to actual output.
This is necessary to support nested aggregation blocks.
This is necessary for niche situations where `aggregate_failures` is nested.
myronmarston added a commit that referenced this pull request May 16, 2015
@myronmarston myronmarston merged commit 4334568 into master May 16, 2015
@myronmarston myronmarston deleted the aggregate-failures branch May 16, 2015 02:08
myronmarston added a commit that referenced this pull request May 16, 2015
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants