-
-
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
Enable logging non-string - fix #1410 #1412
Conversation
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.
Looks good to me!
lib/cucumber/glue/proto_world.rb
Outdated
@@ -108,8 +108,7 @@ def embed(file, mime_type, _label = 'Screenshot') | |||
end | |||
|
|||
def log(message) | |||
raise Cucumber::LogTypeInvalid unless message.is_a?(String) | |||
attach(message.dup, 'text/x.cucumber.log+plain') | |||
attach(message.to_s.dup, 'text/x.cucumber.log+plain') |
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.
Why the dup
?
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.
Otherwise we log the object itself and it will display its value at display time, not at log time (there a test showing that and it fails without the dup
)
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 understand why we used to do message.dup
, but I don't think we need message.to_s.dup
. I think message.to_s
is sufficient.
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.
(Me, a reader, thought this was because the string would be used in a mutable context.)
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 though the to_s
would be enough too. In fact it's enough for non-string objects (obviously :D ) but when using a String we need the dup
.
An example from the tests:
describe 'when modifying the printed variable after the call to puts' do
define_feature <<-FEATURE
Feature: Banana party
Scenario: Monkey eats banana
When puts is called twice for the same variable
FEATURE
define_steps do
When(/^puts is called twice for the same variable$/) do
foo = String.new('a')
puts foo
foo.upcase!
puts foo
end
end
This test fails without the dup
(we output A\nA
instead of a\nA
). I suspect that String.to_s do not return a duplicate but imply itself (also note, the test still uses puts
instead of log, but that'll be removed once we removed the override of puts
by log
)
And @olleolleolle you're not wrong, it's just that the string might be mutated between the moment it I logged and the moment we actually display it.
dsl.Given(/Loud/) do | ||
log ['Not', 1, 'string'] | ||
end | ||
expect { run_step 'Loud' }.to raise_exception(Cucumber::LogTypeInvalid) |
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.
Is Cucumber::LogTypeInvalid
still used? Should it be removed?
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.
indeed
Summary
See #1410
Details
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: