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

Convert Tty test to spec. #2040

Merged
merged 1 commit into from
Feb 18, 2017
Merged

Conversation

reitermarkus
Copy link
Member

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

require "utils"

describe Tty do
specify "::strip_ansi" do
Copy link
Contributor

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".

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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("")
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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)
Copy link
Contributor

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("")
Copy link
Contributor

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.

require "utils"

describe Tty do
subject { described_class }
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice. 👍

@reitermarkus reitermarkus merged commit 61a41d0 into Homebrew:master Feb 18, 2017
@reitermarkus reitermarkus deleted the spec-utils_tty branch February 18, 2017 14:06
@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
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