-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
add test for "Better Method#inspect" introduced in Ruby 2.7 #793
Conversation
Looks good 👍 . But I would add some corner cases with |
There are quite few methods in spec/core/method/fixtures/classes.rb Lines 49 to 79 in bfd843a
It would be good to test the output for each "kind" of argument (pre/opt/rest/post/keyreq/keyopt/keyrest/block). |
core/method/shared/to_s.rb
Outdated
ruby_version_is "2.7" do | ||
it "returns a String containing method arguments" do | ||
m = MethodSpecs::Methods.new.method :two_req | ||
m.send(@method).should =~ /\#two_req\(a, b\)/ |
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.
Could you use m.send(@method).should.include?("two_req(a, b)")
?
That way, there is no need to escape any character.
Hello @andrykonchin and @eregon Thank you for your feedbacks. 🎉 Extending the tests revealed a new trivial issue: line size. it "returns a String containing method arguments" do
obj = MethodSpecs::Methods.new
obj.method(:zero).send(@method).should.include?("#zero()")
obj.method(:one_req).send(@method).should.include?("one_req(a)")
obj.method(:two_req).send(@method).should.include?("two_req(a, b)")
# ... there are more ...
obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("one_req_one_opt_with_splat_and_block(a, b=..., *c, &blk)")
obj.method(:two_req_one_opt_with_splat_and_block).send(@method).should.include?("two_req_one_opt_with_splat_and_block(a, b, c=..., *d, &blk)")
obj.method(:one_req_two_opt_with_splat_and_block).send(@method).should.include?("one_req_two_opt_with_splat_and_block(a, b=..., c=..., *d, &blk)")
end Putting the inputs into a "table" and then loop makes it somewhat more readable, but slower (I guess?). it "returns a String containing method arguments" do
obj = MethodSpecs::Methods.new
[
[:zero, "#zero()"],
[:one_req, "one_req(a)"],
[:two_req, "two_req(a, b)"],
# ... there are more ...
[:one_req_one_opt_with_splat_and_block, "one_req_one_opt_with_splat_and_block(a, b=..., *c, &blk)"],
[:two_req_one_opt_with_splat_and_block, "two_req_one_opt_with_splat_and_block(a, b, c=..., *d, &blk)"],
[:one_req_two_opt_with_splat_and_block, "one_req_two_opt_with_splat_and_block(a, b=..., c=..., *d, &blk)"]
].each do |method_key, expected_string|
obj.method(method_key).send(@method).should.include?(expected_string)
end
end Do you have any preferences here? |
I think we can just omit the method name in the String given to it "returns a String containing method arguments" do
obj = MethodSpecs::Methods.new
obj.method(:zero).send(@method).should.include?("()")
obj.method(:one_req).send(@method).should.include?("(a)")
obj.method(:two_req).send(@method).should.include?("(a, b)")
# ... there are more ...
obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
obj.method(:two_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b, c=..., *d, &blk)")
obj.method(:one_req_two_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., c=..., *d, &blk)")
end The table gives less information in the case an expectation fails, so it's not as good. Another possibility would be to just break lines like: it "returns a String containing method arguments" do
obj.method(:one_req_one_opt_with_splat_and_block).send(@method)
.should.include?("one_req_one_opt_with_splat_and_block(a, b=..., *c, &blk)")
end As mentioned in #793 (comment) I think it's useful to test each kind of argument, but not all combinations, so the 3 |
ca705a4
to
be3f8c1
Compare
Hello @eregon Once again, thank you for your review and feedback!
Perfect, done. It fits. 🚀 However, I'm bit intimidated by the comment for testing "each kind of argument", as I am insecure what some of them mean 🙃
However, I added tests for each simple "kind" of argument, plus one "complicated" case. Thanks |
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.
This looks great, thank you!
Hello 👋
From #745
I hope I've chosen the right approach and put it in the right place?!