rspec-paramz 2.0.0 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad92978ad2f245bcae60978474d7ec8b6de9e20adb2090bc1572f0974cc8c5d8
4
- data.tar.gz: cad5699ce3a8290b5d7076abea8d5e3f70745b9606f54d909da777bee7155268
3
+ metadata.gz: b6ab7748da440263de4f4a668e3a9cb50546c78e59faf7f6c13b7b903d898887
4
+ data.tar.gz: 41f9aa35260d87b107ffc28a43e88d3a3078204d1d06e3d936be23e5db39586d
5
5
  SHA512:
6
- metadata.gz: 1741436d436b3b23bb739c3d95a794f0d2de2304505bbe3d6cc679c9346fdf21b4c847426d79eb9cdaf10fac9793da4b6a03459223f383a020f16b80134c2eb8
7
- data.tar.gz: a974dd00c973303da0f7bd7bed9e49b121190aa257da8381e530554e05d37dce45cd2ef76194d1a131e6ef0e961452275d4448d49035010ebc5d92365e3cdcfb
6
+ metadata.gz: 41f02f22fff92a028bfba776420243a20dc033564f4354e19eff49c216084b6e9fca15004758aef69b8d42fc2a1868defcbf7b962e4ec66dc37b60904df8616b
7
+ data.tar.gz: 8d175884a4d5d17f0c2e07b9f4c03561083e189e75f4478e1680168ed6e3cfb6d2840f5083b6a3ad24d1746ed83014ca6ce5cf619a8f0b9dff88c34c93e49dc9
@@ -13,7 +13,7 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby-version: ['3.1', '3.2', '3.3', '3.4', 'head']
16
+ ruby-version: ['3.3', '3.4', 'head']
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v4
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ mise.toml
data/.rubocop.yml CHANGED
@@ -4,4 +4,4 @@ inherit_gem:
4
4
  - "config/rspec.yml"
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 3.1
7
+ TargetRubyVersion: 3.3
data/Gemfile.lock CHANGED
@@ -1,47 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-paramz (1.2.0)
4
+ rspec-paramz (3.0.1)
5
+ prism
5
6
  rspec
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- ast (2.4.2)
11
+ ast (2.4.3)
11
12
  coderay (1.1.3)
12
- diff-lcs (1.6.0)
13
- json (2.10.1)
14
- language_server-protocol (3.17.0.4)
13
+ diff-lcs (1.6.2)
14
+ json (2.13.2)
15
+ language_server-protocol (3.17.0.5)
15
16
  lint_roller (1.1.0)
16
17
  method_source (1.1.0)
17
18
  onkcop (1.0.0.0)
18
19
  rubocop (>= 0.80.0)
19
20
  rubocop-rspec (>= 1.34.0)
20
- parallel (1.26.3)
21
- parser (3.3.7.1)
21
+ parallel (1.27.0)
22
+ parser (3.3.9.0)
22
23
  ast (~> 2.4.1)
23
24
  racc
25
+ prism (1.4.0)
24
26
  pry (0.15.2)
25
27
  coderay (~> 1.1)
26
28
  method_source (~> 1.0)
27
29
  racc (1.8.1)
28
30
  rainbow (3.1.1)
29
- rake (13.2.1)
30
- regexp_parser (2.10.0)
31
- rspec (3.13.0)
31
+ rake (13.3.0)
32
+ regexp_parser (2.11.0)
33
+ rspec (3.13.1)
32
34
  rspec-core (~> 3.13.0)
33
35
  rspec-expectations (~> 3.13.0)
34
36
  rspec-mocks (~> 3.13.0)
35
- rspec-core (3.13.3)
37
+ rspec-core (3.13.5)
36
38
  rspec-support (~> 3.13.0)
37
- rspec-expectations (3.13.3)
39
+ rspec-expectations (3.13.5)
38
40
  diff-lcs (>= 1.2.0, < 2.0)
39
41
  rspec-support (~> 3.13.0)
