ruby-lsp-shoulda-context 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df77769d30187280cbfb7653ab7c30b097f1a257e96d6f8b516973c17e01e060
4
- data.tar.gz: a4b86b7db5dbf742a8e23e209014b1f439fe09f6d183ee3b2cbdb3d2af09a884
3
+ metadata.gz: '09ae8206abcee5697a5b709fdb5527c3f764d0c31686d2b39a11c1d3ce346e3b'
4
+ data.tar.gz: 0c9a92f7d8411cab5d3967e069e457ef29c449312073f41c5dc69e41bce7d8fd
5
5
  SHA512:
6
- metadata.gz: 10d9c031dfb1ebeb7710458e2bc57197ac9fd2d565351067d62d920558a40d8e0579bd82e37a8b869368b2e892b10a08a1e1de769bf37ce1108a70fe17cceea4
7
- data.tar.gz: 75f3213c94dafce5ec96bbf6d3ab922b6806fa76b1c55a4dd96da7ff9765d5e771ffbb14cd5dcfe10700a530e1e88d75a747dbb4249301c7b9924e5850e12444
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
@@ -9,5 +9,4 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
-
13
12
  task default: [:test, :rubocop]
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
- - [ ] Make should with method runnable
43
+ - [x] Make should with method runnable
44
44
  - [ ] Make exec method conditional to rails or Minitest setup
45
- - [ ] 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)
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
- SUPPORTED_TEST_LIBRARIES = T.let(["minitest", "test-unit"], T::Array[String])
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
- @test_id_stack = T.let([], T::Array[Integer])
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 = T.let(
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
- @group_id_stack.push(@id)
66
- @id += 1
67
- @test_id_stack.push(@id)
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
- if class_name.end_with?("Test")
88
- add_test_code_lens(node, name: class_name, kind: :group)
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(@id)
92
- @id += 1
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
- !(node.block.nil? || (node.receiver && node.receiver&.slice != "RSpec"))
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 \"/#{name}/\""
140
+ command = "#{@base_command} #{@path} -n \"/#{@pattern.strip}/\""
135
141
 
136
- grouping_data = { group_id: @group_id_stack.last, kind: kind, id: @id }
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,
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RubyLsp
5
5
  module ShouldaContext
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.1"
7
7
  end
8
8
  end
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.2.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-08 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lsp