ruby-lsp-shoulda-context 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +0 -6
- data/Readme.md +6 -6
- data/lib/ruby_lsp/ruby-lsp-shoulda-context/code_lens.rb +44 -37
- data/lib/ruby_lsp/shoulda_context/version.rb +1 -1
- data/lib/ruby_lsp/shoulda_context.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e85ecf8ef4be164ef72b0817522b02075af4e60c67f5ea995fe4c8e2e822080
|
4
|
+
data.tar.gz: c3f914b5aa84fd369e433137c0efc6a996bdeef610dcd739bd8120fbdb746292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85b000eb5c0500c8dd375d912ee926d88d04d19cee72fd926013b78ea873c190570fa55c4fa483c6cb063db5700501d90b2e0feec6958f1591ec8b968ff53b78
|
7
|
+
data.tar.gz: 1b637d01c9aaf0f85abe772415389ffb7a0f46f9262a78470145716f240566d78a25dac593626e1d061f3235aa69b5902d7d46e72fba344ded83cf323d771d65
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -4,15 +4,15 @@ This gem provides support for [shoulda-context](https://github.com/thoughtbot/sh
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
TODO: Replace `
|
7
|
+
TODO: Replace `ruby-lsp-shoulda-context` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
8
|
|
9
9
|
Install the gem and add to the application's Gemfile by executing:
|
10
10
|
|
11
|
-
|
11
|
+
bundle add ruby-lsp-shoulda-context
|
12
12
|
|
13
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
14
|
|
15
|
-
|
15
|
+
gem install ruby-lsp-shoulda-context
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
@@ -36,13 +36,13 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
36
36
|
|
37
37
|
Everyone interacting in the RubyLsp::ShouldaContext project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[domingo2000]/ruby-lsp-shoulda-context/blob/main/CODE_OF_CONDUCT.md).
|
38
38
|
|
39
|
-
## Roadmap
|
39
|
+
## Roadmap
|
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.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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-lsp
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- Readme.md
|
41
41
|
- lib/ruby_lsp/ruby-lsp-shoulda-context/addon.rb
|
42
42
|
- lib/ruby_lsp/ruby-lsp-shoulda-context/code_lens.rb
|
43
|
+
- lib/ruby_lsp/shoulda_context.rb
|
43
44
|
- lib/ruby_lsp/shoulda_context/version.rb
|
44
45
|
homepage: https://github.com/domingo2000/ruby-lsp-shoulda-context
|
45
46
|
licenses:
|