40
- rspec-mocks (3.13.2)
42
+ rspec-mocks (3.13.5)
41
43
  diff-lcs (>= 1.2.0, < 2.0)
42
44
  rspec-support (~> 3.13.0)
43
- rspec-support (3.13.2)
44
- rubocop (1.72.2)
45
+ rspec-support (3.13.4)
46
+ rubocop (1.79.2)
45
47
  json (~> 2.3)
46
48
  language_server-protocol (~> 3.17.0.2)
47
49
  lint_roller (~> 1.1.0)
@@ -49,12 +51,13 @@ GEM
49
51
  parser (>= 3.3.0.2)
50
52
  rainbow (>= 2.2.2, < 4.0)
51
53
  regexp_parser (>= 2.9.3, < 3.0)
52
- rubocop-ast (>= 1.38.0, < 2.0)
54
+ rubocop-ast (>= 1.46.0, < 2.0)
53
55
  ruby-progressbar (~> 1.7)
54
56
  unicode-display_width (>= 2.4.0, < 4.0)
55
- rubocop-ast (1.38.0)
56
- parser (>= 3.3.1.0)
57
- rubocop-rspec (3.5.0)
57
+ rubocop-ast (1.46.0)
58
+ parser (>= 3.3.7.2)
59
+ prism (~> 1.4)
60
+ rubocop-rspec (3.6.0)
58
61
  lint_roller (~> 1.1)
59
62
  rubocop (~> 1.72, >= 1.72.1)
60
63
  ruby-progressbar (1.13.0)
@@ -73,4 +76,4 @@ DEPENDENCIES
73
76
  rspec-paramz!
74
77
 
75
78
  BUNDLED WITH
