solargraph-rspec 0.2.1 → 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 +22 -0
- data/README.md +22 -4
- data/lib/solargraph/rspec/config.rb +10 -0
- data/lib/solargraph/rspec/spec_walker/fake_let_method.rb +12 -9
- data/lib/solargraph/rspec/spec_walker/node_types.rb +3 -2
- data/lib/solargraph/rspec/spec_walker.rb +1 -1
- data/lib/solargraph/rspec/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: eb5a5e8955a55b4b936e0f7ac8b75daeddd08cc5eed9230b5706054398384480
|
4
|
+
data.tar.gz: bb897224942929755a8b9aebbc224bed114393f05b66115299b545a401b4bcdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60902200d9a6574fe1313b51e270e568273fca41200e9dfbfdcd1f5529f6e95d3cda1e23b1eb303ab1be524048b23c435958590b29f2a9aab6083c0db788d55f
|
7
|
+
data.tar.gz: 405dce9b2d8b0621a66486d6840969cc635754bdbb40e0d1ec2b142cd48c11afa863f0e463afc47c3387f4ed264a607fec981d2df2fe0f15de9f37cc450445e0
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
Add here...
|
11
|
+
|
12
|
+
## v0.3.0 - 2024-07-10
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- Added `example_methods` as a configuration option to add your own example methods. (thanks to [@mskog](https://github.com/mskog) - first code contributor 🎉)
|
17
|
+
|
18
|
+
## v0.2.2 - 2024-06-23
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
- Suggest keeping `spec/**/*` in the `exclude` section of `.solargraph.yml` to avoid performance issues (see [commit](https://github.com/lekemula/solargraph-rspec/commit/3f0fc39e59e99bf9430e55c52ecb88650e49315e))
|
23
|
+
- Fix `let` definitions when do/end keywords overlap with body definition
|
24
|
+
```ruby
|
25
|
+
let(:todo) do # "do" keyword overlap
|
26
|
+
{
|
27
|
+
'todo' => 'end' # "end" keyword overlap
|
28
|
+
}
|
29
|
+
end
|
30
|
+
```
|
31
|
+
- Error handling in SpecWalker::FakeLetMethod
|
10
32
|
|
11
33
|
## [0.2.1] - 2024-06-09
|
12
34
|
|
data/README.md
CHANGED
@@ -34,14 +34,19 @@ Or add it to your Gemfile:
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
group :development do
|
37
|
-
gem 'solargraph'
|
38
|
-
gem 'solargraph-rspec'
|
37
|
+
gem 'solargraph', require: false
|
38
|
+
gem 'solargraph-rspec', require: false
|
39
39
|
end
|
40
40
|
```
|
41
41
|
|
42
42
|
If you add them to your Gemfile, you'll have to tell your IDE plugin to use bundler to load the right version of solargraph.
|
43
43
|
|
44
|
-
Add `solargraph-rspec` to your `.solargraph.yml`
|
44
|
+
Add `solargraph-rspec` to your `.solargraph.yml` as a plugin.
|
45
|
+
|
46
|
+
> [!CAUTION]
|
47
|
+
> To avoid **performance issues**, please keep the `spec/**/*` directory in **exclude** list in the Solargraph configuration.
|
48
|
+
> That does not actually *exclude* the specs, but rather avoids pre-indexing the specs when Solargraph boots up, and only parses
|
49
|
+
> the specs on demand when opened in the editor, which is what we usually want.
|
45
50
|
|
46
51
|
(if you don't have a `.solargraph.yml` in your project root, you can run `solargraph config` to add one)
|
47
52
|
|
@@ -50,7 +55,7 @@ Add `solargraph-rspec` to your `.solargraph.yml` and remove the `spec` directory
|
|
50
55
|
include:
|
51
56
|
- "**/*.rb"
|
52
57
|
exclude:
|
53
|
-
|
58
|
+
+- spec/**/*
|
54
59
|
- test/**/*
|
55
60
|
- vendor/**/*
|
56
61
|
- ".bundle/**/*"
|
@@ -75,6 +80,19 @@ rspec:
|
|
75
80
|
- let_it_be
|
76
81
|
```
|
77
82
|
|
83
|
+
If you have your own custom `example`-like methods like `it`, you can add them to your `.solargraph.yml` file like this:
|
84
|
+
|
85
|
+
```yaml
|
86
|
+
# .solargraph.yml
|
87
|
+
# ...
|
88
|
+
rspec:
|
89
|
+
example_methods:
|
90
|
+
- my_it
|
91
|
+
```
|
92
|
+
|
93
|
+
This is useful if you use gems like [rspec-given](https://github.com/rspec-given/rspec-given) which introduces its own `let` and `example` methods.
|
94
|
+
|
95
|
+
|
78
96
|
### Gem completions
|
79
97
|
|
80
98
|
Solargraph utilizes the YARD documentation to provide code completion. If you want to have completion for gems in your project, you can generate YARD documentation for them ([Read more](https://solargraph.org/guides/yard)).
|
@@ -20,6 +20,11 @@ module Solargraph
|
|
20
20
|
(Rspec::LET_METHODS + additional_let_methods).map(&:to_sym)
|
21
21
|
end
|
22
22
|
|
23
|
+
# @return [Array<Symbol>]
|
24
|
+
def example_methods
|
25
|
+
(Rspec::EXAMPLE_METHODS + additional_example_methods).map(&:to_sym)
|
26
|
+
end
|
27
|
+
|
23
28
|
private
|
24
29
|
|
25
30
|
# @return [Hash]
|
@@ -32,6 +37,11 @@ module Solargraph
|
|
32
37
|
(rspec_raw_data['let_methods'] || []).map(&:to_sym)
|
33
38
|
end
|
34
39
|
|
40
|
+
# @return [Array<Symbol>]
|
41
|
+
def additional_example_methods
|
42
|
+
(rspec_raw_data['example_methods'] || []).map(&:to_sym)
|
43
|
+
end
|
44
|
+
|
35
45
|
# @return [Hash]
|
36
46
|
def raw_data
|
37
47
|
@solargraph_config.raw_data
|
@@ -4,18 +4,18 @@ module Solargraph
|
|
4
4
|
module Rspec
|
5
5
|
class SpecWalker
|
6
6
|
class FakeLetMethod
|
7
|
-
|
8
|
-
|
9
|
-
/{(.*)}/m
|
10
|
-
)
|
7
|
+
MATCH_DO_END = /.*? do(.*)end/m.freeze
|
8
|
+
MATCH_CURLY = /{(.*)}/m.freeze
|
11
9
|
|
12
10
|
# @param block_ast [RubyVM::AbstractSyntaxTree::Node]
|
13
|
-
# @return [RubyVM::AbstractSyntaxTree::Node]
|
11
|
+
# @return [RubyVM::AbstractSyntaxTree::Node, nil]
|
14
12
|
def self.transform_block(block_ast, code, method_name = nil)
|
15
13
|
method_name ||= NodeTypes.let_method_name(block_ast)
|
16
14
|
block_body = block_ast.children[1]
|
17
|
-
|
18
|
-
|
15
|
+
let_definition_code = code.lines[block_body.first_lineno - 1..block_body.last_lineno - 1].join
|
16
|
+
match_do_end = let_definition_code.match(MATCH_DO_END)&.captures&.first || ''
|
17
|
+
match_curly = let_definition_code.match(MATCH_CURLY)&.captures&.first || ''
|
18
|
+
method_body = [match_do_end, match_curly].max_by(&:length).strip
|
19
19
|
|
20
20
|
ast = RubyVM::AbstractSyntaxTree.parse <<~RUBY
|
21
21
|
def #{method_name}
|
@@ -24,8 +24,11 @@ module Solargraph
|
|
24
24
|
RUBY
|
25
25
|
|
26
26
|
ast.children[2]
|
27
|
-
rescue SyntaxError
|
28
|
-
|
27
|
+
rescue SyntaxError => e
|
28
|
+
Solargraph.logger.warn "[RSpec] Failed to build fake let method: #{e.message}, \
|
29
|
+
\n\nlet_definition_code: \n```\n#{let_definition_code}\n```, \
|
30
|
+
\n\nmethod_body: \n```\n#{method_body}\n```, \
|
31
|
+
\nast: #{block_ast.inspect}"
|
29
32
|
ensure
|
30
33
|
nil
|
31
34
|
end
|
@@ -25,9 +25,10 @@ module Solargraph
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# @param ast [RubyVM::AbstractSyntaxTree::Node]
|
28
|
+
# @param config [Config]
|
28
29
|
# @return [Boolean]
|
29
|
-
def self.a_example_block?(block_ast)
|
30
|
-
|
30
|
+
def self.a_example_block?(block_ast, config)
|
31
|
+
config.example_methods.map(&:to_s).include?(method_with_block_name(block_ast))
|
31
32
|
end
|
32
33
|
|
33
34
|
# @param ast [RubyVM::AbstractSyntaxTree::Node]
|
@@ -138,7 +138,7 @@ module Solargraph
|
|
138
138
|
end
|
139
139
|
|
140
140
|
walker.on :ITER do |block_ast|
|
141
|
-
next unless NodeTypes.a_example_block?(block_ast)
|
141
|
+
next unless NodeTypes.a_example_block?(block_ast, config)
|
142
142
|
|
143
143
|
@handlers[:on_example_block].each do |handler|
|
144
144
|
handler.call(PinFactory.build_location_range(block_ast))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lekë Mula
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solargraph
|