-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 NoMethodError that is raised when the environment variable CUCUMBER_COLORS is defined #1641
Conversation
Signed-off-by: Stephan Kämper <[email protected]>
Signed-off-by: Stephan Kämper <[email protected]>
As a question for the reviewers: I wonder if there should be additional tests for this. While the existing tests had to be adapted to reflect the code change, I'm not (entirely) sure whether this is sufficient (given that the bug slipped through with the tests). Even though
would have revealed the bug, I'm not sure this would be a good fit for another scenario in a feature file. |
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.
Thanks for your PR @s2k :)
Would it be possible to keep an instance methods - which would just call the class one - in order to prevent anything to break for users who would have hacked their cucumber?
And thus we could make sure to test the two methods actually
Also there is a call to apply_custom_colors right after it has been defined. I am surprised you did not had to change that call actually, but I may have missed something with ruby here 🤔
…e specs Signed-off-by: Stephan Kämper <[email protected]>
Thanks for the feedback. I had to change the definition of Here's an example: module Example
def for_instances(arg)
p arg
end
def self.for_class(arg)
p arg
end
begin
for_class('Calling the class method is OK')
rescue NoMethodError => e
p e
end
begin
for_instances('The instance method is not available in the class')
rescue NoMethodError => e
puts "That didn't work"
puts "Message:"
puts "*" * 40
puts e.message
puts "*" * 40
end
end Running it yields:
In other words: I hesitate to provide an instance method, because the method is not meant to be called on an instance (but provided it anyway 🙂), so we can discuss it. |
Thanks for the update. @luke-hill what is your opinion on this? |
Co-authored-by: Aurélien Reeves <[email protected]>
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.
If we have a mixture of things we need (or you want to permit both the class method and the instance method variant), your better bet is simply manipulating yourself from instance to class by doing self.class.foo
…it in the specs" This reverts commit 1560c6e.
No worries, I'll just need to revert 1560c6e, right? |
Yes, in addition to the last comments from @luke-hill |
OK, as far as I can see we could now merge this PR, no? |
This needs releasing. The bug with CUCUMBER_COLORS is in the current release 8.0.0 7 months after it has been fixed in cucumber:main. Can we get a point release out to address this? |
Description
This fixes a NoMethodError exception that is raised, when the environment variable
CUCUMBER_COLORS
is set, by allowingapply_custom_colors
to be called right after its definition inCucumber::Formatter::ANSIColor
.Defining the method as a class method of the module allows it to be called in the module itself.
Type of change