ruby-lsp-shoulda-context 0.2.0 → 0.3.1
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/CHANGELOG.md +4 -0
- data/Rakefile +0 -1
- data/Readme.md +2 -2
- data/lib/ruby_lsp/ruby-lsp-shoulda-context/code_lens.rb +44 -37
- 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: '09ae8206abcee5697a5b709fdb5527c3f764d0c31686d2b39a11c1d3ce346e3b'
|
4
|
+
data.tar.gz: 0c9a92f7d8411cab5d3967e069e457ef29c449312073f41c5dc69e41bce7d8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db20a0d41b63d7000b54ada01a178d86391e72f5411cdea8e837a015cae79e87e50eba253785043ae7b24559a7adc4e0d159df973e1e442da8ad8e99aa7dccc9
|
7
|
+
data.tar.gz: 7d45ec20310b9f0f154d574756f16232957541fadbb846c9f848fb486fdf8a0d82d8e51a084e51e22036ed91a59914eed49d1b714b67f676e602a0f4bcbf878a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
|
+
## [0.3.0] - 2024-02-10
|
3
|
+
- Removed collisions from different should/context methods that have the same name at different levels
|
2
4
|
## [0.2.0] - 2024-02-07
|
5
|
+
|
3
6
|
- Add bump gem for semantic versioning and changelog
|
7
|
+
|
4
8
|
## [0.1.0] - 2024-02-07
|
5
9
|
|
6
10
|
- Initial release
|
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -40,9 +40,9 @@ Everyone interacting in the RubyLsp::ShouldaContext project's codebases, issue t
|
|
40
40
|
|
41
41
|
- [x] Make context runnable
|
42
42
|
- [x] Make should with string runnable
|
43
|
-
- [
|
43
|
+
- [x] Make should with method runnable
|
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
47
|
|
48
48
|
**Note**: This project is in very early stage and could have major bugs
|
@@ -9,7 +9,16 @@ module RubyLsp
|
|
9
9
|
|
10
10
|
include ::RubyLsp::Requests::Support::Common
|
11
11
|
|
12
|
-
|
12
|
+
BASE_COMMAND = T.let(
|
13
|
+
begin
|
14
|
+
Bundler.with_original_env { Bundler.default_lockfile }
|
15
|
+
"bundle exec ruby"
|
16
|
+
rescue Bundler::GemfileNotFound
|
17
|
+
"ruby"
|
18
|
+
end + " -ITest",
|
19
|
+
String,
|
20
|
+
)
|
21
|
+
|
13
22
|
REQUIRED_LIBRARY = T.let("shoulda-context", String)
|
14
23
|
|
15
24
|
ResponseType = type_member { { fixed: T::Array[::RubyLsp::Interface::CodeLens] } }
|
@@ -22,29 +31,12 @@ module RubyLsp
|
|
22
31
|
@_response = T.let([], ResponseType)
|
23
32
|
# Listener is only initialized if uri.to_standardized_path is valid
|
24
33
|
@path = T.let(T.must(uri.to_standardized_path), String)
|
34
|
+
@group_id = T.let(1, Integer)
|
25
35
|
@group_id_stack = T.let([], T::Array[Integer])
|
26
|
-
@
|
27
|
-
@id = T.let(1, Integer)
|
36
|
+
@pattern = T.let("test_: ", String)
|
28
37
|
dispatcher.register(self, :on_call_node_enter, :on_call_node_leave, :on_class_node_enter, :on_class_node_leave)
|
29
38
|
|
30
|
-
@base_command =
|
31
|
-
begin
|
32
|
-
cmd = if File.exist?(File.join(Dir.pwd, "bin", "rspec"))
|
33
|
-
"bin/rspec"
|
34
|
-
else
|
35
|
-
"rspec"
|
36
|
-
end
|
37
|
-
|
38
|
-
if File.exist?("Gemfile.lock")
|
39
|
-
"bundle exec #{cmd}"
|
40
|
-
else
|
41
|
-
cmd
|
42
|
-
end
|
43
|
-
end,
|
44
|
-
String,
|
45
|
-
)
|
46
|
-
|
47
|
-
@base_command = "bundle exec ruby -ITest"
|
39
|
+
@base_command = BASE_COMMAND
|
48
40
|
|
49
41
|
super(dispatcher)
|
50
42
|
end
|
@@ -54,42 +46,49 @@ module RubyLsp
|
|
54
46
|
case node.message
|
55
47
|
when "should"
|
56
48
|
name = generate_name(node)
|
49
|
+
@pattern += "should #{name} "
|
57
50
|
add_test_code_lens(node, name: name, kind: :example)
|
58
|
-
@id += 1
|
59
|
-
@test_id_stack.push(@id)
|
60
51
|
when "context"
|
61
52
|
return unless valid_group?(node)
|
62
53
|
|
63
54
|
name = generate_name(node)
|
55
|
+
@pattern += "#{name} "
|
64
56
|
add_test_code_lens(node, name: name, kind: :group)
|
65
|
-
|
66
|
-
@
|
67
|
-
@
|
57
|
+
|
58
|
+
@group_id_stack.push(@group_id)
|
59
|
+
@group_id += 1
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
71
63
|
sig { params(node: Prism::CallNode).void }
|
72
64
|
def on_call_node_leave(node)
|
73
65
|
case node.message
|
66
|
+
when "should"
|
67
|
+
name = generate_name(node)
|
68
|
+
@pattern = remove_last_pattern_in_string(@pattern, "should #{name} ")
|
74
69
|
when "context"
|
75
70
|
return unless valid_group?(node)
|
76
71
|
|
72
|
+
name = generate_name(node)
|
73
|
+
@pattern = remove_last_pattern_in_string(@pattern, "#{name} ")
|
77
74
|
@group_id_stack.pop
|
78
|
-
@test_id_stack.pop
|
79
|
-
when "should"
|
80
|
-
@test_id_stack.pop
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
84
78
|
sig { params(node: Prism::ClassNode).void }
|
85
79
|
def on_class_node_enter(node)
|
86
80
|
class_name = node.constant_path.slice
|
87
|
-
|
88
|
-
|
81
|
+
|
82
|
+
if @path && class_name.end_with?("Test")
|
83
|
+
add_test_code_lens(
|
84
|
+
node,
|
85
|
+
name: class_name,
|
86
|
+
kind: :group,
|
87
|
+
)
|
89
88
|
end
|
90
89
|
|
91
|
-
@group_id_stack.push(@
|
92
|
-
@
|
90
|
+
@group_id_stack.push(@group_id)
|
91
|
+
@group_id += 1
|
93
92
|
end
|
94
93
|
|
95
94
|
sig { params(node: Prism::ClassNode).void }
|
@@ -99,9 +98,17 @@ module RubyLsp
|
|
99
98
|
|
100
99
|
private
|
101
100
|
|
101
|
+
def remove_last_pattern_in_string(string, pattern)
|
102
|
+
string.sub(/#{pattern}$/, "")
|
103
|
+
end
|
104
|
+
|
105
|
+
def pattern_only_has_test?(pattern)
|
106
|
+
pattern == "test_: "
|
107
|
+
end
|
108
|
+
|
102
109
|
sig { params(node: Prism::CallNode).returns(T::Boolean) }
|
103
110
|
def valid_group?(node)
|
104
|
-
!
|
111
|
+
!node.block.nil?
|
105
112
|
end
|
106
113
|
|
107
114
|
sig { params(node: Prism::CallNode).returns(String) }
|
@@ -129,11 +136,11 @@ module RubyLsp
|
|
129
136
|
sig { params(node: Prism::Node, name: String, kind: Symbol).void }
|
130
137
|
def add_test_code_lens(node, name:, kind:)
|
131
138
|
return unless DependencyDetector.instance.dependencies.include?(REQUIRED_LIBRARY)
|
132
|
-
return unless SUPPORTED_TEST_LIBRARIES.include?(DependencyDetector.instance.detected_test_library) && @path
|
133
139
|
|
134
|
-
command = "#{@base_command} #{@path} -n \"/#{
|
140
|
+
command = "#{@base_command} #{@path} -n \"/#{@pattern.strip}/\""
|
135
141
|
|
136
|
-
grouping_data = { group_id: @group_id_stack.last, kind: kind
|
142
|
+
grouping_data = { group_id: @group_id_stack.last, kind: kind }
|
143
|
+
grouping_data[:id] = @group_id if kind == :group
|
137
144
|
|
138
145
|
arguments = [
|
139
146
|
@path,
|
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.3.1
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-lsp
|