-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Convert Tty test to spec. #2040
Conversation
require "utils" | ||
|
||
describe Tty do | ||
specify "::strip_ansi" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use spec names that describe the behaviour rather than just naming a method where possible? These cases seem pretty straightforward, e.g. "::strip_ansi removes ANSI escapes from a String".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2044 (comment) also applies here.
|
||
specify "::width" do | ||
expect(described_class.width).to be_kind_of(Integer) | ||
expect(described_class.width).to be >= 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be different tests, like before.
@@ -0,0 +1,54 @@ | |||
require "utils" | |||
|
|||
describe Tty do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2044 (comment) also applies here.
context "$stdout is not a TTY" do | ||
it "returns an empty string for all colors" do | ||
allow($stdout).to receive(:tty?).and_return(false) | ||
expect(described_class.to_s).to eq("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use be_empty
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that's better here, since eq("")
tests if it is an empty string, not just if it's empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems pretty unlikely to me that #to_s
would return, e.g. an Array, but it's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am aware that this is pretty unlikely, but I like getting two tests for the price of one. 😄
|
||
context "$stdout is not a TTY" do | ||
it "returns an empty string for all colors" do | ||
allow($stdout).to receive(:tty?).and_return(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a before
block since it's doing what's described in the context.
|
||
context "$stdout is not a TTY" do | ||
it "returns an empty string for all colors" do | ||
allow($stdout).to receive(:tty?).and_return(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a before block since it's doing what's described in the context.
context "$stdout is not a TTY" do | ||
it "returns an empty string for all colors" do | ||
allow($stdout).to receive(:tty?).and_return(true) | ||
expect(described_class.to_s).to eq("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use be_empty
here.
a753d99
to
ae6618d
Compare
require "utils" | ||
|
||
describe Tty do | ||
subject { described_class } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this line is necessary. Haven't checked, but I think RSpec automatically sets subject
like this when described_class
is a module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. 👍
ae6618d
to
8736b6c
Compare
brew tests
with your changes locally?