code_analyzer 0.4.8 → 0.5.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.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module CodeAnalyzer
3
- VERSION = "0.4.8"
3
+ VERSION = '0.5.0'
4
4
  end
@@ -6,7 +6,7 @@ module CodeAnalyzer
6
6
  class Warning
7
7
  attr_reader :filename, :line_number, :message
8
8
 
9
- def initialize(options={})
9
+ def initialize(options = {})
10
10
  @filename = options[:filename]
11
11
  @line_number = options[:line_number].to_s
12
12
  @message = options[:message]
@@ -4,55 +4,59 @@ module CodeAnalyzer
4
4
  describe Checker do
5
5
  let(:checker) { Checker.new }
6
6
 
7
- context "interesting_nodes" do
8
- it "should get empty interesting nodes" do
7
+ context 'interesting_nodes' do
8
+ it 'should get empty interesting nodes' do
9
9
  expect(checker.interesting_nodes).to eq []
10
10
  end
11
11
 
12
- it "should add interesting nodes" do
12
+ it 'should add interesting nodes' do
13
13
  Checker.interesting_nodes :class, :def
14
- expect(checker.interesting_nodes).to eq [:class, :def]
14
+ expect(checker.interesting_nodes).to eq %i[class def]
15
15
  end
16
16
  end
17
17
 
18
- context "interesting_files" do
19
- it "should match none of interesting files" do
18
+ context 'interesting_files' do
19
+ it 'should match none of interesting files' do
20
20
  expect(checker.interesting_files).to eq []
21
21
  end
22
22
 
23
- it "should add interesting files" do
23
+ it 'should add interesting files' do
24
24
  Checker.interesting_files /lib/, /spec/
25
25
  expect(checker.interesting_files).to eq [/lib/, /spec/]
26
26
  end
27
27
  end
28
28
 
29
- context "#parse_file?" do
30
- it "should return true if node_file matches pattern" do
31
- allow(checker).to receive(:interesting_files).and_return([/spec\/.*\.rb/, /lib\/.*\.rb/])
32
- expect(checker.parse_file?("lib/code_analyzer.rb")).to be true
29
+ context '#parse_file?' do
30
+ it 'should return true if node_file matches pattern' do
31
+ allow(checker).to receive(:interesting_files).and_return(
32
+ [%r{spec\/.*\.rb}, %r{lib\/.*\.rb}]
33
+ )
34
+ expect(checker.parse_file?('lib/code_analyzer.rb')).to be true
33
35
  end
34
36
 
35
37
  it "should return false if node_file doesn't match pattern" do
36
- allow(checker).to receive(:interesting_files).and_return([/spec\/.*\.rb/])
37
- expect(checker.parse_file?("lib/code_analyzer.rb")).to be false
38
+ allow(checker).to receive(:interesting_files).and_return(
39
+ [%r{spec\/.*\.rb}]
40
+ )
41
+ expect(checker.parse_file?('lib/code_analyzer.rb')).to be false
38
42
  end
39
43
  end
40
44
 
41
- context "callback" do
42
- it "should add callback to start_call" do
45
+ context 'callback' do
46
+ it 'should add callback to start_call' do
43
47
  block = Proc.new {}
44
48
  Checker.add_callback(:start_call, &block)
45
49
  expect(Checker.get_callbacks(:start_call)).to eq [block]
46
50
  end
47
51
 
48
- it "should add callback to both start_class and end_class" do
52
+ it 'should add callback to both start_class and end_class' do
49
53
  block = Proc.new {}
50
54
  Checker.add_callback(:start_class, :end_class, &block)
51
55
  expect(Checker.get_callbacks(:start_class)).to eq [block]
52
56
  expect(Checker.get_callbacks(:end_class)).to eq [block]
53
57
  end
54
58
 
55
- it "should add multiple callbacks to end_call" do
59
+ it 'should add multiple callbacks to end_call' do
56
60
  block1 = Proc.new {}
57
61
  block2 = Proc.new {}
58
62
  Checker.add_callback(:end_call, &block1)
@@ -1,14 +1,14 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module CodeAnalyzer::CheckingVisitor
4
4
  describe Default do
5
- let(:checker1) { double(:checker, interesting_nodes: [:class, :def]) }
6
- let(:checker2) { double(:checker, interesting_nodes: [:def, :call]) }
5
+ let(:checker1) { double(:checker, interesting_nodes: %i[class def]) }
6
+ let(:checker2) { double(:checker, interesting_nodes: %i[def call]) }
7
7
  let(:visitor) { Default.new(checkers: [checker1, checker2]) }
8
8
 
9
- it "should check def node by all checkers" do
10
- filename = "filename"
11
- content = "def test; end"
9
+ it 'should check def node by all checkers' do
10
+ filename = 'filename'
11
+ content = 'def test; end'
12
12
  allow(checker1).to receive(:parse_file?).with(filename).and_return(true)
13
13
  allow(checker2).to receive(:parse_file?).with(filename).and_return(true)
14
14
  expect(checker1).to receive(:node_start)
@@ -19,9 +19,9 @@ module CodeAnalyzer::CheckingVisitor
19
19
  visitor.check(filename, content)
20
20
  end
21
21
 
22
- it "should check class node by only checker1" do
23
- filename = "filename"
24
- content = "class Test; end"
22
+ it 'should check class node by only checker1' do
23
+ filename = 'filename'
24
+ content = 'class Test; end'
25
25
  allow(checker1).to receive(:parse_file?).with(filename).and_return(true)
26
26
  expect(checker1).to receive(:node_start)
27
27
  expect(checker1).to receive(:node_end)
@@ -29,9 +29,9 @@ module CodeAnalyzer::CheckingVisitor
29
29
  visitor.check(filename, content)
30
30
  end
31
31
 
32
- it "should check call node by only checker2" do
33
- filename = "filename"
34
- content = "obj.message"
32
+ it 'should check call node by only checker2' do
33
+ filename = 'filename'
34
+ content = 'obj.message'
35
35
  allow(checker2).to receive(:parse_file?).with(filename).and_return(true)
36
36
  expect(checker2).to receive(:node_start)
37
37
  expect(checker2).to receive(:node_end)
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module CodeAnalyzer::CheckingVisitor
4
4
  describe Plain do
@@ -6,9 +6,9 @@ module CodeAnalyzer::CheckingVisitor
6
6
  let(:checker2) { double(:checker) }
7
7
  let(:visitor) { Plain.new(checkers: [checker1, checker2]) }
8
8
 
9
- it "should check by all checkers" do
10
- filename = "filename"
11
- content = "content"
9
+ it 'should check by all checkers' do
10
+ filename = 'filename'
11
+ content = 'content'
12
12
  expect(checker1).to receive(:parse_file?).and_return(false)
13
13
  expect(checker2).to receive(:parse_file?).and_return(true)
14
14
  expect(checker1).not_to receive(:check).with(filename, content)
@@ -4,32 +4,32 @@ module CodeAnalyzer
4
4
  describe Nil do
5
5
  let(:core_nil) { Nil.new }
6
6
 
7
- context "to_s" do
8
- it "should return self" do
7
+ context 'to_s' do
8
+ it 'should return self' do
9
9
  expect(core_nil.to_s).to eq core_nil
10
10
  end
11
11
  end
12
12
 
13
- context "hash_size" do
14
- it "should return 0" do
13
+ context 'hash_size' do
14
+ it 'should return 0' do
15
15
  expect(core_nil.hash_size).to eq 0
16
16
  end
17
17
  end
18
18
 
19
- context "method_missing" do
20
- it "should return self" do
19
+ context 'method_missing' do
20
+ it 'should return self' do
21
21
  expect(core_nil.undefined).to eq core_nil
