code_analyzer 0.4.6 → 0.5.2

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