Skip to content

🌈 Fix readline specs#717

Merged
rafaelfranca merged 2 commits into
rails:masterfrom
bpo:fix-readline-specs
Mar 5, 2020
Merged

🌈 Fix readline specs#717
rafaelfranca merged 2 commits into
rails:masterfrom
bpo:fix-readline-specs

Conversation

@bpo

@bpo bpo commented Mar 5, 2020

Copy link
Copy Markdown
Contributor

An error was introduced in commit 7061b06
where readline specs fail because require "readline" is called after the
spec has established a mock ::Readline. Prior to that change
require "readline" was always only called once.

This patch:

  • memoizes the require to ensure that it only happens once
  • leaves the Object.const_defined? check in place to keep tests simple
  • eagerly calls available? in the readline spec to match the original
    author's intent by requiring readline before the specs start.

This error wasn't caught by CI due to the bundler cache. You can see the failure caused by the earlier change by removing the Bundler cache from Travis

An error was introduced in commit 7061b06
where readline specs fail because `require "readline"` is be called after the
spec has established a mock `::Readline`. Prior to that change
`require "readline"` was always only called once.

This patch:
  * memoizes the `require` to ensure that it only happens once
  * leaves the `Object.const_defined?` check in place to keep tests simple
  * eagerly calls `available?` in the readline spec to match the original
    author's intent by requiring `readline` before the specs start.
class Readline < Basic
def self.available?
begin
require "readline"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

require by default only happens once. Why do we need this memoization?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had myself convinced that subsequent calls after building the mock would raise a TypeError here, but I was incorrect. Will update this PR.

@rafaelfranca rafaelfranca merged commit 8ec6acb into rails:master Mar 5, 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.

2 participants