22
22
  end
23
23
  end
24
24
 
25
- context "present?" do
26
- it "should return false" do
25
+ context 'present?' do
26
+ it 'should return false' do
27
27
  expect(core_nil).not_to be_present
28
28
  end
29
29
  end
30
30
 
31
- context "blank?" do
32
- it "should return true" do
31
+ context 'blank?' do
32
+ it 'should return true' do
33
33
  expect(core_nil).to be_blank
34
34
  end
35
35
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sexp do
4
- describe "line" do
4
+ describe 'line' do
5
5
  before :each do
6
6
  content = <<-EOF
7
7
  class Demo
@@ -27,52 +27,52 @@ describe Sexp do
27
27
  @node = parse_content(content)
28
28
  end
29
29
 
30
- it "should return class line" do
30
+ it 'should return class line' do
31
31
  expect(@node.grep_node(sexp_type: :class).line_number).to eq 1
32
32
  end
33
33
 
34
- it "should return def line" do
34
+ it 'should return def line' do
35
35
  expect(@node.grep_node(sexp_type: :def).line_number).to eq 2
36
36
  end
37
37
 
38
- it "should return const line" do
38
+ it 'should return const line' do
39
39
  expect(@node.grep_node(sexp_type: :const_ref).line_number).to eq 1
40
40
  end
41
41
 
42
- it "should return const path line" do
42
+ it 'should return const path line' do
43
43
  expect(@node.grep_node(sexp_type: :const_path_ref).line_number).to eq 3
44
44
  end
45
45
 
46
- it "should return alias line" do
46
+ it 'should return alias line' do
47
47
  expect(@node.grep_node(sexp_type: :alias).line_number).to eq 5
48
48
  end
49
49
 
50
- it "should return hash line" do
50
+ it 'should return hash line' do
51
51
  expect(@node.grep_node(sexp_type: :hash).line_number).to eq 6
52
52
  end
53
53
 
54
- it "should return massign line" do
54
+ it 'should return massign line' do
55
55
  expect(@node.grep_node(sexp_type: :massign).line_number).to eq 8
56
56
  end
57
57
 
58
- it "should return opassign line" do
58
+ it 'should return opassign line' do
59
59
  expect(@node.grep_node(sexp_type: :opassign).line_number).to eq 11
60
60
  end
61
61
 
62
- it "should return if line" do
62
+ it 'should return if line' do
63
63
  expect(@node.grep_node(sexp_type: :if).line_number).to eq 14
64
64
  end
65
65
 
66
- it "should return elsif line" do
66
+ it 'should return elsif line' do
67
67
  expect(@node.grep_node(sexp_type: :elsif).line_number).to eq 16
68
68
  end
69
69
 
70
- it "should return if_mod line" do
70
+ it 'should return if_mod line' do
71
71
  expect(@node.grep_node(sexp_type: :if_mod).line_number).to eq 15
72
72
  end
73
73
  end
74
74
 
75
- describe "grep_nodes" do
75
+ describe 'grep_nodes' do
76
76
  before :each do
77
77
  content = <<-EOF
78
78
  def show
@@ -82,42 +82,100 @@ describe Sexp do
82
82
  @node = parse_content(content)
83
83
  end
84
84
 
85
- it "should get the call nodes with receiver current_user" do
85
+ it 'should get the call nodes with receiver current_user' do
86
86
  nodes = []
87
- @node.grep_nodes(sexp_type: :call, receiver: "current_user") { |node| nodes << node }
88
- if RUBY_VERSION == "1.9.2"
89
- expect(nodes).to eq [s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
87
+ @node.grep_nodes(sexp_type: :call, receiver: 'current_user') do |node|
88
+ nodes << node
89
+ end
90
+ if RUBY_VERSION == '1.9.2'
91
+ expect(nodes).to eq [
92
+ s(
93
+ :call,
94
+ s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
95
+ s(:@period, ".", s(2, 20)),
96
+ s(:@ident, 'posts', s(2, 21))
97
+ )
98
+ ]
90
99
  else
91
- expect(nodes).to eq [s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
100
+ expect(nodes).to eq [
101
+ s(
102
+ :call,
103
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
104
+ s(:@period, ".", s(2, 20)),
105
+ s(:@ident, 'posts', s(2, 21))
106
+ )
107
+ ]
92
108
  end
93
109
  end
94
110
 
95
- it "should get the call nodes with different messages" do
111
+ it 'should get the call nodes with different messages' do
96
112
  nodes = []
97
- @node.grep_nodes(sexp_type: :call, message: ["posts", "find"]) { |node| nodes << node }
98
- if RUBY_VERSION == "1.9.2"
99
- expect(nodes).to eq [s(:call, s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
113
+ @node.grep_nodes(sexp_type: :call, message: %w[posts find]) do |node|
114
+ nodes << node
115
+ end
116
+ if RUBY_VERSION == '1.9.2'
117
+ expect(nodes).to eq [
118
+ s(
119
+ :call,
120
+ s(
121
+ :call,
122
+ s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
123
+ s(:@period, ".", s(2, 20)),
124
+ s(:@ident, 'posts', s(2, 21))
125
+ ),
126
+ s(:@period, ".", s(2, 26)),
127
+ s(:@ident, 'find', s(2, 27))
128
+ ),
129
+ s(
130
+ :call,
131
+ s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
132
+ s(:@period, ".", s(2, 20)),
133
+ s(:@ident, 'posts', s(2, 21))
134
+ )
135
+ ]
100
136
  else
101
- expect(nodes).to eq [s(:call, s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
137
+ expect(nodes).to eq [
138
+ s(
139
+ :call,
140
+ s(
141
+ :call,
142
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
143
+ s(:@period, ".", s(2, 20)),
144
+ s(:@ident, 'posts', s(2, 21))
145
+ ),
146
+ s(:@period, ".", s(2, 26)),
147
+ s(:@ident, 'find', s(2, 27))
148
+ ),
149
+ s(
150
+ :call,
151
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
152
+ s(:@period, ".", s(2, 20)),
153
+ s(:@ident, 'posts', s(2, 21))
154
+ )
155
+ ]
102
156
  end
103
157
  end
104
158
 
105
- if RUBY_VERSION == "1.9.2"
106
- it "should get the var_ref node with to_s" do
159
+ if RUBY_VERSION == '1.9.2'
160
+ it 'should get the var_ref node with to_s' do
107
161
  nodes = []
108
- @node.grep_nodes(sexp_type: :var_ref, to_s: "current_user") { |node| nodes << node }
109
- expect(nodes).to eq [s(:var_ref, s(:@ident, "current_user", s(2, 8)))]
162
+ @node.grep_nodes(sexp_type: :var_ref, to_s: 'current_user') do |node|
163
+ nodes << node
164
+ end
165
+ expect(nodes).to eq [s(:var_ref, s(:@ident, 'current_user', s(2, 8)))]
110
166
  end
111
167
  else
112
- it "should get the vcall node with to_s" do
168
+ it 'should get the vcall node with to_s' do
113
169
  nodes = []
114
- @node.grep_nodes(sexp_type: :vcall, to_s: "current_user") { |node| nodes << node }
115
- expect(nodes).to eq [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
170
+ @node.grep_nodes(sexp_type: :vcall, to_s: 'current_user') do |node|
171
+ nodes << node
172
+ end
173
+ expect(nodes).to eq [s(:vcall, s(:@ident, 'current_user', s(2, 8)))]
116
174
  end
117
175
  end
118
176
  end
119
177
 
120
- describe "grep_node" do
178
+ describe 'grep_node' do
121
179
  before :each do
122
180
  content = <<-EOF
123
181
  def show
@@ -127,17 +185,27 @@ describe Sexp do
127
185
  @node = parse_content(content)
128
186
  end
129
187
 
130
- it "should get first node with empty argument" do
131
- node = @node.grep_node(sexp_type: :call, receiver: "current_user")
132
- if RUBY_VERSION == "1.9.2"
133
- expect(node).to eq s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
188
+ it 'should get first node with empty argument' do
189
+ node = @node.grep_node(sexp_type: :call, receiver: 'current_user')
190
+ if RUBY_VERSION == '1.9.2'
191
+ expect(node).to eq s(
192
+ :call,
193
+ s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
194
+ s(:@period, ".", s(2, 20)),
195
+ s(:@ident, 'posts', s(2, 21))
196
+ )
134
197
  else
135
- expect(node).to eq s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
198
+ expect(node).to eq s(
199
+ :call,
200
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
201
+ s(:@period, ".", s(2, 20)),
202
+ s(:@ident, 'posts', s(2, 21))
203
+ )
136
204
  end
137
205
  end
138
206
  end
139
207
 
140
- describe "grep_nodes_count" do
208
+ describe 'grep_nodes_count' do
141
209
  before :each do
142
210
  content = <<-EOF
143
211
  def show
@@ -147,597 +215,743 @@ describe Sexp do
147
215
  @node = parse_content(content)
148
216
  end
149
217
 
150
- it "should get the count of call nodes" do
218
+ it 'should get the count of call nodes' do
151
219
  expect(@node.grep_nodes_count(sexp_type: :call)).to eq 2
152
220
  end
153
221
  end
154
222
 
155
- describe "receiver" do
156
- it "should get receiver of assign node" do
157
- node = parse_content("user.name = params[:name]").grep_node(sexp_type: :assign)
223
+ describe 'receiver' do
224
+ it 'should get receiver of assign node' do
225
+ node =
226
+ parse_content('user.name = params[:name]').grep_node(sexp_type: :assign)
158
227
  receiver = node.receiver
159
228
  expect(receiver.sexp_type).to eq :field
160
- expect(receiver.receiver.to_s).to eq "user"
161
- expect(receiver.message.to_s).to eq "name"
229
+ expect(receiver.receiver.to_s).to eq 'user'
230
+ expect(receiver.message.to_s).to eq 'name'
162
231
  end
163
232
 
164
- it "should get receiver of field node" do
165
- node = parse_content("user.name = params[:name]").grep_node(sexp_type: :field)
166
- expect(node.receiver.to_s).to eq "user"
233
+ it 'should get receiver of field node' do
234
+ node =
235
+ parse_content('user.name = params[:name]').grep_node(sexp_type: :field)
236
+ expect(node.receiver.to_s).to eq 'user'
167
237
  end
168
238
 
169
- it "should get receiver of call node" do
170
- node = parse_content("user.name").grep_node(sexp_type: :call)
171
- expect(node.receiver.to_s).to eq "user"
239
+ it 'should get receiver of call node' do
240
+ node = parse_content('user.name').grep_node(sexp_type: :call)
241
+ expect(node.receiver.to_s).to eq 'user'
172
242
  end
173
243
 
174
- it "should get receiver of binary" do
244
+ it 'should get receiver of binary' do
175
245
  node = parse_content("user == 'user_name'").grep_node(sexp_type: :binary)
176
- expect(node.receiver.to_s).to eq "user"
246
+ expect(node.receiver.to_s).to eq 'user'
177
247
  end
178
248
 
179
- it "should get receiver of command_call" do
249
+ it 'should get receiver of command_call' do
180
250
  content = <<-EOF
181
251
  map.resources :posts do
182
252
  end
183
253
  EOF
184
254
  node = parse_content(content).grep_node(sexp_type: :command_call)
185
- expect(node.receiver.to_s).to eq "map"
255
+ expect(node.receiver.to_s).to eq 'map'
186
256
  end
187
257
 
188
- it "should get receiver of method_add_arg" do
189
- node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
190
- expect(node.receiver.to_s).to eq "Post"
258
+ it 'should get receiver of method_add_arg' do
259
+ node =
260
+ parse_content('Post.find(:all)').grep_node(sexp_type: :method_add_arg)
261
+ expect(node.receiver.to_s).to eq 'Post'
191
262
  end
192
263
 
193
- it "should get receiver of method_add_block" do
194
- node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
195
- expect(node.receiver.to_s).to eq "Post"
264
+ it 'should get receiver of method_add_block' do
265
+ node =
266
+ parse_content('Post.save do; end').grep_node(
267
+ sexp_type: :method_add_block
268
+ )
269
+ expect(node.receiver.to_s).to eq 'Post'
196
270
  end
197
271
  end
198
272
 
199
- describe "module_name" do
200
- it "should get module name of module node" do
201
- node = parse_content("module Admin; end").grep_node(sexp_type: :module)
202
- expect(node.module_name.to_s).to eq "Admin"
273
+ describe 'module_name' do
274
+ it 'should get module name of module node' do
275
+ node = parse_content('module Admin; end').grep_node(sexp_type: :module)
276
+ expect(node.module_name.to_s).to eq 'Admin'
203
277
  end
204
278
  end
205
279
 
206
- describe "class_name" do
207
- it "should get class name of class node" do
208
- node = parse_content("class User; end").grep_node(sexp_type: :class)
209
- expect(node.class_name.to_s).to eq "User"
280
+ describe 'class_name' do
281
+ it 'should get class name of class node' do
282
+ node = parse_content('class User; end').grep_node(sexp_type: :class)
283
+ expect(node.class_name.to_s).to eq 'User'
210
284
  end
211
285
  end
212
286
 
213
- describe "base_class" do
214
- it "should get base class of class node" do
215
- node = parse_content("class User < ActiveRecord::Base; end").grep_node(sexp_type: :class)
216
- expect(node.base_class.to_s).to eq "ActiveRecord::Base"
287
+ describe 'base_class' do
288
+ it 'should get base class of class node' do
289
+ node =
290
+ parse_content('class User < ActiveRecord::Base; end').grep_node(
291
+ sexp_type: :class
292
+ )
293
+ expect(node.base_class.to_s).to eq 'ActiveRecord::Base'
217
294
  end
218
295
  end
219
296
 
220
- describe "left_value" do
221
- it "should get the left value of assign" do
222
- node = parse_content("user = current_user").grep_node(sexp_type: :assign)
223
- expect(node.left_value.to_s).to eq "user"
297
+ describe 'left_value' do
298
+ it 'should get the left value of assign' do
299
+ node = parse_content('user = current_user').grep_node(sexp_type: :assign)
300
+ expect(node.left_value.to_s).to eq 'user'
224
301
  end
225
302
  end
226
303
 
227
- describe "right_value" do
228
- it "should get the right value of assign" do
229
- node = parse_content("user = current_user").grep_node(sexp_type: :assign)
230
- expect(node.right_value.to_s).to eq "current_user"
304
+ describe 'right_value' do
305
+ it 'should get the right value of assign' do
306
+ node = parse_content('user = current_user').grep_node(sexp_type: :assign)
307
+ expect(node.right_value.to_s).to eq 'current_user'
231
308
  end
232
309
  end
233
310
 
234
- describe "message" do
235
- it "should get the message of command" do
236
- node = parse_content("has_many :projects").grep_node(sexp_type: :command)
237
- expect(node.message.to_s).to eq "has_many"
311
+ describe 'message' do
312
+ it 'should get the message of command' do
313
+ node = parse_content('has_many :projects').grep_node(sexp_type: :command)
314
+ expect(node.message.to_s).to eq 'has_many'
238
315
  end
239
316
 
240
- it "should get the message of command_call" do
241
- node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
242
- expect(node.message.to_s).to eq "resources"
317
+ it 'should get the message of command_call' do
318
+ node =
319
+ parse_content('map.resources :posts do; end').grep_node(
320
+ sexp_type: :command_call
321
+ )
322
+ expect(node.message.to_s).to eq 'resources'
243
323
  end
244
324
 
245
- it "should get the message of field" do
325
+ it 'should get the message of field' do
246
326
  node = parse_content("user.name = 'test'").grep_node(sexp_type: :field)
247
- expect(node.message.to_s).to eq "name"
327
+ expect(node.message.to_s).to eq 'name'
248
328
  end
249
329
 
250
- it "should get the message of call" do
251
- node = parse_content("user.name").grep_node(sexp_type: :call)
252
- expect(node.message.to_s).to eq "name"
330
+ it 'should get the message of call' do
331
+ node = parse_content('user.name').grep_node(sexp_type: :call)
332
+ expect(node.message.to_s).to eq 'name'
253
333
  end
254
334
 
255
- it "should get the message of binary" do
335
+ it 'should get the message of binary' do
256
336
  node = parse_content("user.name == 'test'").grep_node(sexp_type: :binary)
257
- expect(node.message.to_s).to eq "=="
337
+ expect(node.message.to_s).to eq '=='
258
338
  end
259
339
 
260
- it "should get the message of fcall" do
340
+ it 'should get the message of fcall' do
261
341
  node = parse_content("test?('world')").grep_node(sexp_type: :fcall)
262
- expect(node.message.to_s).to eq "test?"
342
+ expect(node.message.to_s).to eq 'test?'
263
343
  end
264
344
 
265
- it "should get the message of method_add_arg" do
266
- node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
267
- expect(node.message.to_s).to eq "find"
345
+ it 'should get the message of method_add_arg' do
346
+ node =
347
+ parse_content('Post.find(:all)').grep_node(sexp_type: :method_add_arg)
348
+ expect(node.message.to_s).to eq 'find'
268
349
  end
269
350
 
270
- it "should get the message of method_add_block" do
271
- node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
272
- expect(node.message.to_s).to eq "save"
351
+ it 'should get the message of method_add_block' do
352
+ node =
353
+ parse_content('Post.save do; end').grep_node(
354
+ sexp_type: :method_add_block
355
+ )
356
+ expect(node.message.to_s).to eq 'save'
273
357
  end
274
358
  end
275
359
 
276
- describe "arguments" do
277
- it "should get the arguments of command" do
278
- node = parse_content("resources :posts do; end").grep_node(sexp_type: :command)
360
+ describe 'arguments' do
361
+ it 'should get the arguments of command' do
362
+ node =
363
+ parse_content('resources :posts do; end').grep_node(sexp_type: :command)
279
364
  expect(node.arguments.sexp_type).to eq :args_add_block
280
365
  end
281
366
 
282
- it "should get the arguments of command_call" do
283
- node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
367
+ it 'should get the arguments of command_call' do
368
+ node =
369
+ parse_content('map.resources :posts do; end').grep_node(
370
+ sexp_type: :command_call
371
+ )
284
372
  expect(node.arguments.sexp_type).to eq :args_add_block
285
373
  end
286
374
 
287
- it "should get the arguments of method_add_arg" do
288
- node = parse_content("User.find(:all)").grep_node(sexp_type: :method_add_arg)
375
+ it 'should get the arguments of method_add_arg' do
376
+ node =
377
+ parse_content('User.find(:all)').grep_node(sexp_type: :method_add_arg)
289
378
  expect(node.arguments.sexp_type).to eq :args_add_block
290
379
  end
291
380
 
292
- it "should get the arguments of method_add_block" do
293
- node = parse_content("Post.save(false) do; end").grep_node(sexp_type: :method_add_block)
381
+ it 'should get the arguments of method_add_block' do
382
+ node =
383
+ parse_content('Post.save(false) do; end').grep_node(
384
+ sexp_type: :method_add_block
385
+ )
294
386
  expect(node.arguments.sexp_type).to eq :args_add_block
295
387
  end
296
388
  end
297
389
 
298
- describe "argument" do
299
- it "should get the argument of binary" do
300
- node = parse_content("user == current_user").grep_node(sexp_type: :binary)
301
- expect(node.argument.to_s).to eq "current_user"
302
- end
303
- end
304
-
305
- describe "all" do
306
- it "should get all arguments" do
307
- node = parse_content("puts 'hello', 'world'").grep_node(sexp_type: :args_add_block)
308
- expect(node.all.map(&:to_s)).to eq ["hello", "world"]
309
- end
310
-
311
- it "should get all arguments with &:" do
312
- node = parse_content("user.posts.map(&:title)").grep_node(sexp_type: :args_add_block)
313
- expect(node.all.map(&:to_s)).to eq ["title"]
314
- end
315
-
316
- it "should get all arguments with command_call node" do
317
- node = parse_content("options_for_select(Account.get_business current_user)").grep_node(sexp_type: :args_add)
318
- if RUBY_VERSION == "1.9.2"
319
- expect(node.all).to eq [s(:command_call, s(:var_ref, s(:@const, "Account", s(1, 19))), :".", s(:@ident, "get_business", s(1, 27)), s(:args_add_block, s(:args_add, s(:args_new), s(:var_ref, s(:@ident, "current_user", s(1, 40)))), false))]
390
+ describe 'argument' do
391
+ it 'should get the argument of binary' do
392
+ node = parse_content('user == current_user').grep_node(sexp_type: :binary)
393
+ expect(node.argument.to_s).to eq 'current_user'
394
+ end
395
+ end
396
+
397
+ describe 'all' do
398
+ it 'should get all arguments' do
399
+ node =
400
+ parse_content("puts 'hello', 'world'").grep_node(
401
+ sexp_type: :args_add_block
402
+ )
403
+ expect(node.all.map(&:to_s)).to eq %w[hello world]
404
+ end
405
+
406
+ it 'should get all arguments with &:' do
407
+ node =
408
+ parse_content('user.posts.map(&:title)').grep_node(
409
+ sexp_type: :args_add_block
410
+ )
411
+ expect(node.all.map(&:to_s)).to eq %w[title]
412
+ end
413
+
414
+ it 'should get all arguments with command_call node' do
415
+ node =
416
+ parse_content('options_for_select(Account.get_business current_user)')
417
+ .grep_node(sexp_type: :args_add)
418
+ if RUBY_VERSION == '1.9.2'
419
+ expect(node.all).to eq [
420
+ s(
421
+ :command_call,
422
+ s(:var_ref, s(:@const, 'Account', s(1, 19))),
423
+ :".",
424
+ s(:@ident, 'get_business', s(1, 27)),
425
+ s(
426
+ :args_add_block,
427
+ s(
428
+ :args_add,
429
+ s(:args_new),
430
+ s(:var_ref, s(:@ident, 'current_user', s(1, 40)))
431
+ ),
432
+ false
433
+ )
434
+ )
435
+ ]
320
436
  else
321
- expect(node.all).to eq [s(:command_call, s(:var_ref, s(:@const, "Account", s(1, 19))), :".", s(:@ident, "get_business", s(1, 27)), s(:args_add_block, s(:args_add, s(:args_new), s(:vcall, s(:@ident, "current_user", s(1, 40)))), false))]
437
+ expect(node.all).to eq [
438
+ s(
439
+ :command_call,
440
+ s(:var_ref, s(:@const, 'Account', s(1, 19))),
441
+ s(:@period, ".", s(1, 26)),
442
+ s(:@ident, 'get_business', s(1, 27)),
443
+ s(
444
+ :args_add_block,
445
+ s(
446
+ :args_add,
447
+ s(:args_new),
448
+ s(:vcall, s(:@ident, 'current_user', s(1, 40)))
449
+ ),
450
+ false
451
+ )
452
+ )
453
+ ]
322
454
  end
323
455
  end
324
456
 
325
- it "no error for args_add_star" do
326
- node = parse_content("send(:\"\#{route}_url\", *args)").grep_node(sexp_type: :args_add_block)
457
+ it 'no error for args_add_star' do
458
+ node =
459
+ parse_content("send(:\"\#{route}_url\", *args)").grep_node(
460
+ sexp_type: :args_add_block
461
+ )
327
462
  expect { node.all }.not_to raise_error
328
463
  end
329
464
  end
330
465
 
331
- describe "conditional_statement" do
332
- it "should get conditional statement of if" do
333
- node = parse_content("if true; end").grep_node(sexp_type: :if)
334
- expect(node.conditional_statement.to_s).to eq "true"
466
+ describe 'conditional_statement' do
467
+ it 'should get conditional statement of if' do
468
+ node = parse_content('if true; end').grep_node(sexp_type: :if)
469
+ expect(node.conditional_statement.to_s).to eq 'true'
335
470
  end
336
471
 
337
- it "should get conditional statement of unless" do
338
- node = parse_content("unless false; end").grep_node(sexp_type: :unless)
339
- expect(node.conditional_statement.to_s).to eq "false"
472
+ it 'should get conditional statement of unless' do
473
+ node = parse_content('unless false; end').grep_node(sexp_type: :unless)
474
+ expect(node.conditional_statement.to_s).to eq 'false'
340
475
  end
341
476
 
342
- it "should get conditional statement of elsif" do
343
- node = parse_content("if true; elsif false; end").grep_node(sexp_type: :elsif)
344
- expect(node.conditional_statement.to_s).to eq "false"
477
+ it 'should get conditional statement of elsif' do
478
+ node =
479
+ parse_content('if true; elsif false; end').grep_node(sexp_type: :elsif)
480
+ expect(node.conditional_statement.to_s).to eq 'false'
345
481
  end
346
482
 
347
- it "should get conditional statement of if_mod" do
483
+ it 'should get conditional statement of if_mod' do
348
484
  node = parse_content("'OK' if true").grep_node(sexp_type: :if_mod)
349
- expect(node.conditional_statement.to_s).to eq "true"
485
+ expect(node.conditional_statement.to_s).to eq 'true'
350
486
  end
351
487
 
352
- it "should get conditional statement of unless_mod" do
353
- node = parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
354
- expect(node.conditional_statement.to_s).to eq "false"
488
+ it 'should get conditional statement of unless_mod' do
489
+ node =
490
+ parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
491
+ expect(node.conditional_statement.to_s).to eq 'false'
355
492
  end
356
493
 
357
- it "should get conditional statement of ifop" do
494
+ it 'should get conditional statement of ifop' do
358
495
  node = parse_content("true ? 'OK' : 'NO'").grep_node(sexp_type: :ifop)
359
- expect(node.conditional_statement.to_s).to eq "true"
496
+ expect(node.conditional_statement.to_s).to eq 'true'
360
497
  end
361
498
  end
362
499
 
363
- describe "all_conditions" do
364
- it "should get all conditions" do
365
- node = parse_content("user == current_user && user.valid? || user.admin?").grep_node(sexp_type: :binary)
500
+ describe 'all_conditions' do
501
+ it 'should get all conditions' do
502
+ node =
503
+ parse_content('user == current_user && user.valid? || user.admin?')
504
+ .grep_node(sexp_type: :binary)
366
505
  expect(node.all_conditions.size).to eq 3
367
506
  end
368
507
  end
369
508
 
370
- describe "method_name" do
371
- it "should get the method name of def" do
372
- node = parse_content("def show; end").grep_node(sexp_type: :def)
373
- expect(node.method_name.to_s).to eq "show"
509
+ describe 'method_name' do
510
+ it 'should get the method name of def' do
511
+ node = parse_content('def show; end').grep_node(sexp_type: :def)
512
+ expect(node.method_name.to_s).to eq 'show'
374
513
  end
375
514
 
376
- it "should get the method name of defs" do
377
- node = parse_content("def self.find; end").grep_node(sexp_type: :defs)
378
- expect(node.method_name.to_s).to eq "find"
515
+ it 'should get the method name of defs' do
516
+ node = parse_content('def self.find; end').grep_node(sexp_type: :defs)
517
+ expect(node.method_name.to_s).to eq 'find'
379
518
  end
380
519
  end
381
520
 
382
- describe "body" do
383
- it "should get body of class" do
384
- node = parse_content("class User; end").grep_node(sexp_type: :class)
521
+ describe 'body' do
522
+ it 'should get body of class' do
523
+ node = parse_content('class User; end').grep_node(sexp_type: :class)
385
524
  expect(node.body.sexp_type).to eq :bodystmt
386
525
  end
387
526
 
388
- it "should get body of def" do
389
- node = parse_content("def login; end").grep_node(sexp_type: :def)
527
+ it 'should get body of def' do
528
+ node = parse_content('def login; end').grep_node(sexp_type: :def)
390
529
  expect(node.body.sexp_type).to eq :bodystmt
391
530
  end
392
531
 
393
- it "should get body of defs" do
394
- node = parse_content("def self.login; end").grep_node(sexp_type: :defs)
532
+ it 'should get body of defs' do
533
+ node = parse_content('def self.login; end').grep_node(sexp_type: :defs)
395
534
  expect(node.body.sexp_type).to eq :bodystmt
396
535
  end
397
536
 
398
- it "should get body of module" do
399
- node = parse_content("module Enumerable; end").grep_node(sexp_type: :module)
537
+ it 'should get body of module' do
538
+ node =
539
+ parse_content('module Enumerable; end').grep_node(sexp_type: :module)
400
540
  expect(node.body.sexp_type).to eq :bodystmt
401
541
  end
402
542
 
403
- it "should get body of if" do
543
+ it 'should get body of if' do
404
544
  node = parse_content("if true; 'OK'; end").grep_node(sexp_type: :if)
405
545
  expect(node.body.sexp_type).to eq :stmts_add
406
546
  end
407
547
 
408
- it "should get body of elsif" do
409
- node = parse_content("if true; elsif true; 'OK'; end").grep_node(sexp_type: :elsif)
548
+ it 'should get body of elsif' do
549
+ node =
550
+ parse_content("if true; elsif true; 'OK'; end").grep_node(
551
+ sexp_type: :elsif
552
+ )
410
553
  expect(node.body.sexp_type).to eq :stmts_add
411
554
  end
412
555
 
413
- it "should get body of unless" do
414
- node = parse_content("unless true; 'OK'; end").grep_node(sexp_type: :unless)
556
+ it 'should get body of unless' do
557
+ node =
558
+ parse_content("unless true; 'OK'; end").grep_node(sexp_type: :unless)
415
559
  expect(node.body.sexp_type).to eq :stmts_add
416
560
  end
417
561
 
418
- it "should get body of else" do
419
- node = parse_content("if true; else; 'OK'; end").grep_node(sexp_type: :else)
562
+ it 'should get body of else' do
563
+ node =
564
+ parse_content("if true; else; 'OK'; end").grep_node(sexp_type: :else)
420
565
  expect(node.body.sexp_type).to eq :stmts_add
421
566
  end
422
567
 
423
- it "should get body of if_mod" do
568
+ it 'should get body of if_mod' do
424
569
  node = parse_content("'OK' if true").grep_node(sexp_type: :if_mod)
425
- expect(node.body.to_s).to eq "OK"
570
+ expect(node.body.to_s).to eq 'OK'
426
571
  end
427
572
 
428
- it "should get body of unless_mod" do
429
- node = parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
430
- expect(node.body.to_s).to eq "OK"
573
+ it 'should get body of unless_mod' do
574
+ node =
575
+ parse_content("'OK' unless false").grep_node(sexp_type: :unless_mod)
576
+ expect(node.body.to_s).to eq 'OK'
431
577
  end
432
578
 
433
- it "should get body of if_op" do
579
+ it 'should get body of if_op' do
434
580
  node = parse_content("true ? 'OK' : 'NO'").grep_node(sexp_type: :ifop)
435
- expect(node.body.to_s).to eq "OK"
581
+ expect(node.body.to_s).to eq 'OK'
436
582
  end
437
583
  end
438
584
 
439
- describe "block" do
440
- it "sould get block of method_add_block node" do
441
- node = parse_content("resources :posts do; resources :comments; end").grep_node(sexp_type: :method_add_block)
585
+ describe 'block' do
586
+ it 'sould get block of method_add_block node' do
587
+ node =
588
+ parse_content('resources :posts do; resources :comments; end')
589
+ .grep_node(sexp_type: :method_add_block)
442
590
  expect(node.block_node.sexp_type).to eq :do_block
443
591
  end
444
592
  end
445
593
 
446
- describe "statements" do
447
- it "should get statements of do_block node" do
448
- node = parse_content("resources :posts do; resources :comments; resources :like; end").grep_node(sexp_type: :do_block)
594
+ describe 'statements' do
595
+ it 'should get statements of do_block node' do
596
+ node =
597
+ parse_content(
598
+ 'resources :posts do; resources :comments; resources :like; end'
599
+ )
600
+ .grep_node(sexp_type: :do_block)
449
601
  expect(node.statements.size).to eq 2
450
602
  end
451
603
 
452
- it "should get statements of bodystmt node" do
453
- node = parse_content("class User; def login?; end; def admin?; end; end").grep_node(sexp_type: :bodystmt)
604
+ it 'should get statements of bodystmt node' do
605
+ node =
606
+ parse_content('class User; def login?; end; def admin?; end; end')
607
+ .grep_node(sexp_type: :bodystmt)
454
608
  expect(node.statements.size).to eq 2
455
609
  end
456
610
  end
457
611
 
458
- describe "exception_classes" do
459
- it "should get exception classes of rescue node" do
460
- node = parse_content("def test; rescue CustomException; end").grep_node(sexp_type: :rescue)
461
- expect(node.exception_classes.first.to_s).to eq "CustomException"
612
+ describe 'exception_classes' do
613
+ it 'should get exception classes of rescue node' do
614
+ node =
615
+ parse_content('def test; rescue CustomException; end').grep_node(
616
+ sexp_type: :rescue
617
+ )
618
+ expect(node.exception_classes.first.to_s).to eq 'CustomException'
462
619
  end
463
620
 
464
- it "should get empty of empty rescue node" do
465
- node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
466
- expect(node.exception_classes.first.to_s).to eq ""
621
+ it 'should get empty of empty rescue node' do
622
+ node =
623
+ parse_content('def test; rescue; end').grep_node(sexp_type: :rescue)
624
+ expect(node.exception_classes.first.to_s).to eq ''
467
625
  end
468
626
 
469
- it "should get exception classes of rescue node for multiple exceptions" do
470
- node = parse_content("def test; rescue StandardError, CustomException; end").grep_node(sexp_type: :rescue)
471
- expect(node.exception_classes.first.to_s).to eq "StandardError"
472
- expect(node.exception_classes.last.to_s).to eq "CustomException"
627
+ it 'should get exception classes of rescue node for multiple exceptions' do
628
+ node =
629
+ parse_content('def test; rescue StandardError, CustomException; end')
630
+ .grep_node(sexp_type: :rescue)
631
+ expect(node.exception_classes.first.to_s).to eq 'StandardError'
632
+ expect(node.exception_classes.last.to_s).to eq 'CustomException'
473
633
  end
474
634
  end
475
635
 
476
- describe "exception_variable" do
477
- it "should get exception varible of rescue node" do
478
- node = parse_content("def test; rescue => e; end").grep_node(sexp_type: :rescue)
479
- expect(node.exception_variable.to_s).to eq "e"
636
+ describe 'exception_variable' do
637
+ it 'should get exception varible of rescue node' do
638
+ node =
639
+ parse_content('def test; rescue => e; end').grep_node(
640
+ sexp_type: :rescue
641
+ )
642
+ expect(node.exception_variable.to_s).to eq 'e'
480
643
  end
481
644
 
482
- it "should get empty of empty rescue node" do
483
- node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
484
- expect(node.exception_variable.to_s).to eq ""
645
+ it 'should get empty of empty rescue node' do
646
+ node =
647
+ parse_content('def test; rescue; end').grep_node(sexp_type: :rescue)
648
+ expect(node.exception_variable.to_s).to eq ''
485
649
  end
486
650
  end
487
651
 
488
- describe "hash_value" do
489
- it "should get value for hash node" do
490
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
491
- expect(node.hash_value("first_name").to_s).to eq "Richard"
492
- expect(node.hash_value("last_name").to_s).to eq "Huang"
652
+ describe 'hash_value' do
653
+ it 'should get value for hash node' do
654
+ node =
655
+ parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(
656
+ sexp_type: :hash
657
+ )
658
+ expect(node.hash_value('first_name').to_s).to eq 'Richard'
659
+ expect(node.hash_value('last_name').to_s).to eq 'Huang'
493
660
  end
494
661
 
495
- it "should get value for bare_assoc_hash" do
496
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
497
- expect(node.hash_value("first_name").to_s).to eq "Richard"
498
- expect(node.hash_value("last_name").to_s).to eq "Huang"
662
+ it 'should get value for bare_assoc_hash' do
663
+ node =
664
+ parse_content(
665
+ "add_user :user, first_name: 'Richard', last_name: 'Huang'"
666
+ )
667
+ .grep_node(sexp_type: :bare_assoc_hash)
668
+ expect(node.hash_value('first_name').to_s).to eq 'Richard'
669
+ expect(node.hash_value('last_name').to_s).to eq 'Huang'
499
670
  end
500
671
  end
501
672
 
502
- describe "hash_size" do
503
- it "should get value for hash node" do
504
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
673
+ describe 'hash_size' do
674
+ it 'should get value for hash node' do
675
+ node =
676
+ parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(
677
+ sexp_type: :hash
678
+ )
505
679
  expect(node.hash_size).to eq 2
506
680
  end
507
681
 
508
- it "should get value for bare_assoc_hash" do
509
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
682
+ it 'should get value for bare_assoc_hash' do
683
+ node =
684
+ parse_content(
685
+ "add_user :user, first_name: 'Richard', last_name: 'Huang'"
686
+ )
687
+ .grep_node(sexp_type: :bare_assoc_hash)
510
688
  expect(node.hash_size).to eq 2
511
689
  end
512
690
  end
513
691
 
514
- describe "hash_keys" do
515
- it "should get hash_keys for hash node" do
516
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
517
- expect(node.hash_keys).to eq ["first_name", "last_name"]
692
+ describe 'hash_keys' do
693
+ it 'should get hash_keys for hash node' do
694
+ node =
695
+ parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(
696
+ sexp_type: :hash
697
+ )
698
+ expect(node.hash_keys).to eq %w[first_name last_name]
518
699
  end
519
700
 
520
- it "should get hash_keys for bare_assoc_hash" do
521
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
522
- expect(node.hash_keys).to eq ["first_name", "last_name"]
701
+ it 'should get hash_keys for bare_assoc_hash' do
702
+ node =
703
+ parse_content(
704
+ "add_user :user, first_name: 'Richard', last_name: 'Huang'"
705
+ )
706
+ .grep_node(sexp_type: :bare_assoc_hash)
707
+ expect(node.hash_keys).to eq %w[first_name last_name]
523
708
  end
524
709
  end
525
710
 
526
- describe "hash_values" do
527
- it "should get hash_values for hash node" do
528
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
529
- expect(node.hash_values.map(&:to_s)).to eq ["Richard", "Huang"]
711
+ describe 'hash_values' do
712
+ it 'should get hash_values for hash node' do
713
+ node =
714
+ parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(
715
+ sexp_type: :hash
716
+ )
717
+ expect(node.hash_values.map(&:to_s)).to eq %w[Richard Huang]
530
718
  end
531
719
 
532
- it "should get hash_values for bare_assoc_hash" do
533
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
534
- expect(node.hash_values.map(&:to_s)).to eq ["Richard", "Huang"]
720
+ it 'should get hash_values for bare_assoc_hash' do
721
+ node =
722
+ parse_content(
723
+ "add_user :user, first_name: 'Richard', last_name: 'Huang'"
724
+ )
725
+ .grep_node(sexp_type: :bare_assoc_hash)
726
+ expect(node.hash_values.map(&:to_s)).to eq %w[Richard Huang]
535
727
  end
536
728
  end
537
729
 
538
- describe "array_size" do
539
- it "should get array size" do
540
- node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
730
+ describe 'array_size' do
731
+ it 'should get array size' do
732
+ node =
733
+ parse_content("['first_name', 'last_name']").grep_node(
734
+ sexp_type: :array
735
+ )
541
736
  expect(node.array_size).to eq 2
542
737
  end
543
738
 
544
- it "should get 0" do
545
- node = parse_content("[]").grep_node(sexp_type: :array)
739
+ it 'should get 0' do
740
+ node = parse_content('[]').grep_node(sexp_type: :array)
546
741
  expect(node.array_size).to eq 0
547
742
  end
548
743
  end
549
744
 
550
- describe "array_values" do
551
- it "should get array values" do
552
- node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
553
- expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
745
+ describe 'array_values' do
746
+ it 'should get array values' do
747
+ node =
748
+ parse_content("['first_name', 'last_name']").grep_node(
749
+ sexp_type: :array
750
+ )
751
+ expect(node.array_values.map(&:to_s)).to eq %w[first_name last_name]
554
752
  end
555
753
 
556
- it "should get empty array values" do
557
- node = parse_content("[]").grep_node(sexp_type: :array)
754
+ it 'should get empty array values' do
755
+ node = parse_content('[]').grep_node(sexp_type: :array)
558
756
  expect(node.array_values).to eq []
559
757
  end
560
758
 
561
- it "should get array value with array and words_add" do
562
- node = parse_content("%W{day week fortnight}").grep_node(sexp_type: :array)
563
- expect(node.array_values.map(&:to_s)).to eq ["day", "week", "fortnight"]
759
+ it 'should get array value with array and words_add' do
760
+ node =
761
+ parse_content('%W{day week fortnight}').grep_node(sexp_type: :array)
762
+ expect(node.array_values.map(&:to_s)).to eq %w[day week fortnight]
564
763
  end
565
764
 
566
- it "should get empty array values with array and words_add" do
567
- node = parse_content("%W{}").grep_node(sexp_type: :array)
765
+ it 'should get empty array values with array and words_add' do
766
+ node = parse_content('%W{}').grep_node(sexp_type: :array)
568
767
  expect(node.array_values.map(&:to_s)).to eq []
569
768
  end
570
769
 
571
- it "should get array value with array and qwords_add" do
572
- node = parse_content("%w(first_name last_name)").grep_node(sexp_type: :array)
573
- expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
770
+ it 'should get array value with array and qwords_add' do
771
+ node =
772
+ parse_content('%w(first_name last_name)').grep_node(sexp_type: :array)
773
+ expect(node.array_values.map(&:to_s)).to eq %w[first_name last_name]
574
774
  end
575
775
 
576
- it "should get empty array values with array and qwords_add" do
577
- node = parse_content("%w()").grep_node(sexp_type: :array)
776
+ it 'should get empty array values with array and qwords_add' do
777
+ node = parse_content('%w()').grep_node(sexp_type: :array)
578
778
  expect(node.array_values.map(&:to_s)).to eq []
579
779
  end
580
780
 
581
781
  if RUBY_VERSION.to_i > 1
582
- it "should get array value with array and symbols_add" do
583
- node = parse_content("%I(first_name last_name)").grep_node(sexp_type: :array)
584
- expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
782
+ it 'should get array value with array and symbols_add' do
783
+ node =
784
+ parse_content('%I(first_name last_name)').grep_node(sexp_type: :array)
785
+ expect(node.array_values.map(&:to_s)).to eq %w[first_name last_name]
585
786
  end
586
787
 
587
- it "should get empty array value with array and symbols_add" do
588
- node = parse_content("%I()").grep_node(sexp_type: :array)
788
+ it 'should get empty array value with array and symbols_add' do
789
+ node = parse_content('%I()').grep_node(sexp_type: :array)
589
790
  expect(node.array_values.map(&:to_s)).to eq []
590
791
  end
591
792
 
592
- it "should get array value with array and qsymbols_add" do
593
- node = parse_content("%i(first_name last_name)").grep_node(sexp_type: :array)
594
- expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
793
+ it 'should get array value with array and qsymbols_add' do
794
+ node =
795
+ parse_content('%i(first_name last_name)').grep_node(sexp_type: :array)
796
+ expect(node.array_values.map(&:to_s)).to eq %w[first_name last_name]
595
797
  end
596
798
 
597
- it "should get empty array values with array and qsymbols_new" do
598
- node = parse_content("%i()").grep_node(sexp_type: :array)
799
+ it 'should get empty array values with array and qsymbols_new' do
800
+ node = parse_content('%i()').grep_node(sexp_type: :array)
599
801
  expect(node.array_values.map(&:to_s)).to eq []
600
802
  end
601
803
  end
602
804
  end
603
805
 
604
- describe "alias" do
605
- context "method" do
806
+ describe 'alias' do
807
+ context 'method' do
606
808
  before do
607
- @node = parse_content("alias new old").grep_node(sexp_type: :alias)
809
+ @node = parse_content('alias new old').grep_node(sexp_type: :alias)
608
810
  end
609
811
 
610
- it "should get old_method" do
611
- expect(@node.old_method.to_s).to eq "old"
812
+ it 'should get old_method' do
813
+ expect(@node.old_method.to_s).to eq 'old'
612
814
  end
613
815
 
614
- it "should get new_method" do
615
- expect(@node.new_method.to_s).to eq "new"
816
+ it 'should get new_method' do
817
+ expect(@node.new_method.to_s).to eq 'new'
616
818
  end
617
819
  end
618
820
 
619
- context "symbol" do
821
+ context 'symbol' do
620
822
  before do
621
- @node = parse_content("alias :new :old").grep_node(sexp_type: :alias)
823
+ @node = parse_content('alias :new :old').grep_node(sexp_type: :alias)
622
824
  end
623
825
 
624
- it "should get old_method" do
625
- expect(@node.old_method.to_s).to eq "old"
826
+ it 'should get old_method' do
827
+ expect(@node.old_method.to_s).to eq 'old'
626
828
  end
627
829
 
628
- it "should get new_method" do
629
- expect(@node.new_method.to_s).to eq "new"
830
+ it 'should get new_method' do
831
+ expect(@node.new_method.to_s).to eq 'new'
630
832
  end
631
833
  end
632
834
  end
633
835
 
634
- describe "to_object" do
635
- it "should to array" do
636
- node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
637
- expect(node.to_object).to eq ["first_name", "last_name"]
836
+ describe 'to_object' do
837
+ it 'should to array' do
838
+ node =
839
+ parse_content("['first_name', 'last_name']").grep_node(
840
+ sexp_type: :array
841
+ )
842
+ expect(node.to_object).to eq %w[first_name last_name]
638
843
  end
639
844
 
640
- it "should to array with %w()" do
641
- node = parse_content("%w(new create)").grep_node(sexp_type: :array)
642
- expect(node.to_object).to eq ["new", "create"]
845
+ it 'should to array with %w()' do
846
+ node = parse_content('%w(new create)').grep_node(sexp_type: :array)
847
+ expect(node.to_object).to eq %w[new create]
643
848
  end
644
849
 
645
- it "should to array with symbols" do
646
- node = parse_content("[:first_name, :last_name]").grep_node(sexp_type: :array)
647
- expect(node.to_object).to eq ["first_name", "last_name"]
850
+ it 'should to array with symbols' do
851
+ node =
852
+ parse_content('[:first_name, :last_name]').grep_node(sexp_type: :array)
853
+ expect(node.to_object).to eq %w[first_name last_name]
648
854
  end
649
855
 
650
- it "should to empty array" do
651
- node = parse_content("[]").grep_node(sexp_type: :array)
856
+ it 'should to empty array' do
857
+ node = parse_content('[]').grep_node(sexp_type: :array)
652
858
  expect(node.to_object).to eq []
653
859
  end
654
860
 
655
- it "should to string" do
861
+ it 'should to string' do
656
862
  node = parse_content("'richard'").grep_node(sexp_type: :string_literal)
657
- expect(node.to_object).to eq "richard"
863
+ expect(node.to_object).to eq 'richard'
658
864
  end
659
865
  end
660
866
 
661
- describe "to_s" do
662
- it "should get to_s for string" do
867
+ describe 'to_s' do
868
+ it 'should get to_s for string' do
663
869
  node = parse_content("'user'").grep_node(sexp_type: :string_literal)
664
- expect(node.to_s).to eq "user"
870
+ expect(node.to_s).to eq 'user'
665
871
  end
666
872
 
667
- it "should get to_s for symbol" do
668
- node = parse_content(":user").grep_node(sexp_type: :symbol_literal)
669
- expect(node.to_s).to eq "user"
873
+ it 'should get to_s for symbol' do
874
+ node = parse_content(':user').grep_node(sexp_type: :symbol_literal)
875
+ expect(node.to_s).to eq 'user'
670
876
  end
671
877
 
672
- it "should get to_s for const" do
673
- node = parse_content("User").grep_node(sexp_type: :@const)
674
- expect(node.to_s).to eq "User"
878
+ it 'should get to_s for const' do
879
+ node = parse_content('User').grep_node(sexp_type: :@const)
880
+ expect(node.to_s).to eq 'User'
675
881
  end
676
882
 
677
- it "should get to_s for ivar" do
678
- node = parse_content("@user").grep_node(sexp_type: :@ivar)
679
- expect(node.to_s).to eq "@user"
883
+ it 'should get to_s for ivar' do
884
+ node = parse_content('@user').grep_node(sexp_type: :@ivar)
885
+ expect(node.to_s).to eq '@user'
680
886
  end
681
887
 
682
- it "should get to_s for class with module" do
683
- node = parse_content("ActiveRecord::Base").grep_node(sexp_type: :const_path_ref)
684
- expect(node.to_s).to eq "ActiveRecord::Base"
888
+ it 'should get to_s for class with module' do
889
+ node =
890
+ parse_content('ActiveRecord::Base').grep_node(
891
+ sexp_type: :const_path_ref
892
+ )
893
+ expect(node.to_s).to eq 'ActiveRecord::Base'
685
894
  end
686
895
 
687
- it "should get to_s for label" do
688
- node = parse_content("{first_name: 'Richard'}").grep_node(sexp_type: :@label)
689
- expect(node.to_s).to eq "first_name"
896
+ it 'should get to_s for label' do
897
+ node =
898
+ parse_content("{first_name: 'Richard'}").grep_node(sexp_type: :@label)
899
+ expect(node.to_s).to eq 'first_name'
690
900
  end
691
901
 
692
- it "should get to_s for call" do
693
- node = parse_content("current_user.post").grep_node(sexp_type: :call)
694
- expect(node.to_s).to eq "current_user.post"
902
+ it 'should get to_s for call' do
903
+ node = parse_content('current_user.post').grep_node(sexp_type: :call)
904
+ expect(node.to_s).to eq 'current_user.post'
695
905
  end
696
906
 
697
- it "should get to_s for top_const_ref" do
698
- node = parse_content("::User").grep_node(sexp_type: :top_const_ref)
699
- expect(node.to_s).to eq "::User"
907
+ it 'should get to_s for top_const_ref' do
908
+ node = parse_content('::User').grep_node(sexp_type: :top_const_ref)
909
+ expect(node.to_s).to eq '::User'
700
910
  end
701
911
  end
702
912
 
703
- describe "const?" do
704
- it "should return true for const with var_ref" do
705
- node = parse_content("User.find").grep_node(sexp_type: :var_ref)
913
+ describe 'const?' do
914
+ it 'should return true for const with var_ref' do
915
+ node = parse_content('User.find').grep_node(sexp_type: :var_ref)
706
916
  expect(node).to be_const
707
917
  end
708
918
 
709
- it "should return true for const with @const" do
710
- node = parse_content("User.find").grep_node(sexp_type: :@const)
919
+ it 'should return true for const with @const' do
920
+ node = parse_content('User.find').grep_node(sexp_type: :@const)
711
921
  expect(node).to be_const
712
922
  end
713
923
 
714
- it "should return false for ivar" do
715
- node = parse_content("@user.find").grep_node(sexp_type: :@ivar)
924
+ it 'should return false for ivar' do
925
+ node = parse_content('@user.find').grep_node(sexp_type: :@ivar)
716
926
  expect(node).not_to be_const
717
927
  end
718
928
  end
719
929
 
720
- describe "present?" do
721
- it "should return true" do
722
- node = parse_content("hello world")
930
+ describe 'present?' do
931
+ it 'should return true' do
932
+ node = parse_content('hello world')
723
933
  expect(node).to be_present
724
934
  end
725
935
  end
726
936
 
727
- describe "blank?" do
728
- it "should return false" do
729
- node = parse_content("hello world")
937
+ describe 'blank?' do
938
+ it 'should return false' do
939
+ node = parse_content('hello world')
730
940
  expect(node).not_to be_blank
731
941
  end
732
942
  end
733
943
 
734
- describe "remove_line_and_column" do
735
- it "should remove" do
736
- s(:@ident, "test", s(2, 12)).remove_line_and_column.should_equal s(:@ident, "test")
944
+ describe 'remove_line_and_column' do
945
+ it 'should remove' do
946
+ s(:@ident, 'test', s(2, 12)).remove_line_and_column.should_equal s(
947
+ :@ident,
948
+ 'test'
949
+ )
737
950
  end
738
951
 
739
- it "should remove child nodes" do
740
- s(:const_ref, s(:@const, "Demo", s(1, 12))).remove_line_and_column.should_equal s(:const_def, s(:@const, "Demo"))
952
+ it 'should remove child nodes' do
953
+ s(:const_ref, s(:@const, 'Demo', s(1, 12)))
954
+ .remove_line_and_column.should_equal s(:const_def, s(:@const, 'Demo'))
741
955
  end
742
956
  end
743
957
  end