Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Follow frozen_string_literal and equal and be matchers behavior in docs #1303

Closed
wants to merge 1 commit into from
Closed

Follow frozen_string_literal and equal and be matchers behavior in docs #1303

wants to merge 1 commit into from

Conversation

kachick
Copy link
Contributor

@kachick kachick commented Jun 6, 2021

I understand this PR just updates documentations part of #997

@@ -582,7 +582,7 @@ def eql(expected)
#
# @example
# expect(5).to equal(5) # Integers are equal
# expect("5").not_to equal("5") # Strings that look the same are not the same object
Copy link
Member

@pirj pirj Jun 6, 2021

Choose a reason for hiding this comment

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

I believe there is no point to compare two string literals, so this comment describes the case when some non-literal actual value is compared with equal with an expected literal might result in a failure.

BTW, the use of equal instead of be_equal seems to be the real problem here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Suggested change
# expect("5").not_to equal("5") # Strings that look the same are not the same object
# expect(+"5").not_to equal(+"5") # Strings that look the same are not the same object

So this is a way (or use dup). Is it better?

Copy link
Member

Choose a reason for hiding this comment

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

What are you after with this change in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1303 (comment) is the my motivation

Copy link
Member

Choose a reason for hiding this comment

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

To me, the current doc says "don't use equals unless you absolutely know what you're doing, e.g. if you compare identical strings that are not the same object, the comparison would fail".
Do you think adding + would help to make this more clear for developers of all experience levels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks, that is the documentation direction of this project, I understood.

@@ -92,6 +92,8 @@ Feature: Equality matchers
Scenario: compare using equal (equal?)
Given a file named "compare_using_equal.rb" with:
"""ruby
# frozen_string_literal: false
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know, # frozen_string_literal: false makes the old ruby behaviors for string literals.
Recent projects basically prefers # frozen_string_literal: true. Then ruby handles same string literal as a same object.

So clarifying to set false does not make confusion when reading docs as a tutorial. I think.

Copy link
Member

@pirj pirj Jun 6, 2021

Choose a reason for hiding this comment

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

We use .feature files for two purposes:

  1. Documentation, that is published to https://relishapp.com/rspec/
    I'd prefer not to show an example that the usage of frozen_string_literal makes sense or difference for spec files, as I haven't seen any evidence of that.

  2. End-to-end tests of our code
    Is there a good reason to explicitly specify the already default non-frozen string literal in our own tests?

Was the current doc causing a confusion of some kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know the cucumber role in this project.

Personally I don’t have any problem. So I will left from this issue!

@kachick kachick closed this Jun 6, 2021
@kachick kachick deleted the follow-frozen_string_literal branch June 6, 2021 18:10
@pirj
Copy link
Member

pirj commented Jun 6, 2021

Thanks for understanding.

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