solargraph-rspec 0.5.3 → 0.5.5
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/.rspec +1 -0
- data/.rubocop.yml +6 -4
- data/.solargraph.yml.example +26 -0
- data/Appraisals +7 -0
- data/CHANGELOG.md +7 -1
- data/README.md +19 -13
- data/gemfiles/default.gemfile +10 -9
- data/gemfiles/default.gemfile.lock +121 -99
- data/lib/solargraph/rspec/config.rb +6 -2
- data/lib/solargraph/rspec/convention.rb +4 -4
- data/lib/solargraph/rspec/correctors/base.rb +35 -1
- data/lib/solargraph/rspec/correctors/context_block_namespace_corrector.rb +1 -0
- data/lib/solargraph/rspec/correctors/described_class_corrector.rb +1 -1
- data/lib/solargraph/rspec/correctors/example_and_hook_blocks_binding_corrector.rb +1 -0
- data/lib/solargraph/rspec/correctors/let_methods_corrector.rb +2 -1
- data/lib/solargraph/rspec/correctors/subject_method_corrector.rb +2 -2
- data/lib/solargraph/rspec/{test_helpers.rb → gems.rb} +9 -10
- data/lib/solargraph/rspec/pin_factory.rb +33 -6
- data/lib/solargraph/rspec/spec_walker/fake_let_method.rb +1 -5
- data/lib/solargraph/rspec/spec_walker/node_types.rb +9 -7
- data/lib/solargraph/rspec/spec_walker/rspec_context_namespace.rb +3 -1
- data/lib/solargraph/rspec/spec_walker.rb +2 -1
- data/lib/solargraph/rspec/version.rb +1 -1
- data/lib/solargraph/rspec/walker.rb +4 -0
- data/rbs_collection.yaml +20 -0
- data/release_gem.sh +210 -0
- metadata +6 -3
@@ -12,7 +12,7 @@ module Solargraph
|
|
12
12
|
# @return [Solargraph::Rspec::SpecWalker]
|
13
13
|
attr_reader :rspec_walker
|
14
14
|
|
15
|
-
# @return [Array<Solargraph::Pin::Base]
|
15
|
+
# @return [Array<Solargraph::Pin::Base>]
|
16
16
|
attr_reader :added_pins
|
17
17
|
|
18
18
|
# @param namespace_pins [Array<Solargraph::Pin::Base>]
|
@@ -68,11 +68,45 @@ module Solargraph
|
|
68
68
|
# @param pin [Solargraph::Pin::Base]
|
69
69
|
# @param new_closure [Solargraph::Pin::Closure]
|
70
70
|
def override_closure(pin, new_closure)
|
71
|
+
# HACK: We should only rely on public API, and avoid instance_variable_get/set.
|
71
72
|
pin.instance_variable_set('@closure', new_closure)
|
72
73
|
pin.reset_generated!
|
73
74
|
|
74
75
|
pin.remove_instance_variable(:@path) if pin.instance_variables.include? :@path
|
75
76
|
end
|
77
|
+
|
78
|
+
# Given the following code, Solargraph::Parser.node_range returns the following range for block ast:
|
79
|
+
#
|
80
|
+
# ```ruby
|
81
|
+
# some_method_with_block do
|
82
|
+
# ^ - block start
|
83
|
+
# end
|
84
|
+
# ^ - block end
|
85
|
+
# ```
|
86
|
+
#
|
87
|
+
# Instead we want the range to be:
|
88
|
+
#
|
89
|
+
# ```ruby
|
90
|
+
# some_method_with_block do
|
91
|
+
# ^ - block start
|
92
|
+
# end
|
93
|
+
# ^ - block end
|
94
|
+
# ```
|
95
|
+
#
|
96
|
+
# @param closure [Solargraph::Pin::Closure]
|
97
|
+
# @param source_map [Solargraph::SourceMap]
|
98
|
+
# @return [void]
|
99
|
+
def override_block_location(closure, source_map)
|
100
|
+
range = closure.location.range
|
101
|
+
block_ast = source_map.source.node_at(range.ending.line, range.ending.column)
|
102
|
+
new_location = PinFactory.build_location(
|
103
|
+
PinFactory.build_location_range(block_ast),
|
104
|
+
closure.location.filename
|
105
|
+
)
|
106
|
+
|
107
|
+
# HACK: We should only rely on public API, and avoid instance_variable_get/set.
|
108
|
+
closure.instance_variable_set('@location', new_location)
|
109
|
+
end
|
76
110
|
end
|
77
111
|
end
|
78
112
|
end
|
@@ -26,6 +26,7 @@ module Solargraph
|
|
26
26
|
)
|
27
27
|
|
28
28
|
override_closure(original_block_pin, namespace_pin)
|
29
|
+
override_block_location(original_block_pin, source_map)
|
29
30
|
|
30
31
|
# Include DSL methods in the example group block
|
31
32
|
# TODO: This does not work on solagraph! Class methods are not included from parent class.
|
@@ -7,7 +7,7 @@ module Solargraph
|
|
7
7
|
module Correctors
|
8
8
|
# Defines `described_class` method in the example group block
|
9
9
|
class DescribedClassCorrector < Base
|
10
|
-
# @param
|
10
|
+
# @param _source_map [Solargraph::SourceMap]
|
11
11
|
# @return [void]
|
12
12
|
def correct(_source_map)
|
13
13
|
rspec_walker.on_described_class do |described_class_name, location_range|
|
@@ -7,7 +7,7 @@ module Solargraph
|
|
7
7
|
module Correctors
|
8
8
|
# Defines let-like methods in the example group block
|
9
9
|
class LetMethodsCorrector < Base
|
10
|
-
# @param
|
10
|
+
# @param _source_map [Solargraph::SourceMap]
|
11
11
|
# @return [void]
|
12
12
|
def correct(_source_map)
|
13
13
|
rspec_walker.on_let_method do |let_name, location_range, fake_method_ast|
|
@@ -23,6 +23,7 @@ module Solargraph
|
|
23
23
|
|
24
24
|
# @param namespace [Pin::Namespace]
|
25
25
|
# @param method_name [String]
|
26
|
+
# @param location_range [Range]
|
26
27
|
# @param node [::Parser::AST::Node, nil]
|
27
28
|
# @param types [Array<String>, nil]
|
28
29
|
# @return [Pin::Method, nil]
|
@@ -7,7 +7,7 @@ module Solargraph
|
|
7
7
|
module Correctors
|
8
8
|
# Defines let-like methods in the example group block
|
9
9
|
class SubjectMethodCorrector < LetMethodsCorrector
|
10
|
-
# @param
|
10
|
+
# @param _source_map [Solargraph::SourceMap]
|
11
11
|
# @return [void]
|
12
12
|
def correct(_source_map)
|
13
13
|
rspec_walker.on_subject do |subject_name, location_range, fake_method_ast|
|
@@ -75,7 +75,7 @@ module Solargraph
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# @param namespace_pin [Pin::Namespace]
|
78
|
-
# @param method_name [:is_expected, :should, :should_not]
|
78
|
+
# @param method_name [:is_expected, :should, :should_not] # rubocop:disable YARD/TagTypeSyntax
|
79
79
|
# @param location [Solargraph::Location]
|
80
80
|
# @return [Pin::Method]
|
81
81
|
def one_liner_expectation_pin(namespace_pin, method_name, location)
|
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
module Solargraph
|
4
4
|
module Rspec
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
class Gems
|
6
|
+
# rubocop:disable YARD/MeaninglessTag
|
7
|
+
# @param required_gems [Array<String>]
|
8
|
+
# @param helper_modules [Array<String>]
|
9
|
+
# rubocop:enable YARD/MeaninglessTag
|
10
|
+
GemHelpers = Struct.new(:required_gems, :helper_modules, keyword_init: true)
|
12
11
|
|
13
12
|
class << self
|
14
|
-
# @return [String]
|
13
|
+
# @return [Array<String>]
|
15
14
|
def gem_names
|
16
15
|
GEM_HELPERS.flat_map(&:required_gems)
|
17
16
|
end
|
@@ -37,7 +36,7 @@ module Solargraph
|
|
37
36
|
|
38
37
|
GEM_HELPERS = [
|
39
38
|
GemHelpers.new(
|
40
|
-
required_gems: %w[rspec],
|
39
|
+
required_gems: %w[rspec rspec-expectations rspec-core],
|
41
40
|
helper_modules: %w[RSpec::Matchers]
|
42
41
|
),
|
43
42
|
# https://github.com/rspec/rspec-mocks
|
@@ -48,7 +47,7 @@ module Solargraph
|
|
48
47
|
# @see https://github.com/rspec/rspec-rails#what-tests-should-i-write
|
49
48
|
# @see https://github.com/rspec/rspec-rails#helpful-rails-matchers
|
50
49
|
GemHelpers.new(
|
51
|
-
required_gems: %w[rspec-rails actionmailer activesupport
|
50
|
+
required_gems: %w[rspec-rails actionmailer activesupport actionpack],
|
52
51
|
helper_modules: [
|
53
52
|
'RSpec::Rails::Matchers',
|
54
53
|
'ActionController::TestCase::Behavior',
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Credits: This file
|
3
|
+
# Credits: This file was originally copied and adapted from the solargraph-rails gem.
|
4
4
|
|
5
5
|
module Solargraph
|
6
6
|
module Rspec
|
@@ -8,11 +8,12 @@ module Solargraph
|
|
8
8
|
module PinFactory
|
9
9
|
# @param namespace [Solargraph::Pin::Namespace]
|
10
10
|
# @param name [String]
|
11
|
-
# @param types [Array<String
|
12
|
-
# @param
|
11
|
+
# @param types [Array<String>, nil]
|
12
|
+
# @param [Parser::AST::Node, nil] node
|
13
|
+
# @param location [Solargraph::Location, nil]
|
13
14
|
# @param comments [Array<String>]
|
14
15
|
# @param attribute [Boolean]
|
15
|
-
# @param scope [:instance, :class]
|
16
|
+
# @param scope [:instance, :class] # rubocop:disable YARD/TagTypeSyntax
|
16
17
|
# @return [Solargraph::Pin::Method]
|
17
18
|
def self.build_public_method(
|
18
19
|
namespace,
|
@@ -42,7 +43,7 @@ module Solargraph
|
|
42
43
|
end
|
43
44
|
|
44
45
|
# @param namespace [Solargraph::Pin::Namespace]
|
45
|
-
# @param
|
46
|
+
# @param module_name [String]
|
46
47
|
# @param location [Solargraph::Location]
|
47
48
|
# @return [Solargraph::Pin::Reference::Include]
|
48
49
|
def self.build_module_include(namespace, module_name, location)
|
@@ -74,10 +75,36 @@ module Solargraph
|
|
74
75
|
)
|
75
76
|
end
|
76
77
|
|
78
|
+
# Given the following code, Solargraph::Parser.node_range returns the following range for block ast:
|
79
|
+
#
|
80
|
+
# some_method_with_block do
|
81
|
+
# ^ - block start
|
82
|
+
# end
|
83
|
+
# ^ - block end
|
84
|
+
#
|
85
|
+
# Instead we want the range to be:
|
86
|
+
#
|
87
|
+
# some_method_with_block do
|
88
|
+
# ^ - block start
|
89
|
+
# end
|
90
|
+
# ^ - block end
|
91
|
+
#
|
77
92
|
# @param ast [::Parser::AST::Node]
|
78
93
|
# @return [Solargraph::Range]
|
79
94
|
def self.build_location_range(ast)
|
80
|
-
|
95
|
+
if ast.type == :block
|
96
|
+
method_range = Solargraph::Parser.node_range(ast.children[0])
|
97
|
+
full_block_range = Solargraph::Parser.node_range(ast)
|
98
|
+
|
99
|
+
Solargraph::Range.from_to(
|
100
|
+
method_range.ending.line,
|
101
|
+
method_range.ending.character,
|
102
|
+
full_block_range.ending.line,
|
103
|
+
full_block_range.ending.character
|
104
|
+
)
|
105
|
+
else
|
106
|
+
Solargraph::Parser.node_range(ast)
|
107
|
+
end
|
81
108
|
end
|
82
109
|
|
83
110
|
# @param location_range [Solargraph::Range]
|
@@ -11,6 +11,7 @@ module Solargraph
|
|
11
11
|
# Transforms let block to method ast node
|
12
12
|
# @param block_ast [::Parser::AST::Node]
|
13
13
|
# @return [::Parser::AST::Node, nil]
|
14
|
+
# @param [String, nil] method_name
|
14
15
|
def transform_block(block_ast, method_name = nil)
|
15
16
|
method_name ||= NodeTypes.let_method_name(block_ast)
|
16
17
|
|
@@ -22,11 +23,6 @@ module Solargraph
|
|
22
23
|
block_ast.children[2]
|
23
24
|
]
|
24
25
|
)
|
25
|
-
rescue SyntaxError => e
|
26
|
-
Solargraph.logger.warn "[RSpec] Failed to build fake let method: #{e.message}, \
|
27
|
-
\n\nlet_definition_code: \n```\n#{let_definition_code}\n```, \
|
28
|
-
\n\nmethod_body: \n```\n#{method_body}\n```, \
|
29
|
-
\nast: #{block_ast.inspect}"
|
30
26
|
end
|
31
27
|
end
|
32
28
|
end
|
@@ -10,38 +10,40 @@ module Solargraph
|
|
10
10
|
ast.is_a?(::Parser::AST::Node) && ast.type == :block
|
11
11
|
end
|
12
12
|
|
13
|
-
# @param
|
13
|
+
# @param block_ast [::Parser::AST::Node]
|
14
14
|
# @return [Boolean]
|
15
15
|
def self.a_context_block?(block_ast)
|
16
16
|
Solargraph::Rspec::CONTEXT_METHODS.include?(method_with_block_name(block_ast))
|
17
17
|
end
|
18
18
|
|
19
|
-
# @param
|
19
|
+
# @param block_ast [::Parser::AST::Node]
|
20
20
|
# @return [Boolean]
|
21
21
|
def self.a_subject_block?(block_ast)
|
22
22
|
Solargraph::Rspec::SUBJECT_METHODS.include?(method_with_block_name(block_ast))
|
23
23
|
end
|
24
24
|
|
25
|
-
# @param
|
25
|
+
# @param block_ast [::Parser::AST::Node]
|
26
26
|
# @param config [Config]
|
27
27
|
# @return [Boolean]
|
28
28
|
def self.a_example_block?(block_ast, config)
|
29
29
|
config.example_methods.map(&:to_s).include?(method_with_block_name(block_ast))
|
30
30
|
end
|
31
31
|
|
32
|
-
# @param
|
32
|
+
# @param block_ast [::Parser::AST::Node]
|
33
33
|
# @param config [Config]
|
34
34
|
# @return [Boolean]
|
35
35
|
def self.a_let_block?(block_ast, config)
|
36
36
|
config.let_methods.map(&:to_s).include?(method_with_block_name(block_ast))
|
37
37
|
end
|
38
38
|
|
39
|
-
# @param
|
39
|
+
# @param block_ast [::Parser::AST::Node]
|
40
40
|
# @return [Boolean]
|
41
41
|
def self.a_hook_block?(block_ast)
|
42
42
|
Solargraph::Rspec::HOOK_METHODS.include?(method_with_block_name(block_ast))
|
43
43
|
end
|
44
44
|
|
45
|
+
# @param [::Parser::AST::Node] ast
|
46
|
+
# @return [Boolean]
|
45
47
|
def self.a_constant?(ast)
|
46
48
|
ast.type == :const
|
47
49
|
end
|
@@ -56,7 +58,7 @@ module Solargraph
|
|
56
58
|
end
|
57
59
|
|
58
60
|
# @param block_ast [::Parser::AST::Node]
|
59
|
-
# @return [::Parser::AST::Node]
|
61
|
+
# @return [::Parser::AST::Node, nil]
|
60
62
|
def self.context_description_node(block_ast)
|
61
63
|
return nil unless a_context_block?(block_ast)
|
62
64
|
|
@@ -64,7 +66,7 @@ module Solargraph
|
|
64
66
|
end
|
65
67
|
|
66
68
|
# @param block_ast [::Parser::AST::Node]
|
67
|
-
# @return [String]
|
69
|
+
# @return [String, nil]
|
68
70
|
def self.let_method_name(block_ast)
|
69
71
|
return nil unless a_block?(block_ast)
|
70
72
|
|
@@ -11,6 +11,8 @@ module Solargraph
|
|
11
11
|
return unless block_ast.is_a?(::Parser::AST::Node)
|
12
12
|
|
13
13
|
ast = NodeTypes.context_description_node(block_ast)
|
14
|
+
return unless ast
|
15
|
+
|
14
16
|
if ast.type == :str
|
15
17
|
string_to_const_name(ast)
|
16
18
|
elsif NodeTypes.a_constant?(ast)
|
@@ -24,7 +26,7 @@ module Solargraph
|
|
24
26
|
private
|
25
27
|
|
26
28
|
# @see https://github.com/rspec/rspec-core/blob/1eeadce5aa7137ead054783c31ff35cbfe9d07cc/lib/rspec/core/example_group.rb#L862
|
27
|
-
# @param
|
29
|
+
# @param string_ast [Parser::AST::Node]
|
28
30
|
# @return [String]
|
29
31
|
def string_to_const_name(string_ast)
|
30
32
|
return unless string_ast.type == :str
|
@@ -188,8 +188,9 @@ module Solargraph
|
|
188
188
|
end
|
189
189
|
|
190
190
|
# Find all describe/context blocks in the AST.
|
191
|
-
# @param ast [Parser::AST::Node]
|
192
191
|
# @yield [String, Parser::AST::Node]
|
192
|
+
# @param [Parser::AST::Node] ast
|
193
|
+
# @param [String] root_namespace
|
193
194
|
def each_context_block(ast, root_namespace = Rspec::ROOT_NAMESPACE, &block)
|
194
195
|
each_block(ast, root_namespace) do |block_ast, parent_namespace|
|
195
196
|
is_a_context = NodeTypes.a_context_block?(block_ast)
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
#
|
4
|
+
# Credits: This file was originally copied and adapted from the solargraph-rails gem
|
5
|
+
|
3
6
|
module Solargraph
|
4
7
|
module Rspec
|
5
8
|
class Walker
|
@@ -51,6 +54,7 @@ module Solargraph
|
|
51
54
|
end
|
52
55
|
|
53
56
|
# @param children [Array<::Parser::AST::Node>]
|
57
|
+
# @param args [Array]
|
54
58
|
def match_children(children, args = @args)
|
55
59
|
args.each_with_index.all? do |arg, i|
|
56
60
|
if arg == :any
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
# Download sources
|
3
|
+
sources:
|
4
|
+
- type: git
|
5
|
+
name: ruby/gem_rbs_collection
|
6
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
7
|
+
revision: main
|
8
|
+
repo_dir: gems
|
9
|
+
|
10
|
+
# You can specify local directories as sources also.
|
11
|
+
# - type: local
|
12
|
+
# path: path/to/your/local/repository
|
13
|
+
|
14
|
+
# A directory to install the downloaded RBSs
|
15
|
+
path: .gem_rbs_collection
|
16
|
+
|
17
|
+
# gems:
|
18
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
19
|
+
# - name: GEM_NAME
|
20
|
+
# ignore: true
|
data/release_gem.sh
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Credits: This file was originally copied and adapted from the log_bench gem.
|
3
|
+
# https://raw.githubusercontent.com/silva96/log_bench/refs/heads/main/release_gem.sh
|
4
|
+
set -euo pipefail
|
5
|
+
|
6
|
+
############################################
|
7
|
+
# Config — tweak if your gem/repo differs
|
8
|
+
############################################
|
9
|
+
GEM_NAME="solargraph-rspec"
|
10
|
+
LIB_DIR="lib/solargraph/rspec"
|
11
|
+
DEFAULT_BRANCH="main"
|
12
|
+
VERSION_FILE="${LIB_DIR}/version.rb"
|
13
|
+
GEMSPEC_FILE="${GEM_NAME}.gemspec"
|
14
|
+
TAG_PREFIX="v"
|
15
|
+
|
16
|
+
# Bump mode: patch | minor | major (default patch)
|
17
|
+
BUMP="${BUMP:-patch}"
|
18
|
+
|
19
|
+
############################################
|
20
|
+
# Arg parsing (optional)
|
21
|
+
############################################
|
22
|
+
while [[ $# -gt 0 ]]; do
|
23
|
+
case "$1" in
|
24
|
+
--bump) BUMP="${2:-patch}"; shift 2 ;;
|
25
|
+
--bump=*) BUMP="${1#*=}"; shift 1 ;;
|
26
|
+
-h|--help)
|
27
|
+
cat <<EOF
|
28
|
+
Usage: $0 [--bump patch|minor|major]
|
29
|
+
Defaults to --bump patch (e.g., 0.2.6 -> 0.2.7).
|
30
|
+
EOF
|
31
|
+
exit 0 ;;
|
32
|
+
*) echo "Unknown arg: $1" >&2; exit 1 ;;
|
33
|
+
esac
|
34
|
+
done
|
35
|
+
|
36
|
+
case "$BUMP" in
|
37
|
+
patch|minor|major) : ;;
|
38
|
+
*) echo "Invalid --bump: $BUMP (use patch|minor|major)"; exit 1 ;;
|
39
|
+
esac
|
40
|
+
|
41
|
+
############################################
|
42
|
+
# Pretty logging
|
43
|
+
############################################
|
44
|
+
if command -v tput >/dev/null 2>&1 && [ -n "${TERM:-}" ]; then
|
45
|
+
BOLD=$(tput bold) || BOLD=""
|
46
|
+
RESET=$(tput sgr0) || RESET=""
|
47
|
+
GREEN=$(tput setaf 2) || GREEN=""
|
48
|
+
YELLOW=$(tput setaf 3) || YELLOW=""
|
49
|
+
RED=$(tput setaf 1) || RED=""
|
50
|
+
BLUE=$(tput setaf 4) || BLUE=""
|
51
|
+
else
|
52
|
+
BOLD=""; RESET=""; GREEN=""; YELLOW=""; RED=""; BLUE=""
|
53
|
+
fi
|
54
|
+
|
55
|
+
log() { printf "%b\n" "${BLUE}▸${RESET} $*"; }
|
56
|
+
success() { printf "%b\n" "${GREEN}✔${RESET} $*"; }
|
57
|
+
warn() { printf "%b\n" "${YELLOW}⚠${RESET} $*"; }
|
58
|
+
error() { printf "%b\n" "${RED}✖${RESET} $*"; }
|
59
|
+
die() { error "$*"; exit 1; }
|
60
|
+
|
61
|
+
############################################
|
62
|
+
# Helpers
|
63
|
+
############################################
|
64
|
+
require_cmd() { command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"; }
|
65
|
+
|
66
|
+
current_version() {
|
67
|
+
# Extract the first X.Y.Z from the VERSION file
|
68
|
+
grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' "$VERSION_FILE" | head -n1
|
69
|
+
}
|
70
|
+
|
71
|
+
validate_semver() { [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; }
|
72
|
+
|
73
|
+
bump_version() {
|
74
|
+
local mode="$1" ver="$2"
|
75
|
+
IFS='.' read -r MA MI PA <<<"$ver"
|
76
|
+
case "$mode" in
|
77
|
+
patch) echo "${MA}.${MI}.$((PA+1))" ;;
|
78
|
+
minor) echo "${MA}.$((MI+1)).0" ;;
|
79
|
+
major) echo "$((MA+1)).0.0" ;;
|
80
|
+
esac
|
81
|
+
}
|
82
|
+
|
83
|
+
update_version_file() {
|
84
|
+
local new="$1"
|
85
|
+
# Robust sed (preserves indentation, quote style, optional .freeze)
|
86
|
+
sed -E "s/^([[:space:]]*)VERSION[[:space:]]*=[[:space:]]*(['\"])[0-9]+\.[0-9]+\.[0-9]+(['\"])(\.freeze)?/\1VERSION = \2${new}\3\4/" \
|
87
|
+
"$VERSION_FILE" > "${VERSION_FILE}.tmp"
|
88
|
+
mv "${VERSION_FILE}.tmp" "$VERSION_FILE"
|
89
|
+
}
|
90
|
+
|
91
|
+
ensure_clean_worktree() {
|
92
|
+
if [ -n "$(git status --porcelain)" ]; then
|
93
|
+
warn "Your working tree has uncommitted changes:"
|
94
|
+
git status --short
|
95
|
+
read -rp "$(printf '%b' "${YELLOW}Proceed anyway? [y/N] ${RESET}")" ans
|
96
|
+
[[ "${ans:-}" =~ ^[Yy]$ ]] || die "Aborted due to dirty working tree."
|
97
|
+
fi
|
98
|
+
}
|
99
|
+
|
100
|
+
############################################
|
101
|
+
# Checks
|
102
|
+
############################################
|
103
|
+
require_cmd git
|
104
|
+
require_cmd bundle
|
105
|
+
require_cmd gem
|
106
|
+
require_cmd sed
|
107
|
+
|
108
|
+
if ! command -v gh >/dev/null 2>&1; then
|
109
|
+
warn "GitHub CLI (gh) not found. GitHub release creation will be skipped."
|
110
|
+
GH_AVAILABLE="false"
|
111
|
+
else
|
112
|
+
GH_AVAILABLE="true"
|
113
|
+
fi
|
114
|
+
|
115
|
+
[ -f "$VERSION_FILE" ] || die "Version file not found: $VERSION_FILE"
|
116
|
+
[ -f "$GEMSPEC_FILE" ] || die "Gemspec not found: $GEMSPEC_FILE"
|
117
|
+
|
118
|
+
############################################
|
119
|
+
# Start
|
120
|
+
############################################
|
121
|
+
log "${BOLD}Publishing ${GEM_NAME}${RESET}"
|
122
|
+
ensure_clean_worktree
|
123
|
+
|
124
|
+
log "Pulling latest from origin/${DEFAULT_BRANCH}…"
|
125
|
+
git checkout "$DEFAULT_BRANCH" >/dev/null 2>&1 || true
|
126
|
+
git pull origin "$DEFAULT_BRANCH"
|
127
|
+
success "Up to date."
|
128
|
+
|
129
|
+
CURR_VER="$(current_version)"
|
130
|
+
[ -n "$CURR_VER" ] || die "Could not determine current version from $VERSION_FILE"
|
131
|
+
|
132
|
+
log "Current version detected in ${VERSION_FILE}: ${BOLD}${CURR_VER}${RESET}"
|
133
|
+
PROPOSED="$(bump_version "$BUMP" "$CURR_VER")"
|
134
|
+
read -rp "$(printf '%b' "${BLUE}Proposed next ${BOLD}${BUMP}${RESET}${BLUE} version is ${BOLD}${PROPOSED}${RESET}${BLUE}. Press Enter to accept or type a different semver (X.Y.Z): ${RESET}")" NEW_VER
|
135
|
+
NEW_VER="${NEW_VER:-$PROPOSED}"
|
136
|
+
validate_semver "$NEW_VER" || die "Invalid semver: $NEW_VER"
|
137
|
+
|
138
|
+
TAG="${TAG_PREFIX}${NEW_VER}"
|
139
|
+
|
140
|
+
# Guard against existing tag
|
141
|
+
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
|
142
|
+
die "Tag ${TAG} already exists."
|
143
|
+
fi
|
144
|
+
|
145
|
+
log "Updating version file to ${BOLD}${NEW_VER}${RESET}…"
|
146
|
+
before_contents="$(cat "$VERSION_FILE")"
|
147
|
+
update_version_file "$NEW_VER"
|
148
|
+
after_contents="$(cat "$VERSION_FILE")"
|
149
|
+
if [ "$before_contents" = "$after_contents" ]; then
|
150
|
+
AFTER_VER="$(current_version || true)"
|
151
|
+
if [ "$AFTER_VER" = "$NEW_VER" ]; then
|
152
|
+
warn "Version file already at ${NEW_VER}; nothing to change."
|
153
|
+
else
|
154
|
+
die "Failed to update ${VERSION_FILE}. Ensure it has a line like:
|
155
|
+
VERSION = \"${CURR_VER}\"
|
156
|
+
(or with single quotes / optional .freeze)."
|
157
|
+
fi
|
158
|
+
else
|
159
|
+
success "Updated ${VERSION_FILE}."
|
160
|
+
fi
|
161
|
+
|
162
|
+
log "Installing gems (bundle install)…"
|
163
|
+
bundle install
|
164
|
+
success "Dependencies installed."
|
165
|
+
|
166
|
+
log "Committing version bump (including Gemfile.lock if changed)…"
|
167
|
+
FILES_TO_COMMIT=()
|
168
|
+
if ! git diff --quiet -- "$VERSION_FILE"; then
|
169
|
+
FILES_TO_COMMIT+=("$VERSION_FILE")
|
170
|
+
fi
|
171
|
+
if [ -f "Gemfile.lock" ] && ! git diff --quiet -- "Gemfile.lock"; then
|
172
|
+
FILES_TO_COMMIT+=("Gemfile.lock")
|
173
|
+
fi
|
174
|
+
|
175
|
+
if [ "${#FILES_TO_COMMIT[@]}" -gt 0 ]; then
|
176
|
+
git add "${FILES_TO_COMMIT[@]}"
|
177
|
+
git commit -m "Bump version to ${NEW_VER}"
|
178
|
+
success "Committed: ${FILES_TO_COMMIT[*]}"
|
179
|
+
else
|
180
|
+
warn "No changes to commit (version file and Gemfile.lock unchanged)."
|
181
|
+
fi
|
182
|
+
|
183
|
+
log "Creating tag ${BOLD}${TAG}${RESET}…"
|
184
|
+
git tag "${TAG}" -m "Release version ${NEW_VER}"
|
185
|
+
success "Tag created."
|
186
|
+
|
187
|
+
log "Pushing branch & tag to origin…"
|
188
|
+
git push origin "$DEFAULT_BRANCH"
|
189
|
+
git push origin "${TAG}"
|
190
|
+
success "Pushed."
|
191
|
+
|
192
|
+
if [ "$GH_AVAILABLE" = "true" ]; then
|
193
|
+
log "Creating GitHub release ${BOLD}${TAG}${RESET} with auto-generated notes…"
|
194
|
+
gh release create "${TAG}" --title "Release version ${NEW_VER}" --generate-notes || warn "Failed to create GitHub release via gh."
|
195
|
+
success "GitHub release created."
|
196
|
+
else
|
197
|
+
warn "Skipping GitHub release creation (gh not installed)."
|
198
|
+
fi
|
199
|
+
|
200
|
+
log "Building gem…"
|
201
|
+
gem build "$GEMSPEC_FILE"
|
202
|
+
GEM_FILE="${GEM_NAME}-${NEW_VER}.gem"
|
203
|
+
[ -f "$GEM_FILE" ] || die "Gem file not found after build: $GEM_FILE"
|
204
|
+
success "Built ${GEM_FILE}."
|
205
|
+
|
206
|
+
log "Pushing gem to RubyGems…"
|
207
|
+
gem push "$GEM_FILE"
|
208
|
+
success "Gem pushed to RubyGems."
|
209
|
+
|
210
|
+
success "${BOLD}${GEM_NAME} ${NEW_VER}${RESET} has been published! 🎉"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lekë Mula
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-10-05 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: solargraph
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".rspec"
|
35
35
|
- ".rubocop.yml"
|
36
|
+
- ".solargraph.yml.example"
|
36
37
|
- Appraisals
|
37
38
|
- CHANGELOG.md
|
38
39
|
- CODE_OF_CONDUCT.md
|
@@ -54,16 +55,18 @@ files:
|
|
54
55
|
- lib/solargraph/rspec/correctors/example_and_hook_blocks_binding_corrector.rb
|
55
56
|
- lib/solargraph/rspec/correctors/let_methods_corrector.rb
|
56
57
|
- lib/solargraph/rspec/correctors/subject_method_corrector.rb
|
58
|
+
- lib/solargraph/rspec/gems.rb
|
57
59
|
- lib/solargraph/rspec/pin_factory.rb
|
58
60
|
- lib/solargraph/rspec/spec_walker.rb
|
59
61
|
- lib/solargraph/rspec/spec_walker/fake_let_method.rb
|
60
62
|
- lib/solargraph/rspec/spec_walker/full_constant_name.rb
|
61
63
|
- lib/solargraph/rspec/spec_walker/node_types.rb
|
62
64
|
- lib/solargraph/rspec/spec_walker/rspec_context_namespace.rb
|
63
|
-
- lib/solargraph/rspec/test_helpers.rb
|
64
65
|
- lib/solargraph/rspec/version.rb
|
65
66
|
- lib/solargraph/rspec/walker.rb
|
66
67
|
- lib/solargraph_rspec.rb
|
68
|
+
- rbs_collection.yaml
|
69
|
+
- release_gem.sh
|
67
70
|
- sig/solargraph/rspec.rbs
|
68
71
|
- solargraph-rspec.gemspec
|
69
72
|
licenses:
|