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

PR 2368 rebased #2379

Merged
merged 3 commits into from
Jan 31, 2017
Merged

PR 2368 rebased #2379

merged 3 commits into from
Jan 31, 2017

Conversation

myronmarston
Copy link
Member

This is #2368 rebased so the build will hopefully go green, and then we can merge.

/cc @xaviershay @JonRowe

Xavier Shay added 3 commits January 30, 2017 18:42
This was prompted by #2367 and the cumulative reporting out of
deprecations. Semantically, this could be weird! Should clearing
examples also clear the reporter? If the reporter is configured after
initialization through a means other than standard RSpec.configure, that
configuration would be lost. I don't know why you would do that though?

The original intent of clear_examples (from #1700) seems to imply that
reseting the reporters was desirable, so I think this is OK.

It's weird that reporter belongs to configuration. It mixes state with
configuration. This means that we have to do a "partial" configuration
reset when we want to "reset except configuration", which suggests to me
that we'll probably have more issues here in the future.

Reported (among other things) in #2367
While technically examples, shared ones function more like
configuration. When using clear_examples, it is surprising that they are
removed since a shared library of them was likely loaded in the
initial configuration steps.

This is a change in behaviour. It was initially added in 2.9 in 8e8fb2b with no rationale. Its API visibility was unspecified at the time, and it's been officially private since 3.

Reported (among other things) in #2367.
    RSpec.configure { |c| c.output_stream = File.open('testout', 'w') }
    RSpec::Core::Runner.run(["spec1"])
    RSpec::Core::Runner.run(["spec2"])

This implementation is possibly a can of worms, but I _think_ I know
what I'm doing?

* close does not guarantee anymore durability than flush. To ensure "no
  bytes are lost" an fsync would be needed. Not tackling that here,
  instead just removing the relevant spec since it wasn't valid.
* BaseFormatter contains logic to save and restore sync, which is broken
  for closed streams. The restore method was patched in the past, but
  the start method wasn't. Also, these methods aren't reliably called
  since BaseTextFormatter doesn't call super. This all probably needs a
  rethink.
* The one reason to close would be to ensure that we don't leak file
  handles. The only time this could cause a problem is if the process
  did a heap of work _after_ rspec was finished running but before
  exiting (or in our specs if we're not careful!). In that case, since
  it's likely the object would still have an active reference via global
  configuration, it would stay open. I think this is a weird enough
  case, and small enough impact, that we're better off just letting
  process exit or GC close the file. It's also somewhat expected, since
  that's what you typically get with a non-block File.open.
* We don't close the deprecation stream anyway. And also it's weird to
  check for $stdout to avoid closig that, but not (say) $stderr.
* close is probably a misleading name for this formatter API, but it's
  public :( Any existing third-party formatters that close streams in
  this method today will be broken in this reuse case anyway though.

Reported (among other things) in #2367
@JonRowe JonRowe merged commit 94dc75e into master Jan 31, 2017
@JonRowe
Copy link
Member

JonRowe commented Jan 31, 2017

LGTM, merging because the build failure is just JRuby failing to install rubocop, see #2380

@JonRowe JonRowe deleted the myron/pr-2368-rebased branch January 31, 2017 05:24
JonRowe added a commit that referenced this pull request Mar 6, 2017
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
…368-rebased

PR 2368 rebased

---
This commit was imported from rspec/rspec-core@450552a.
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