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

🌈 Fix readline specs #717

Merged
merged 2 commits into from
Mar 5, 2020
Merged

Conversation

bpo
Copy link
Contributor

@bpo bpo commented Mar 5, 2020

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.
@@ -2,8 +2,8 @@ class Thor
module LineEditor
class Readline < Basic
def self.available?
begin
require "readline"
Copy link
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
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