76
- 2.3.15
79
+ 2.7.1
data/README.md CHANGED
@@ -6,7 +6,7 @@ Inspired by [tomykaira/rspec-parameterized](https://github.com/tomykaira/rspec-p
6
6
 
7
7
  ## Requirements
8
8
 
9
- - Ruby 3.1 or later
9
+ - Ruby 3.3 or later
10
10
 
11
11
  ## Installation
12
12
 
@@ -30,236 +30,37 @@ See [paramz_spec.rb](https://github.com/fukayatsu/rspec-paramz/blob/master/spec/
30
30
 
31
31
  ```ruby
32
32
  RSpec.describe RSpec::Paramz do
33
- describe '#paramz' do
34
- context 'format 1' do
33
+ describe "#paramz" do
34
+ describe "additions" do
35
+ let(:one) { 1 }
36
+ let(:two) { 2 }
37
+ let(:three) { 3 }
35
38
  paramz(
36
- [:a, :b, :answer],
37
- 1, 2, 3,
38
- 3, 8, 11,
39
- 5, -8, -3,
39
+ -> { [:a, :b, :answer] },
40
+ -> { [one, two, three ] },
41
+ -> { [3, 8, 11 ] },
42
+ -> { [5, -8, -3 ] },
40
43
  ) do
41
- it 'should do additions' do
44
+ it "do additions" do
42
45
  expect(a + b).to eq answer
43
46
  end
44
47
  end
45
-
46
- #=>
47
- # [a = 1 | b = 2 | answer = 3]
48
- # should do additions
49
- # [a = 3 | b = 8 | answer = 11]
50
- # should do additions
51
- # [a = 5 | b = -8 | answer = -3]
52
- # should do additions
53
- end
54
-
55
- context 'format 2' do
56
- paramz(
57
- [:a, :b, subject: -> { a + b }],
58
- 1, 2, 3,
59
- 3, 8, 11,
60
- 5, -8, -3,
61
- )
62
-
63
- #=>
64
- # [a = 1 | b = 2 | subject { a + b } = 3]
65
- # should == 3
66
- # [a = 3 | b = 8 | subject { a + b } = 11]
67
- # should == 11
68
- # [a = 5 | b = -8 | subject { a + b } = -3]
69
- # should == -3
70
- end
71
-
72
- context 'format 2-a' do
73
- paramz(
74
- [:a, :b, subject: -> { a + b }],
75
- 1, 2, 3,
76
- 3, 8, 11,
77
- 5, -8, -3,
78
- ) do
79
- it 'should do additions' do
80
- expect(subject).to eq(a + b)
81
- end
82
- end
83
-
84
- #=>
85
- # [a = 1 | b = 2 | subject { a + b } = 3]
86
- # should do additions
87
- # [a = 3 | b = 8 | subject { a + b } = 11]
88
- # should do additions
89
- # [a = 5 | b = -8 | subject { a + b } = -3]
90
- # should do additions
91
- end
92
-
93
- context 'format 3' do
94
- paramz(
95
- [:a, :b, subject: { answer: -> { a + b } }],
96
- 1, 2, 3,
97
- 3, 8, 11,
98
- 5, -8, -3,
99
- )
100
-
101
- #=>
102
- # [a = 1 | b = 2 | subject(:answer) { a + b } = 3]
103
- # should == 3
104
- # [a = 3 | b = 8 | subject(:answer) { a + b } = 11]
105
- # should == 11
106
- # [a = 5 | b = -8 | subject(:answer) { a + b } = -3]
107
- # should == -3
108
- end
109
-
110
- context 'format 3-b' do
111
- paramz(
112
- [:a, :b, subject: { answer: -> { a + b } }],
113
- 1, 2, 3,
114
- 3, 8, 11,
115
- 5, -8, -3,
116
- ) do
117
- it 'should do additions' do
118
- expect(subject).to eq(a + b)
119
- end
120
-
121
- it 'should do additions' do
122
- expect(answer).to eq(a + b)
123
- end
124
- end
125
-
126
- #=>
127
- # [a = 1 | b = 2 | subject(:answer) { a + b } = 3]
128
- # should do additions
129
- # should do additions
130
- # [a = 3 | b = 8 | subject(:answer) { a + b } = 11]
131
- # should do additions
132
- # should do additions
133
- # [a = 5 | b = -8 | subject(:answer) { a + b } = -3]
134
- # should do additions
135
- # should do additions
136
- end
137
-
138
- context 'format 4' do
139
- subject { a + b }
140
-
141
- paramz(
142
- [:a, :b, :subject],
143
- 1, 2, 3,
144
- 0, 0, 0,
145
- -1, -2, -3,
146
- )
147
-
148
- #=>
149
- # [a = 1 | b = 2 | subject = 3]
150
- # should == 3
151
- # [a = 0 | b = 0 | subject = 0]
152
- # should == 0
153
- # [a = -1 | b = -2 | subject = -3]
154
- # should == -3
155
- end
156
-
157
- context 'rspec-let' do
158
- let(:one) { 1 }
159
- let(:two) { one * 2 }
160
- let(:three) { one * 3 }
161
-
162
- context 'default' do
163
- paramz(
164
- [:a, :b, :answer],
165
- -> { one }, 0, 1,
166
- -> { one }, -> { one }, -> { 2 },
167
- -> { one }, -> { two }, -> { three },
168
- ) do
169
- it 'should do additions' do
170
- expect(a + b).to eq answer
171
- end
172
- end
173
-
174
- #=>
175
- # [a = { one } | b = 0 | answer = 1]
176
- # should do additions
177
- # [a = { one } | b = { one } | answer = { 2 }]
178
- # should do additions
179
- # [a = { one } | b = { two } | answer = { three }]
180
- # should do additions
181
- end
182
-
183
- context 'default 2' do
184
- subject { a + b }
185
- paramz(
186
- [:a, :b, :subject],
187
- -> { one }, 0, 1,
188
- -> { one }, -> { one }, -> { 2 },
189
- -> { one }, -> { two }, -> { three },
190
- )
191
-
192
- #=>
193
- # [a = { one } | b = 0 | subject = 1]
194
- # should == 1
195
- # [a = { one } | b = { one } | subject = { 2 }]
196
- # should == 2
197
- # [a = { one } | b = { two } | subject = { three }]
198
- # should == 3
199
- end
200
-
201
- context 'default 3' do
202
- paramz(
203
- [:a, :b, subject: -> { a + b }],
204
- -> { one }, 0, 1,
205
- -> { one }, -> { one }, -> { 2 },
206
- -> { one }, -> { two }, -> { three },
207
- )
208
-
209
- #=>
210
- # [a = { one } | b = 0 | subject { a + b } = 1]
211
- # should == 1
212
- # [a = { one } | b = { one } | subject { a + b } = { 2 }]
213
- # should == 2
214
- # [a = { one } | b = { two } | subject { a + b } = { three }]
215
- # should == 3
216
- end
217
-
218
- context 'using RSpec::Paramz::Syntax' do
219
- using RSpec::Paramz::Syntax
220
- paramz(
221
- [:a, :b, :answer],
222
- :one.&, 0, 1,
223
- :one.&, :one.&, -> { 2 },
224
- :one.&, :two.&, :three.&,
225
- ) do
226
- it 'should do additions' do
227
- expect(a + b).to eq answer
228
- end
229
- end
230
-
231
- #=>
232
- # [a = { one } | b = 0 | answer = 1]
233
- # should do additions
234
- # [a = { one } | b = { one } | answer = { 2 }]
235
- # should do additions
236
- # [a = { one } | b = { two } | answer = { three }]
237
- # should do additions
238
- end
239
- end
240
-
241
- context 'nil or empty' do
242
- paramz(
243
- [:a, :b, :answer],
244
- "foo", nil, "foo",
245
- "", nil, "",
246
- nil, "bar", nil
247
- ) do
248
- it 'should do additions' do
249
- expect(a&.to_s).to eq answer
250
- end
251
- end
252
-
253
- #=>
254
- # [a = "foo" | b = nil | answer = "foo"]
255
- # should do additions
256
- # [a = "" | b = nil | answer = ""]
257
- # should do additions
258
- # [a = nil | b = "bar" | answer = nil]
259
- # should do additions
260
48
  end
261
49
  end
262
50
  end
51
+
52
+ # =>
53
+ # RSpec::Paramz
54
+ # #paramz
55
+ # additions
56
+ # [a = one | b = two | answer = three]
57
+ # do additions
58
+ # [a = 3 | b = 8 | answer = 11]
59
+ # do additions
60
+ # [a = 5 | b = -8 | answer = -3]
61
+ # do additions
62
+ # [a = "a" | b = "b" | answer = "ab"]
63
+ # do additions
263
64
  ```
264
65
 
265
66
  ## Development
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Paramz
3
- VERSION = "2.0.0".freeze
3
+ VERSION = "3.0.1".freeze
4
4
  end
5
5
  end
data/lib/rspec/paramz.rb CHANGED
@@ -1,53 +1,65 @@
1
1
  require "rspec/paramz/version"
2
- require "rspec/paramz/syntax"
3
- require "rspec/paramz/named_proc"
4
- require "rspec/paramz/pretty_print"
2
+ require "prism"
5
3
 
6
4
  module RSpec
7
5
  module Paramz
8
6
  module ExampleGroupMethods
9
7
  def paramz(*args, &block)
10
- labels = args.first
11
-
12
- if !block_given? && labels.none? {|label| subject_label?(label) }
13
- raise ArgumentError, "No block or subject given to paramz."
8
+ unless block_given?
9
+ raise ArgumentError, "No block given to paramz."
14
10
  end
15
11
 
16
- args[1..].each_slice(labels.length).with_index do |arg, index|
17
- pairs = [labels, arg].transpose.to_h
18
-
19
- context_name = "[" + pairs.map {|k, v|
20
- "#{RSpec::Paramz::PrettyPrint.inspect(k)} = #{RSpec::Paramz::PrettyPrint.inspect(v, false)}"
21
- }.join(" | ") + "]"
22
-
23
- context context_name do
24
- pairs.each do |label, val|
25
- if subject_label?(label)
26
- if label == :subject
27
- module_exec { val.is_a?(Proc) ? let(:_paramz_subject, &val) : let(:_paramz_subject) { val } }
28
- it { should == _paramz_subject }
29
- next
30
- end
31
-
32
- _subject, _subject_name = parse_subject(label)
33
-
34
- module_exec { _subject.is_a?(Proc) ? subject(_subject_name, &_subject) : subject(_subject_name) { _subject } }
12
+ labels = args.first
13
+ labels = labels.call if labels.respond_to?(:call)
14
+ args[1..].each do |arg|
15
+ location = arg.source_location
16
+ source = spec_file_content(location.first).each_line.to_a[location[1] - 1].strip.delete_suffix(",")
17
+ result = Prism.parse(source)
18
+ lambda_node = result.value.compact_child_nodes.first.compact_child_nodes.first
19
+ array_nodes = lambda_node.body.compact_child_nodes.first
20
+ nodes = array_nodes.elements
21
+
22
+ texts = nodes.map do |node|
23
+ range = node.location.start_offset...node.location.end_offset
24
+ source.byteslice(range)
25
+ end
35
26
 
36
- unless block_given?
37
- module_exec { val.is_a?(Proc) ? let(:_paramz_subject, &val) : let(:_paramz_subject) { val } }
38
- it { should == _paramz_subject }
27
+ context_name =
28
+ "[#{[labels, texts].transpose.map {|label, text| "#{label} = #{text}" }.join(" | ")}]"
29
+
30
+ context(context_name) do
31
+ nodes.each.with_index do |node, index|
32
+ let(labels[index]) do
33
+ if node.type == :true_node
34
+ true
35
+ elsif node.type == :false_node
36
+ false
37
+ elsif node.type == :nil_node
38
+ nil
39
+ elsif node.type == :symbol_node
40
+ node.value.to_sym
41
+ elsif node.type == :string_node
42
+ node.unescaped
43
+ elsif node.type == :array_node
44
+ range = node.opening_loc.start_offset...node.closing_loc.end_offset
45
+ eval(source.byteslice(range)) # rubocop:disable Security/Eval
46
+ elsif node.respond_to?(:value)
47
+ node.value
48
+ elsif node.respond_to?(:content)
49
+ node.content
50
+ else
51
+ loc = node.location
52
+ eval(source[loc.start_character_offset...loc.end_code_units_offset]) # rubocop:disable Security/Eval
39
53
  end
40
- else
41
- module_exec { val.is_a?(Proc) ? let(label, &val) : let(label) { val } }
42
54
  end
43
55
  end
44
56
 
45
- module_eval(&block) if block_given?
57
+ module_exec(&block)
46
58
 
47
59
  after(:each) do |example|
48
60
  if example.exception
49
- index_info = arg.map {|v| RSpec::Paramz::PrettyPrint.inspect(v, false) }.join(", ")
50
- example.exception.backtrace.push("failed paramz index is:#{index + 1}:[#{index_info}]")
61
+ location = arg.source_location
62
+ example.exception.backtrace.push("failed paramz: #{location.first}:#{location.last}")
51
63
  end
52
64
  end
53
65
  end
@@ -56,22 +68,9 @@ module RSpec
56
68
 
57
69
  private
58
70
 
59
- def subject_label?(label)
60
- return true if label == :subject
61
-
62
- label.is_a?(Hash) && label.keys == [:subject]
63
- end
64
-
65
- def parse_subject(label)
66
- _subject = label[:subject]
67
-
68
- _subject_name = nil
69
- if _subject.is_a?(Hash)
70
- _subject_name = _subject.keys.first
71
- _subject = _subject.values.first
72
- end
73
-
74
- [_subject, _subject_name]
71
+ def spec_file_content(path)
72
+ @spec_file_content ||= {}
73
+ @spec_file_content[path] ||= File.read(path)
75
74
  end
76
75
  end
77
76
  end
data/rspec-paramz.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["fukayatsu"]
9
9
  spec.email = ["fukayatsu@gmail.com"]
10
10
 
11
- spec.required_ruby_version = ">= 3.1.0"
11
+ spec.required_ruby_version = ">= 3.3.0"
12
12
 
13
13
  spec.summary = "Simple Parameterized Test for RSpec."
14
14
  spec.description = "Simple Parameterized Test for RSpec"
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
+ spec.add_runtime_dependency "prism"
31
32
  spec.add_runtime_dependency "rspec"
32
33
 
33
34
  spec.add_development_dependency "bundler"
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-paramz
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: prism
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: rspec
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -100,9 +114,6 @@ files:
100
114
  - bin/console
101
115
  - bin/setup
102
116
  - lib/rspec/paramz.rb
103
- - lib/rspec/paramz/named_proc.rb
104
- - lib/rspec/paramz/pretty_print.rb
105
- - lib/rspec/paramz/syntax.rb
106
117
  - lib/rspec/paramz/version.rb
107
118
  - rspec-paramz.gemspec
108
119
  homepage: https://github.com/fukayatsu/rspec-paramz
@@ -119,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
130
  requirements:
120
131
  - - ">="
121
132
  - !ruby/object:Gem::Version
122
- version: 3.1.0
133
+ version: 3.3.0
123
134
  required_rubygems_version: !ruby/object:Gem::Requirement
124
135
  requirements:
125
136
  - - ">="
126
137
  - !ruby/object:Gem::Version
127
138
  version: '0'
128
139
  requirements: []
129
- rubygems_version: 3.6.2
140
+ rubygems_version: 3.6.9
130
141
  specification_version: 4
131
142
  summary: Simple Parameterized Test for RSpec.
132
143
  test_files: []
@@ -1,16 +0,0 @@
1
- module RSpec
2
- module Paramz
3
- class NamedProc < Proc
4
- def initialize(name, &block)
5
- @name = name
6
- super(&block)
7
- end
8
-
9
- def to_s
10
- "{ #{@name} }"
11
- end
12
-
13
- alias_method :inspect, :to_s
14
- end
15
- end
16
- end
@@ -1,62 +0,0 @@
1
- module RSpec
2
- module Paramz
3
- module PrettyPrint
4
- class << self
5
- def inspect(value, raw_value = true)
6
- case value
7
- when Hash
8
- subject(value)
9
- when Proc
10
- to_source(value)
11
- else
12
- raw_value ? value : value.inspect
13
- end
14
- end
15
-
16
- def subject(value)
17
- return value if value.keys != [:subject]
18
-
19
- _subject = value.values.first
20
- case _subject
21
- when Proc
22
- "subject #{to_source(_subject)}"
23
- when Hash
24
- subject_name = _subject.keys.first
25
- subject_value = _subject.values.first
26
-
27
- case subject_value
28
- when Proc
29
- "subject(:#{subject_name}) #{to_source(subject_value)}"
30
- else
31
- "subject { #{subject_value} }"
32
- end
33
- else
34
- value
35
- end
36
- end
37
-
38
- def to_source(value)
39
- return value if value.is_a?(NamedProc) || !value.is_a?(Proc)
40
-
41
- code_location = fetch_code_location(value)
42
- return value if code_location.nil?
43
-
44
- path = value.source_location.first
45
- lines = File.readlines(path)
46
-
47
- source_lines = lines[(code_location[0] - 1)..(code_location[2] - 1)]
48
- source_lines[-1] = source_lines[-1][0..(code_location[3] - 1)]
49
- source_lines[0] = source_lines[0][code_location[1]..]
50
- source_lines.map(&:strip).join("\n")
51
- end
52
-
53
- private
54
-
55
- def fetch_code_location(value)
56
- iseq = RubyVM::InstructionSequence.of(value)
57
- iseq.to_a[4][:code_location]
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,12 +0,0 @@
1
- module RSpec
2
- module Paramz
3
- module Syntax
4
- refine Symbol do
5
- def &
6
- _self = self
7
- NamedProc.new(self) { __send__(_self) }
8
- end
9
- end
10
- end
11
- end
12
- end