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

Use be_empty expectations in more specs #11937

Merged

Conversation

HertzDevil
Copy link
Contributor

This patch replaces most usages of empty?.should be_true with should be_empty, and empty?.should be_false with should_not be_empty, because be_empty's failure message is more descriptive:

require "spec"

it { "".should_not be_empty } # preferred
it { "".empty?.should be_false }
it { "".empty?.should_not be_true }
it { "a".should be_empty } # preferred
it { "a".empty?.should be_true }
it { "a".empty?.should_not be_false }
FFFFFF

Failures:

  1) assert
     Failure/Error: it { "".should_not be_empty }

       Expected: "" not to be empty

     # test.cr:3

  2) assert
     Failure/Error: it { "".empty?.should be_false }

       Expected: false
            got: true

     # test.cr:4

  3) assert
     Failure/Error: it { "".empty?.should_not be_true }

       Expected: actual_value != true
            got: true

     # test.cr:5

  4) assert
     Failure/Error: it { "a".should be_empty }

       Expected: "a" to be empty

     # test.cr:6

  5) assert
     Failure/Error: it { "a".empty?.should be_true }

       Expected: true
            got: false

     # test.cr:7

  6) assert
     Failure/Error: it { "a".empty?.should_not be_false }

       Expected: actual_value != false
            got: false

     # test.cr:8

The only exceptions are specs testing the #empty? method itself. Specs like these are preserved:

describe "#empty?" do
it "test empty?" do
Params.parse("foo=bar&foo=baz&baz=qux").empty?.should be_false
Params.parse("").empty?.should be_true
Params.new.empty?.should be_true
end
end

@HertzDevil HertzDevil changed the title Use be_empty in more specs Use be_empty expectations in more specs Mar 26, 2022
@straight-shoota
Copy link
Member

I would even consider be_empty for testing #empty? explicitly.

@beta-ziliani beta-ziliani added this to the 1.4.0 milestone Mar 29, 2022
@straight-shoota straight-shoota merged commit 7b77c11 into crystal-lang:master Apr 4, 2022
@HertzDevil HertzDevil deleted the refactor/spec-be_empty branch April 6, 2022 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants