rspec-paramz 2.0.0 → 3.0.0

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: dc07d56d743753a5fb87a71f59a09aa0e16412baf21547a3fbaacf825c4d73fa
4
+ data.tar.gz: ad32309278e5f1039be6919fec42b4252f61125df84f71ca565f45be6ca1877e
5
5
  SHA512:
6
- metadata.gz: 1741436d436b3b23bb739c3d95a794f0d2de2304505bbe3d6cc679c9346fdf21b4c847426d79eb9cdaf10fac9793da4b6a03459223f383a020f16b80134c2eb8
7
- data.tar.gz: a974dd00c973303da0f7bd7bed9e49b121190aa257da8381e530554e05d37dce45cd2ef76194d1a131e6ef0e961452275d4448d49035010ebc5d92365e3cdcfb
6
+ metadata.gz: a5d40336ebd8d93cdf7dc5a3422ff1c989a35c39359a6f925ec9076ed8976e6bd94215becb5502524fd14d40eab7c842eadce051bf197c0e3fa2bfbd83fce144
7
+ data.tar.gz: cad59113cf11ebaca4bde86da66c79636496a9acccdac6f6f2913ab14ae488ea7a4e3cb1d527f59d5263ec1fe7c84af49fb02af8d2d1d7d5191f909c14f029c2
@@ -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 (2.0.0)
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.0".freeze
4
4
  end
5
5
  end
data/lib/rspec/paramz.rb CHANGED
@@ -1,53 +1,78 @@
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"
3
+
4
+ class Lambda < Prism::Visitor
5
+ attr_reader :calls
6
+
7
+ def initialize(calls)
8
+ @calls = calls
9
+ end
10
+
11
+ def visit_lambda_node(node)
12
+ super(node)
13
+ @calls << node.source
14
+ end
15
+ end
5
16
 
6
17
  module RSpec
7
18
  module Paramz
8
19
  module ExampleGroupMethods
9
20
  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."
21
+ unless block_given?
22
+ raise ArgumentError, "No block given to paramz."
14
23
  end
15
24
 
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 } }
25
+ labels = args.first
26
+ labels = labels.call if labels.respond_to?(:call)
27
+ args[1..].each do |arg|
28
+ location = arg.source_location
29
+ source = spec_file_content(location.first).each_line.to_a[location[1] - 1].strip.delete_suffix(",")
30
+ result = Prism.parse(source)
31
+ lambda_node = result.value.compact_child_nodes.first.compact_child_nodes.first
32
+ array_nodes = lambda_node.body.compact_child_nodes.first
33
+ nodes = array_nodes.elements
34
+
35
+ texts = nodes.map do |node|
36
+ range = node.location.start_offset...node.location.end_offset
37
+ source.byteslice(range)
38
+ end
35
39
 
36
- unless block_given?
37
- module_exec { val.is_a?(Proc) ? let(:_paramz_subject, &val) : let(:_paramz_subject) { val } }
38
- it { should == _paramz_subject }
40
+ context_name =
41
+ "[#{[labels, texts].transpose.map {|label, text| "#{label} = #{text}" }.join(" | ")}]"
42
+
43
+ context(context_name) do
44
+ nodes.each.with_index do |node, index|
45
+ let(labels[index]) do
46
+ if node.type == :true_node
47
+ true
48
+ elsif node.type == :false_node
49
+ false
50
+ elsif node.type == :nil_node
51
+ nil
52
+ elsif node.type == :symbol_node
53
+ node.value.to_sym
54
+ elsif node.type == :string_node
55
+ node.unescaped
56
+ elsif node.type == :array_node
57
+ range = node.opening_loc.start_offset...node.closing_loc.end_offset
58
+ eval(source.byteslice(range)) # rubocop:disable Security/Eval
59
+ elsif node.respond_to?(:value)
60
+ node.value
61
+ elsif node.respond_to?(:content)
62
+ node.content
63
+ else
64
+ loc = node.location
65
+ eval(source[loc.start_character_offset...loc.end_code_units_offset]) # rubocop:disable Security/Eval
39
66
  end
40
- else
41
- module_exec { val.is_a?(Proc) ? let(label, &val) : let(label) { val } }
42
67
  end
43
68
  end
44
69
 
45
- module_eval(&block) if block_given?
70
+ module_exec(&block)
46
71
 
47
72
  after(:each) do |example|
48
73
  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}]")
74
+ location = arg.source_location
75
+ example.exception.backtrace.push("failed paramz: #{location.first}:#{location.last}")
51
76
  end
52
77
  end
53
78
  end
@@ -56,22 +81,9 @@ module RSpec
56
81
 
57
82
  private
58
83
 
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]
84
+ def spec_file_content(path)
85
+ @spec_file_content ||= {}
86
+ @spec_file_content[path] ||= File.read(path)
75
87
  end
76
88
  end
77
89
  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,29 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-02-19 00:00:00.000000000 Z
11
+ date: 2025-08-07 00:00:00.000000000 Z
11
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prism
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
12
27
  - !ruby/object:Gem::Dependency
13
28
  name: rspec
14
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,9 +115,6 @@ files:
100
115
  - bin/console
101
116
  - bin/setup
102
117
  - 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
118
  - lib/rspec/paramz/version.rb
107
119
  - rspec-paramz.gemspec
108
120
  homepage: https://github.com/fukayatsu/rspec-paramz
@@ -112,6 +124,7 @@ metadata:
112
124
  homepage_uri: https://github.com/fukayatsu/rspec-paramz
113
125
  source_code_uri: https://github.com/fukayatsu/rspec-paramz
114
126
  changelog_uri: https://github.com/fukayatsu/rspec-paramz/releases
127
+ post_install_message:
115
128
  rdoc_options: []
116
129
  require_paths:
117
130
  - lib
@@ -119,14 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
132
  requirements:
120
133
  - - ">="
121
134
  - !ruby/object:Gem::Version
122
- version: 3.1.0
135
+ version: 3.3.0
123
136
  required_rubygems_version: !ruby/object:Gem::Requirement
124
137
  requirements:
125
138
  - - ">="
126
139
  - !ruby/object:Gem::Version
127
140
  version: '0'
128
141
  requirements: []
129
- rubygems_version: 3.6.2
142
+ rubygems_version: 3.3.7
143
+ signing_key:
130
144
  specification_version: 4
131
145
  summary: Simple Parameterized Test for RSpec.
132
146
  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