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

Add a failing spec for #1343. #1353

Merged
merged 2 commits into from
Feb 26, 2014
Merged

Conversation

myronmarston
Copy link
Member

Not sure how to fix this yet. Pushing it to start the conversation.

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

Is it worth considering --require spec_helper or any file in the spec folder as a "delayed" require?

The other option is to somehow process the formatter loading without the requires having been processed, some sort of placeholder formatter?

@myronmarston
Copy link
Member Author

Is it worth considering --require spec_helper or any file in the spec folder as a "delayed" require?

That's one solution. I don't like changing when a --require file is loaded based on what directory it is in, though....that feels hacky. Other solution ideas:

  • Change when we setup the default formatters, and change our generated spec_helper so that it puts the code that sets the formatter to doc into a before(:suite), so that it is delayed until before the specs are run. I tried part of this (moving the code into before(:suite)) but the default formatters were already set up so it was too late.
  • Expose a first class API for this: config.fallback_formatter = 'doc' (or something like that).
  • Do something similar to Fix for #1280 #1289, where we set the passed formatter config to configuration early and then load it lazily.

I'm leaning towards the 1st or 2nd ideas. Thoughts?

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

I'm thinking we push formatter loading before --require and that if we can't load a formatter class immediately wrap it in something to defer it's loading? The alternative is your third suggestion were we process and cache formatter names, but defer their initialisation until later?

I don't mind your first suggestion, but it doesn't fix the issue, just avoids it. The second suggestion doesn't really fit the bill, as this is an override of a formatter, not a fallback.

@myronmarston
Copy link
Member Author

The second suggestion doesn't really fit the bill, as this is an override of a formatter, not a fallback.

I would definitely consider this a fallback. The idea of the generated spec_helper is to use the doc formatter when two conditions are met:

  • No other formatter has been set anywhere
  • Only one spec file is being run

It's a fallback because this config is only intended to take affect if nothing else sets a formatter.

The more I think about that option, the more I like it.

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

Oh I see, you're suggesting we change it so the default formatter when there's only one file to run, yeah ok I'm on board with that.

@myronmarston
Copy link
Member Author

Oh I see, you're suggesting we change it so the default formatter when there's only one file to run, yeah ok I'm on board with that.

That's the entire point of this line of code:

# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.formatter = 'doc' if config.formatters.none?

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

Yes, but the issue is how that interacts with the overridden formatter, this issue of there being "no formatters" would still exist ;)

@myronmarston
Copy link
Member Author

Yes, but the issue is how that interacts with the overridden formatter, this issue of there being "no formatters" would still exist ;)

Sure, but the goals of making --require load files as early as possible (so they can do early things not possible by requiring files from your spec files) and making all configs available in a spec_helper loaded in this fashion are at odds. I really only care about this in as much as it's useful to be able to configure a fallback formatter and before now there wasn't an API for that so I was using formatters.none?.

The spec_helper generated by `rspec --init` could
cause both the progress and documentation formatter
to be used for a command like:

rspec path/to/spec.rb --format progress

This happened because formatters are loaded _after_
`--require` files, so the `config.formatters.none?`
check returned true even though a formatter had
been explicitly set at the command line. It's important
that requires come first so that custom formatters can
be appropriately loaded.
@myronmarston
Copy link
Member Author

@JonRowe -- I just pushed my implementation of this...care to review?

@myronmarston
Copy link
Member Author

Oh yeah, this needs a changelog still -- I'll take care of that later.

@JonRowe
Copy link
Member

JonRowe commented Feb 26, 2014

LGTM

myronmarston added a commit that referenced this pull request Feb 26, 2014
@myronmarston myronmarston merged commit 53a334a into master Feb 26, 2014
@myronmarston myronmarston deleted the fix-spec-helper-formatters-issue branch February 26, 2014 05:16
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.

2 participants