- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 58
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
lib/context: fix Ruby 2.7 warning #64
base: master
Are you sure you want to change the base?
Conversation
This fixes the warning for: ``` /vendor/gems/ruby/2.7.0/gems/shoulda-context-2.0.0/lib/shoulda/context/context.rb:209: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call ```
h = { k: 42 } | ||
context.this_is_missing(h) | ||
end | ||
end |
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've added this test, but even if we remove the ruby2_keywords
fix, this tests passes. I'm open to suggestion on how to improve it.
Hey, thanks for submitting this. What is the warning you're getting? Additionally, I think the reason your test passes now is that a warning isn't the same as an error; if you really wanted to test for that I think you'd have to use something like |
Hi @mcmire I wrote it in the PR description but seems like the line wasn't wrapped. This is what I see:
Could you point me to an existing test that tests a |
@fatih We don't currently use assert_output("", /Some warning goes here/) do
# ... do something that would generate a warning ...
end As for this warning itself, what are you doing that generates this warning? Are you using |
There is a method like this def self.it_behaves_like_timed_route(method: :get, status: 200, path: , &block)
should 'time the route execution' do
response = instance_exec(&block)
expected_tags = [
"method:#{method}",
"route:#{path}",
"status:#{status}",
"status_range:#{status.to_s.first}xx"
]
assert_equal 1, timings('request.time', tags: expected_tags).count
end
end And then call it like this: class FooControllerTest < ActiveSupport::TestCase
context 'POST /foo/:id/bar' do
it_behaves_like_timed_route(method: :post, status: 401, path: '/foo/:id/bar') do
post FOO.app_path('/foo/1/bar')
end
end
end This gives then an error saying
but when track it down it points to this line:
Not sure what's going on there at this point. Is it because I created a method and use that? This is the complete log:
|
@fatih Okay. Is |
@mcmire it's a method of this Class:
And then inside |
We had to make a similar change in factory_bot (see thoughtbot/factory_bot#1415 and then thoughtbot/factory_bot#1425). While reviewing that change I found this post on argument delegation in Ruby2.7/3 useful. I think this change should be good to go once we are happy with the test. We didn't use |
@emilford and I worked on writing a test for this, and we figured out why we weren't seeing the deprecation warnings. It has to do with the We temporarily disabled the warnings logger and realized that the original test case wasn't outputting any deprecation warnings because the hash argument was coming in as the first argument to `this_is_missing, rather than as a kwarg. This is a test that triggers the method_missing warning. We also added a positive assertion to replace def test_should_pass_on_missing_method
delegated_to_missing = false
self.class.define_singleton_method(:this_is_missing) do |bar:|
delegated_to_missing = true
end
context = Shoulda::Context::Context.new("context name", self.class) {}
context.this_is_missing(bar: 42)
assert delegated_to_missing
self.class.singleton_class.undef_method(:this_is_missing)
end We could also add cc @mcmire |
@composerinteralia Ah, okay, I see what you're talking about with warnings_logger. I originally extracted that gem for shoulda-matchers under RSpec and it seems I didn't properly test it for Minitest (it appears that Minitest hijacks |
Good find! I didn't think to check Minitest for calls to |
@composerinteralia @fatih I just fixed |
Is there any plan to merge and release this? Without it I believe |
Yikes, sorry for the delay on this PR, it's been a long time. Right now this PR is blocked because there are code changes, but we don't have any way to confirm that this change really does fix the issue. It looks like @composerinteralia submitted a test that should produce a failure without this fix, so I need to drop that in and see if it really does fail. I can try doing this by end of week. |
This fixes the warning for: