-
Notifications
You must be signed in to change notification settings - Fork 121
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 files for actionpack, activemodel, activerecord, and activesupport #104
Conversation
I changed the git remote of sorbet-typed in my |
And fix a few bugs that were found while writing the tests.
Also fix a bug in the type signature of belongs_to.
Alright, I've added more tests and explained how the tests work in the README. Plus I've fixed a few bugs I found with the existing signatures :) This should be good to review now. |
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 think this is a great idea. One thing that occurred to me is that if a gem has breaking changes between one version and the next, your tests may not be able to account for that. For example:
diff --git a/lib/activesupport/>=6.0.0.rc1/activesupport.rbi b/lib/activesupport/>=6.0.0.rc1/activesupport.rbi
index 9c5e29f..6a146fe 100644
--- a/lib/activesupport/>=6.0.0.rc1/activesupport.rbi
+++ b/lib/activesupport/>=6.0.0.rc1/activesupport.rbi
@@ -1,6 +1,9 @@
# typed: strong
class Array
+ sig { params(a: String).void }
+ def foo(a); end
+
sig { params(elements: T.untyped).returns(T::Array[T.untyped]) }
def excluding(*elements); end
diff --git a/lib/activesupport/all/activesupport.rbi b/lib/activesupport/all/activesupport.rbi
index dd65c02..c2af914 100644
--- a/lib/activesupport/all/activesupport.rbi
+++ b/lib/activesupport/all/activesupport.rbi
@@ -241,6 +241,9 @@ class String
end
class Array
+ sig { params(a: Integer).void }
+ def foo(a); end
+
sig { returns(T::Boolean) }
def blank?; end
diff --git a/lib/activesupport/test/activesupport_test.rb b/lib/activesupport/test/activesupport_test.rb
index f025cb8..ecf9105 100644
--- a/lib/activesupport/test/activesupport_test.rb
+++ b/lib/activesupport/test/activesupport_test.rb
@@ -1,5 +1,7 @@
# typed: true
+Array.new.foo('hi')
+
module ActiveSupportNumberHelperTest
extend ActiveSupport::NumberHelper
results in:
lib/activesupport/test/activesupport_test.rb:3: Expected Integer but found String("hi") for argument a https://srb.help/7002
3 |Array.new.foo('hi')
^^^^^^^^^^^^^^^^^^^
lib/activesupport/all/activesupport.rbi:244: Method Array#foo has specified a as Integer
244 | sig { params(a: Integer).void }
^
Got String("hi") originating from:
lib/activesupport/test/activesupport_test.rb:3:
3 |Array.new.foo('hi')
^^^^
Errors: 1
One way you can fix this is to include tests in each sub-directory instead and then modify the CI script. Here is an example: panthomakos@f53acfb which resolves this issue.
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 seems like a clear improvement to me & it has already discovered existing bugs.
Thank you, this is great! LGTM
If someone wants to improve on this, improvements are also welcome!
@panthomakos 👍 you should open a PR to change that, it looks like a good idea (though I'd prefer if the files were named You can go into I really should open an issue to make this easier... |
Thank you for the write-up. I'll put a PR together! |
I have no idea what this does to sorbet if this is merged and you try to update sorbet-typed.
I've included an intentionally failing method to show that this is working. However, it only allows files that have no type errors, there's no way to test that sorbet catches incorrect code.
This is a simplified version of my
routes.rb
file that I showed in #95.The idea to do this was started by #42 and re-upped in #102 by @panthomakos.
cc: @DarkDimius @jez I know this isn't the test harness you wanted, and I'd still like to get that eventually, but I'm curious if you think this solution would be workable? Do you see any significant flaws with this approach?