-
Notifications
You must be signed in to change notification settings - Fork 3
Fix local variable bindings #16
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16 +/- ##
==========================================
+ Coverage 86.54% 86.59% +0.04%
==========================================
Files 23 23
Lines 1078 1104 +26
Branches 77 76 -1
==========================================
+ Hits 933 956 +23
- Misses 145 148 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey, nice catch! Do you mind adding a spec for this to prevent regressions in the future? Thank you in advance. |
|
Yes! Let me add them. I also realize that there is probably also another improvement for something like an include pin? Maybe even generalize this further up to remove the block corrector. I'll see what I can do |
8131965 to
4fa3e7a
Compare
|
Hey @lekemula I changed the way that I'm fixing the issue & added needed specs. Unfortunately, it seems to affect a spec in a correct but "not like it was before" manner. Basically, now this spec resolved |
|
Thanks for the specs and suggested refactoring @ShadiestGoat 👍 Let me know what do you think about: #16 (comment) |
@ShadiestGoat I'm fine with moving forward with this despite the super-minor "breaking change" (see comment), as soon as you include the other suggestions. Good stuff 👍 |
|
Hi - sorry for the long wait. I'll apply the suggestions in a sec, but I did want to confirm - are you sure? This would break the plugin until your solargraph PR gets merged! |
Hi, I'm fine to move forward with this because I think the issue relates to the way we write the spec, which is an edge case IMO. #16 (comment) That is, we define the class inside: RSpec.describe SomeNamespace::Transaction, type: :model do
class MyClass; end
let(:some_object) { MyClass.new }
endIf I understand you correctly, this would still work, right? class MyClass; end
RSpec.describe SomeNamespace::Transaction, type: :model do
let(:some_object) { MyClass.new }
end |
I can confirm, this does work: diff --git a/spec/solargraph/rspec/convention_spec.rb b/spec/solargraph/rspec/convention_spec.rb
index 1391374..c813b4b 100644
--- a/spec/solargraph/rspec/convention_spec.rb
+++ b/spec/solargraph/rspec/convention_spec.rb
@@ -481,11 +481,19 @@ def load_and_assert_type(let_declaration, let_name, expected_type)
end
it 'infers type for some_object' do
- pending('https://github.com/castwide/solargraph/pull/1008')
- load_and_assert_type(<<~RUBY, 'some_object', 'RSpec::ExampleGroups::TestSomeNamespaceTransaction::MyClass')
+ load_string filename, <<~RUBY
class MyClass; end
- let(:some_object) { MyClass.new }
+
+ RSpec.describe SomeNamespace::Transaction, type: :model do
+ let(:some_object) { MyClass.new }
+ end
RUBY
+
+ assert_public_instance_method_inferred_type(
+ api_map,
+ "RSpec::ExampleGroups::TestSomeNamespaceTransaction#some_object",
+ 'MyClass'
+ )
endSo let's inline |
|
Merging this as is and will apply #16 (comment) changes afterwards. Thanks for the changes @ShadiestGoat! |
Hey!
As part of my work on the
include& factory bot, I've noticed that auto complete is a bit wonky at times for variables defined within examples and contexts. After tons ofputsstatements everywhere, I have to the conclusion that the reason is that the local variables aren't bound to the right block. So eg:Solargraph can recognize the method's return type, but can't infer the type on
some_variable