ruby-lsp-shoulda-context 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +1 -0
- data/lib/ruby_lsp/ruby-lsp-shoulda-context/code_lens.rb +26 -9
- data/lib/ruby_lsp/shoulda_context/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8112ca7fa20b49f281d1b3b89975e7cab08adbdc93d753daaa0b275423adff19
|
4
|
+
data.tar.gz: 7a175a8727300cc49bedf73b82e7263330262e319a8df36083215b4deed11f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 443dcb56b9542410765f47fc3a22d7135fa09ad71abb6e9d2308eee42566b5854c16564abc2f515e4e0433be5e830d1de5ff18c25b41e6612f6d3991129139dc
|
7
|
+
data.tar.gz: 1d9353e3befef9ee4b5f9e7f11cca6e44034fd8cd64c2af0250bacd7716b1113f7eaba9985003a909038c7d2dbddcac021fa5041eb26506c777776a9cdb72833
|
data/Readme.md
CHANGED
@@ -44,5 +44,6 @@ Everyone interacting in the RubyLsp::ShouldaContext project's codebases, issue t
|
|
44
44
|
- [ ] Make exec method conditional to rails or Minitest setup
|
45
45
|
- [x] Make inner context or inner should with collissions with outer DSL not collide using full name of the test (Currently if 2 tests have the same name both are executed)
|
46
46
|
- [x] Provide grouping with classes that ends with "..Test" syntax (Note: The codelens is duplicated becuase lsp support minitest by default and LSP responses are merged)
|
47
|
+
- [ ] Provide support for Inner Classes
|
47
48
|
|
48
49
|
**Note**: This project is in very early stage and could have major bugs
|
@@ -11,11 +11,12 @@ module RubyLsp
|
|
11
11
|
|
12
12
|
BASE_COMMAND = T.let(
|
13
13
|
begin
|
14
|
+
cmd = File.exist?(File.join(Dir.pwd, "bin", "rails")) ? "bin/rails test" : "ruby -ITest"
|
14
15
|
Bundler.with_original_env { Bundler.default_lockfile }
|
15
|
-
"bundle exec
|
16
|
+
"bundle exec #{cmd}"
|
16
17
|
rescue Bundler::GemfileNotFound
|
17
|
-
|
18
|
-
end
|
18
|
+
cmd
|
19
|
+
end,
|
19
20
|
String,
|
20
21
|
)
|
21
22
|
|
@@ -31,6 +32,7 @@ module RubyLsp
|
|
31
32
|
@_response = T.let([], ResponseType)
|
32
33
|
# Listener is only initialized if uri.to_standardized_path is valid
|
33
34
|
@path = T.let(T.must(uri.to_standardized_path), String)
|
35
|
+
@class_name = T.let("", String)
|
34
36
|
@group_id = T.let(1, Integer)
|
35
37
|
@group_id_stack = T.let([], T::Array[Integer])
|
36
38
|
@pattern = T.let("test_: ", String)
|
@@ -46,6 +48,12 @@ module RubyLsp
|
|
46
48
|
case node.message
|
47
49
|
when "should"
|
48
50
|
name = generate_name(node)
|
51
|
+
|
52
|
+
# If is top level should without context the DSL is different
|
53
|
+
if @group_id_stack.length == 1
|
54
|
+
@pattern += "#{@class_name} "
|
55
|
+
end
|
56
|
+
|
49
57
|
@pattern += "should #{name} "
|
50
58
|
add_test_code_lens(node, name: name, kind: :example)
|
51
59
|
when "context"
|
@@ -65,7 +73,13 @@ module RubyLsp
|
|
65
73
|
case node.message
|
66
74
|
when "should"
|
67
75
|
name = generate_name(node)
|
76
|
+
|
68
77
|
@pattern = remove_last_pattern_in_string(@pattern, "should #{name} ")
|
78
|
+
|
79
|
+
# If is top level should without context the DSL is different
|
80
|
+
if @group_id_stack.length == 1
|
81
|
+
@pattern = remove_last_pattern_in_string(@pattern, "#{@class_name} ")
|
82
|
+
end
|
69
83
|
when "context"
|
70
84
|
return unless valid_group?(node)
|
71
85
|
|
@@ -78,12 +92,13 @@ module RubyLsp
|
|
78
92
|
sig { params(node: Prism::ClassNode).void }
|
79
93
|
def on_class_node_enter(node)
|
80
94
|
class_name = node.constant_path.slice
|
95
|
+
@class_name = remove_last_pattern_in_string(class_name, "Test")
|
81
96
|
|
82
97
|
if @path && class_name.end_with?("Test")
|
83
98
|
add_test_code_lens(
|
84
99
|
node,
|
85
100
|
name: class_name,
|
86
|
-
kind: :
|
101
|
+
kind: :class,
|
87
102
|
)
|
88
103
|
end
|
89
104
|
|
@@ -102,10 +117,6 @@ module RubyLsp
|
|
102
117
|
string.sub(/#{pattern}$/, "")
|
103
118
|
end
|
104
119
|
|
105
|
-
def pattern_only_has_test?(pattern)
|
106
|
-
pattern == "test_: "
|
107
|
-
end
|
108
|
-
|
109
120
|
sig { params(node: Prism::CallNode).returns(T::Boolean) }
|
110
121
|
def valid_group?(node)
|
111
122
|
!node.block.nil?
|
@@ -137,7 +148,13 @@ module RubyLsp
|
|
137
148
|
def add_test_code_lens(node, name:, kind:)
|
138
149
|
return unless DependencyDetector.instance.dependencies.include?(REQUIRED_LIBRARY)
|
139
150
|
|
140
|
-
|
151
|
+
if kind == :class
|
152
|
+
pattern = "#{@class_name}Test"
|
153
|
+
kind = :group
|
154
|
+
else
|
155
|
+
pattern = @pattern.strip
|
156
|
+
end
|
157
|
+
command = "#{@base_command} #{@path} --name \"/#{pattern}/\""
|
141
158
|
|
142
159
|
grouping_data = { group_id: @group_id_stack.last, kind: kind }
|
143
160
|
grouping_data[:id] = @group_id if kind == :group
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp-shoulda-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domingo Edwards
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-lsp
|