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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 187f5ae0d0929abe9c9642e92de8859d06fbe03a3633c41402eb009e28023568
4
- data.tar.gz: f8e209ea9af5c9d884a0536328a35a2ba0791c238306148b844cb6b81ca9caad
3
+ metadata.gz: 1e85ecf8ef4be164ef72b0817522b02075af4e60c67f5ea995fe4c8e2e822080
4
+ data.tar.gz: c3f914b5aa84fd369e433137c0efc6a996bdeef610dcd739bd8120fbdb746292
5
5
  SHA512:
6
- metadata.gz: a41cfbdabc0ce001903accdaf9694463f74e81172531b65043378e1360ad9126a7b952d6c494309f63c89298038e858ebdbef11f25de3430306ad31f26cb0eb2
7
- data.tar.gz: 5710da8600b182a6782449955100dc5262b046b0af9a1575854b3c1a19330a26bddfeded4cf1f5e6982b4a74ca4f701c5a7fe96a541f2a8c7a167b91ca3d754f
6
+ metadata.gz: 85b000eb5c0500c8dd375d912ee926d88d04d19cee72fd926013b78ea873c190570fa55c4fa483c6cb063db5700501d90b2e0feec6958f1591ec8b968ff53b78
7
+ data.tar.gz: 1b637d01c9aaf0f85abe772415389ffb7a0f46f9262a78470145716f240566d78a25dac593626e1d061f3235aa69b5902d7d46e72fba344ded83cf323d771d65
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
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
4
+ ## [0.2.0] - 2024-02-07
5
+
6
+ - Add bump gem for semantic versioning and changelog
2
7
 
3
8
  ## [0.1.0] - 2024-02-07
4
9
 
data/Rakefile CHANGED
@@ -9,10 +9,4 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- # Rake::TestTask.new(:test) do |t|
13
- # t.libs << "test"
14
- # t.libs << "lib"
15
- # t.test_files = FileList["test/**/*_test.rb"]
16
- # end
17
-
18
12
  task default: [:test, :rubocop]
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 `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` 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.
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
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- - [ ] 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.1.0"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
@@ -0,0 +1,11 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "shoulda_context/version"
5
+
6
+ module RubyLsp
7
+ module ShouldaContext
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
11
+ 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.1.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-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
@@ -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: