code_analyzer 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1313a9c7eebbf19bc331a99a0f809d7d3045b0d2
4
- data.tar.gz: b681f810a0971fb916cde01d97d80fbf78b1af0c
3
+ metadata.gz: 2853b6068c4e2ed70d3968b12fdd7cd7e012d1a1
4
+ data.tar.gz: 8baf7c2d33f0d38229171c111d5e6b78e3f1c457
5
5
  SHA512:
6
- metadata.gz: c32a12cedaa8586b3aa1398bc1e2da6226b426838c6a13b2bc95b9fc9f7a641d747d4cbdfb114d416d70e4f4f747f5496fad891ccd0f2a75248672e215f069ad
7
- data.tar.gz: 12bd4b30529bdbc137463836a9ccc813676ec128b2760685eef02e452d41ff279963c9853047f5135235ff2e825a4647fe31be0ccc6b685ffd6a748ba4873d6c
6
+ metadata.gz: 341df6c7d531dc8f208c8bb6930a1a0e63f1c6d9f5f654c15c7ff0a237c85eea200c4225140c1fd651eba2b42bde2720b8ce7318f8a9fa25d8694e0133d1111a
7
+ data.tar.gz: 68e901019d4d3a0d0b68120d5c6df966e6fe6540fdb335f1b0c5c1b254dced6853c7dda6174e1a784827c539a62f08f293c59f9011a2e8aac81005505f4bf56d
@@ -836,6 +836,8 @@ class Sexp
836
836
  "#{self[1]}[#{self[2]}]"
837
837
  when :call, :field
838
838
  "#{self.receiver}.#{self.message}"
839
+ when :top_const_ref
840
+ "::#{self[1]}"
839
841
  else
840
842
  ""
841
843
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module CodeAnalyzer
3
- VERSION = "0.4.4"
3
+ VERSION = "0.4.5"
4
4
  end
@@ -6,35 +6,35 @@ module CodeAnalyzer
6
6
 
7
7
  context "interesting_nodes" do
8
8
  it "should get empty interesting nodes" do
9
- checker.interesting_nodes.should == []
9
+ expect(checker.interesting_nodes).to eq []
10
10
  end
11
11
 
12
12
  it "should add interesting nodes" do
13
13
  Checker.interesting_nodes :class, :def
14
- checker.interesting_nodes.should == [:class, :def]
14
+ expect(checker.interesting_nodes).to eq [:class, :def]
15
15
  end
16
16
  end
17
17
 
18
18
  context "interesting_files" do
19
19
  it "should match none of interesting files" do
20
- checker.interesting_files.should == []
20
+ expect(checker.interesting_files).to eq []
21
21
  end
22
22
 
23
23
  it "should add interesting files" do
24
24
  Checker.interesting_files /lib/, /spec/
25
- checker.interesting_files.should == [/lib/, /spec/]
25
+ expect(checker.interesting_files).to eq [/lib/, /spec/]
26
26
  end
27
27
  end
28
28
 
29
29
  context "#parse_file?" do
30
30
  it "should return true if node_file matches pattern" do
31
- checker.stub(:interesting_files).and_return([/spec\/.*\.rb/, /lib\/.*\.rb/])
32
- checker.parse_file?("lib/code_analyzer.rb").should be_true
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
33
33
  end
34
34
 
35
35
  it "should return false if node_file doesn't match pattern" do
36
- checker.stub(:interesting_files).and_return([/spec\/.*\.rb/])
37
- checker.parse_file?("lib/code_analyzer.rb").should be_false
36
+ allow(checker).to receive(:interesting_files).and_return([/spec\/.*\.rb/])
37
+ expect(checker.parse_file?("lib/code_analyzer.rb")).to be_false
38
38
  end
39
39
  end
40
40
 
@@ -42,14 +42,14 @@ module CodeAnalyzer
42
42
  it "should add callback to start_call" do
43
43
  block = Proc.new {}
44
44
  Checker.add_callback(:start_call, &block)
45
- Checker.get_callbacks(:start_call).should == [block]
45
+ expect(Checker.get_callbacks(:start_call)).to eq [block]
46
46
  end
47
47
 
48
48
  it "should add callback to both start_class and end_class" do
49
49
  block = Proc.new {}
50
50
  Checker.add_callback(:start_class, :end_class, &block)
51
- Checker.get_callbacks(:start_class).should == [block]
52
- Checker.get_callbacks(:end_class).should == [block]
51
+ expect(Checker.get_callbacks(:start_class)).to eq [block]
52
+ expect(Checker.get_callbacks(:end_class)).to eq [block]
53
53
  end
54
54
 
55
55
  it "should add multiple callbacks to end_call" do
@@ -57,7 +57,7 @@ module CodeAnalyzer
57
57
  block2 = Proc.new {}
58
58
  Checker.add_callback(:end_call, &block1)
59
59
  Checker.add_callback(:end_call, &block2)
60
- Checker.get_callbacks(:end_call).should == [block1, block2]
60
+ expect(Checker.get_callbacks(:end_call)).to eq [block1, block2]
61
61
  end
62
62
  end
63
63
  end
@@ -5,11 +5,11 @@ module CodeAnalyzer
5
5
  describe Base do
6
6
  it "should return all checkers' warnings" do
7
7
  warning1 = Warning.new
8
- checker1 = mock(:checker, warnings: [warning1])
8
+ checker1 = double(:checker, warnings: [warning1])
9
9
  warning2 = Warning.new
10
- checker2 = mock(:checker, warnings: [warning2])
10
+ checker2 = double(:checker, warnings: [warning2])
11
11
  visitor = Base.new(checkers: [checker1, checker2])
12
- visitor.warnings.should == [warning1, warning2]
12
+ expect(visitor.warnings).to eq [warning1, warning2]
13
13
  end
14
14
  end
15
15
  end
@@ -2,19 +2,19 @@ require "spec_helper"
2
2
 
3
3
  module CodeAnalyzer::CheckingVisitor
4
4
  describe Default do
5
- let(:checker1) { mock(:checker, interesting_nodes: [:class, :def]) }
6
- let(:checker2) { mock(:checker, interesting_nodes: [:def, :call]) }
5
+ let(:checker1) { double(:checker, interesting_nodes: [:class, :def]) }
6
+ let(:checker2) { double(:checker, interesting_nodes: [:def, :call]) }
7
7
  let(:visitor) { Default.new(checkers: [checker1, checker2]) }
8
8
 
9
9
  it "should check def node by all checkers" do
10
10
  filename = "filename"
11
11
  content = "def test; end"
12
- checker1.stub(:parse_file?).with(filename).and_return(true)
13
- checker2.stub(:parse_file?).with(filename).and_return(true)
14
- checker1.should_receive(:node_start)
15
- checker1.should_receive(:node_end)
16
- checker2.should_receive(:node_start)
17
- checker2.should_receive(:node_end)
12
+ allow(checker1).to receive(:parse_file?).with(filename).and_return(true)
13
+ allow(checker2).to receive(:parse_file?).with(filename).and_return(true)
14
+ expect(checker1).to receive(:node_start)
15
+ expect(checker1).to receive(:node_end)
16
+ expect(checker2).to receive(:node_start)
17
+ expect(checker2).to receive(:node_end)
18
18
 
19
19
  visitor.check(filename, content)
20
20
  end
@@ -22,9 +22,9 @@ module CodeAnalyzer::CheckingVisitor
22
22
  it "should check class node by only checker1" do
23
23
  filename = "filename"
24
24
  content = "class Test; end"
25
- checker1.stub(:parse_file?).with(filename).and_return(true)
26
- checker1.should_receive(:node_start)
27
- checker1.should_receive(:node_end)
25
+ allow(checker1).to receive(:parse_file?).with(filename).and_return(true)
26
+ expect(checker1).to receive(:node_start)
27
+ expect(checker1).to receive(:node_end)
28
28
 
29
29
  visitor.check(filename, content)
30
30
  end
@@ -32,9 +32,9 @@ module CodeAnalyzer::CheckingVisitor
32
32
  it "should check call node by only checker2" do
33
33
  filename = "filename"
34
34
  content = "obj.message"
35
- checker2.stub(:parse_file?).with(filename).and_return(true)
36
- checker2.should_receive(:node_start)
37
- checker2.should_receive(:node_end)
35
+ allow(checker2).to receive(:parse_file?).with(filename).and_return(true)
36
+ expect(checker2).to receive(:node_start)
37
+ expect(checker2).to receive(:node_end)
38
38
 
39
39
  visitor.check(filename, content)
40
40
  end
@@ -2,17 +2,17 @@ require "spec_helper"
2
2
 
3
3
  module CodeAnalyzer::CheckingVisitor
4
4
  describe Plain do
5
- let(:checker1) { mock(:checker) }
6
- let(:checker2) { mock(:checker) }
5
+ let(:checker1) { double(:checker) }
6
+ let(:checker2) { double(:checker) }
7
7
  let(:visitor) { Plain.new(checkers: [checker1, checker2]) }
8
8
 
9
9
  it "should check by all checkers" do
10
10
  filename = "filename"
11
11
  content = "content"
12
- checker1.should_receive(:parse_file?).and_return(false)
13
- checker2.should_receive(:parse_file?).and_return(true)
12
+ expect(checker1).to receive(:parse_file?).and_return(false)
13
+ expect(checker2).to receive(:parse_file?).and_return(true)
14
14
  checker1.should_not_receive(:check).with(filename, content)
15
- checker2.should_receive(:check).with(filename, content)
15
+ expect(checker2).to receive(:check).with(filename, content)
16
16
 
17
17
  visitor.check(filename, content)
18
18
  end
@@ -6,31 +6,31 @@ module CodeAnalyzer
6
6
 
7
7
  context "to_s" do
8
8
  it "should return self" do
9
- core_nil.to_s.should == core_nil
9
+ expect(core_nil.to_s).to eq core_nil
10
10
  end
11
11
  end
12
12
 
13
13
  context "hash_size" do
14
14
  it "should return 0" do
15
- core_nil.hash_size.should == 0
15
+ expect(core_nil.hash_size).to eq 0
16
16
  end
17
17
  end
18
18
 
19
19
  context "method_missing" do
20
20
  it "should return self" do
21
- core_nil.undefined.should == core_nil
21
+ expect(core_nil.undefined).to eq core_nil
22
22
  end
23
23
  end
24
24
 
25
25
  context "present?" do
26
26
  it "should return false" do
27
- core_nil.should_not be_present
27
+ expect(core_nil).not_to be_present
28
28
  end
29
29
  end
30
30
 
31
31
  context "blank?" do
32
32
  it "should return true" do
33
- core_nil.should be_blank
33
+ expect(core_nil).to be_blank
34
34
  end
35
35
  end
36
36
  end
@@ -28,35 +28,35 @@ describe Sexp do
28
28
  end
29
29
 
30
30
  it "should return class line" do
31
- @node.grep_node(sexp_type: :class).line_number.should == 1
31
+ expect(@node.grep_node(sexp_type: :class).line_number).to eq 1
32
32
  end
33
33
 
34
34
  it "should return def line" do
35
- @node.grep_node(sexp_type: :def).line_number.should == 2
35
+ expect(@node.grep_node(sexp_type: :def).line_number).to eq 2
36
36
  end
37
37
 
38
38
  it "should return const line" do
39
- @node.grep_node(sexp_type: :const_ref).line_number.should == 1
39
+ expect(@node.grep_node(sexp_type: :const_ref).line_number).to eq 1
40
40
  end
41
41
 
42
42
  it "should return const path line" do
43
- @node.grep_node(sexp_type: :const_path_ref).line_number.should == 3
43
+ expect(@node.grep_node(sexp_type: :const_path_ref).line_number).to eq 3
44
44
  end
45
45
 
46
46
  it "should return alias line" do
47
- @node.grep_node(sexp_type: :alias).line_number.should == 5
47
+ expect(@node.grep_node(sexp_type: :alias).line_number).to eq 5
48
48
  end
49
49
 
50
50
  it "should return hash line" do
51
- @node.grep_node(sexp_type: :hash).line_number.should == 6
51
+ expect(@node.grep_node(sexp_type: :hash).line_number).to eq 6
52
52
  end
53
53
 
54
54
  it "should return massign line" do
55
- @node.grep_node(sexp_type: :massign).line_number.should == 8
55
+ expect(@node.grep_node(sexp_type: :massign).line_number).to eq 8
56
56
  end
57
57
 
58
58
  it "should return opassign line" do
59
- @node.grep_node(sexp_type: :opassign).line_number.should == 11
59
+ expect(@node.grep_node(sexp_type: :opassign).line_number).to eq 11
60
60
  end
61
61
 
62
62
  it "should return if line" do
@@ -86,9 +86,9 @@ describe Sexp do
86
86
  nodes = []
87
87
  @node.grep_nodes(sexp_type: :call, receiver: "current_user") { |node| nodes << node }
88
88
  if RUBY_VERSION == "1.9.2"
89
- nodes.should == [s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
89
+ expect(nodes).to eq [s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
90
90
  else
91
- nodes.should == [s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
91
+ expect(nodes).to eq [s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
92
92
  end
93
93
  end
94
94
 
@@ -96,9 +96,9 @@ describe Sexp do
96
96
  nodes = []
97
97
  @node.grep_nodes(sexp_type: :call, message: ["posts", "find"]) { |node| nodes << node }
98
98
  if RUBY_VERSION == "1.9.2"
99
- nodes.should == [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)))]
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
100
  else
101
- nodes.should == [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)))]
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
102
  end
103
103
  end
104
104
 
@@ -106,13 +106,13 @@ describe Sexp do
106
106
  it "should get the var_ref node with to_s" do
107
107
  nodes = []
108
108
  @node.grep_nodes(sexp_type: :var_ref, to_s: "current_user") { |node| nodes << node }
109
- nodes.should == [s(:var_ref, s(:@ident, "current_user", s(2, 8)))]
109
+ expect(nodes).to eq [s(:var_ref, s(:@ident, "current_user", s(2, 8)))]
110
110
  end
111
111
  else
112
112
  it "should get the vcall node with to_s" do
113
113
  nodes = []
114
114
  @node.grep_nodes(sexp_type: :vcall, to_s: "current_user") { |node| nodes << node }
115
- nodes.should == [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
115
+ expect(nodes).to eq [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
116
116
  end
117
117
  end
118
118
  end
@@ -130,9 +130,9 @@ describe Sexp do
130
130
  it "should get first node with empty argument" do
131
131
  node = @node.grep_node(sexp_type: :call, receiver: "current_user")
132
132
  if RUBY_VERSION == "1.9.2"
133
- node.should == s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
133
+ expect(node).to eq s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
134
134
  else
135
- node.should == s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
135
+ expect(node).to eq s(:call, s(:vcall, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
136
136
  end
137
137
  end
138
138
  end
@@ -148,7 +148,7 @@ describe Sexp do
148
148
  end
149
149
 
150
150
  it "should get the count of call nodes" do
151
- @node.grep_nodes_count(sexp_type: :call).should == 2
151
+ expect(@node.grep_nodes_count(sexp_type: :call)).to eq 2
152
152
  end
153
153
  end
154
154
 
@@ -156,24 +156,24 @@ describe Sexp do
156
156
  it "should get receiver of assign node" do
157
157
  node = parse_content("user.name = params[:name]").grep_node(sexp_type: :assign)
158
158
  receiver = node.receiver
159
- receiver.sexp_type.should == :field
160
- receiver.receiver.to_s.should == "user"
161
- receiver.message.to_s.should == "name"
159
+ 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"
162
162
  end
163
163
 
164
164
  it "should get receiver of field node" do
165
165
  node = parse_content("user.name = params[:name]").grep_node(sexp_type: :field)
166
- node.receiver.to_s.should == "user"
166
+ expect(node.receiver.to_s).to eq "user"
167
167
  end
168
168
 
169
169
  it "should get receiver of call node" do
170
170
  node = parse_content("user.name").grep_node(sexp_type: :call)
171
- node.receiver.to_s.should == "user"
171
+ expect(node.receiver.to_s).to eq "user"
172
172
  end
173
173
 
174
174
  it "should get receiver of binary" do
175
175
  node = parse_content("user == 'user_name'").grep_node(sexp_type: :binary)
176
- node.receiver.to_s.should == "user"
176
+ expect(node.receiver.to_s).to eq "user"
177
177
  end
178
178
 
179
179
  it "should get receiver of command_call" do
@@ -182,149 +182,149 @@ describe Sexp do
182
182
  end
183
183
  EOF
184
184
  node = parse_content(content).grep_node(sexp_type: :command_call)
185
- node.receiver.to_s.should == "map"
185
+ expect(node.receiver.to_s).to eq "map"
186
186
  end
187
187
 
188
188
  it "should get receiver of method_add_arg" do
189
189
  node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
190
- node.receiver.to_s.should == "Post"
190
+ expect(node.receiver.to_s).to eq "Post"
191
191
  end
192
192
 
193
193
  it "should get receiver of method_add_block" do
194
194
  node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
195
- node.receiver.to_s.should == "Post"
195
+ expect(node.receiver.to_s).to eq "Post"
196
196
  end
197
197
  end
198
198
 
199
199
  describe "module_name" do
200
200
  it "should get module name of module node" do
201
201
  node = parse_content("module Admin; end").grep_node(sexp_type: :module)
202
- node.module_name.to_s.should == "Admin"
202
+ expect(node.module_name.to_s).to eq "Admin"
203
203
  end
204
204
  end
205
205
 
206
206
  describe "class_name" do
207
207
  it "should get class name of class node" do
208
208
  node = parse_content("class User; end").grep_node(sexp_type: :class)
209
- node.class_name.to_s.should == "User"
209
+ expect(node.class_name.to_s).to eq "User"
210
210
  end
211
211
  end
212
212
 
213
213
  describe "base_class" do
214
214
  it "should get base class of class node" do
215
215
  node = parse_content("class User < ActiveRecord::Base; end").grep_node(sexp_type: :class)
216
- node.base_class.to_s.should == "ActiveRecord::Base"
216
+ expect(node.base_class.to_s).to eq "ActiveRecord::Base"
217
217
  end
218
218
  end
219
219
 
220
220
  describe "left_value" do
221
221
  it "should get the left value of assign" do
222
222
  node = parse_content("user = current_user").grep_node(sexp_type: :assign)
223
- node.left_value.to_s.should == "user"
223
+ expect(node.left_value.to_s).to eq "user"
224
224
  end
225
225
  end
226
226
 
227
227
  describe "right_value" do
228
228
  it "should get the right value of assign" do
229
229
  node = parse_content("user = current_user").grep_node(sexp_type: :assign)
230
- node.right_value.to_s.should == "current_user"
230
+ expect(node.right_value.to_s).to eq "current_user"
231
231
  end
232
232
  end
233
233
 
234
234
  describe "message" do
235
235
  it "should get the message of command" do
236
236
  node = parse_content("has_many :projects").grep_node(sexp_type: :command)
237
- node.message.to_s.should == "has_many"
237
+ expect(node.message.to_s).to eq "has_many"
238
238
  end
239
239
 
240
240
  it "should get the message of command_call" do
241
241
  node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
242
- node.message.to_s.should == "resources"
242
+ expect(node.message.to_s).to eq "resources"
243
243
  end
244
244
 
245
245
  it "should get the message of field" do
246
246
  node = parse_content("user.name = 'test'").grep_node(sexp_type: :field)
247
- node.message.to_s.should == "name"
247
+ expect(node.message.to_s).to eq "name"
248
248
  end
249
249
 
250
250
  it "should get the message of call" do
251
251
  node = parse_content("user.name").grep_node(sexp_type: :call)
252
- node.message.to_s.should == "name"
252
+ expect(node.message.to_s).to eq "name"
253
253
  end
254
254
 
255
255
  it "should get the message of binary" do
256
256
  node = parse_content("user.name == 'test'").grep_node(sexp_type: :binary)
257
- node.message.to_s.should == "=="
257
+ expect(node.message.to_s).to eq "=="
258
258
  end
259
259
 
260
260
  it "should get the message of fcall" do
261
261
  node = parse_content("test?('world')").grep_node(sexp_type: :fcall)
262
- node.message.to_s.should == "test?"
262
+ expect(node.message.to_s).to eq "test?"
263
263
  end
264
264
 
265
265
  it "should get the message of method_add_arg" do
266
266
  node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
267
- node.message.to_s.should == "find"
267
+ expect(node.message.to_s).to eq "find"
268
268
  end
269
269
 
270
270
  it "should get the message of method_add_block" do
271
271
  node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
272
- node.message.to_s.should == "save"
272
+ expect(node.message.to_s).to eq "save"
273
273
  end
274
274
  end
275
275
 
276
276
  describe "arguments" do
277
277
  it "should get the arguments of command" do
278
278
  node = parse_content("resources :posts do; end").grep_node(sexp_type: :command)
279
- node.arguments.sexp_type.should == :args_add_block
279
+ expect(node.arguments.sexp_type).to eq :args_add_block
280
280
  end
281
281
 
282
282
  it "should get the arguments of command_call" do
283
283
  node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
284
- node.arguments.sexp_type.should == :args_add_block
284
+ expect(node.arguments.sexp_type).to eq :args_add_block
285
285
  end
286
286
 
287
287
  it "should get the arguments of method_add_arg" do
288
288
  node = parse_content("User.find(:all)").grep_node(sexp_type: :method_add_arg)
289
- node.arguments.sexp_type.should == :args_add_block
289
+ expect(node.arguments.sexp_type).to eq :args_add_block
290
290
  end
291
291
 
292
292
  it "should get the arguments of method_add_block" do
293
293
  node = parse_content("Post.save(false) do; end").grep_node(sexp_type: :method_add_block)
294
- node.arguments.sexp_type.should == :args_add_block
294
+ expect(node.arguments.sexp_type).to eq :args_add_block
295
295
  end
296
296
  end
297
297
 
298
298
  describe "argument" do
299
299
  it "should get the argument of binary" do
300
300
  node = parse_content("user == current_user").grep_node(sexp_type: :binary)
301
- node.argument.to_s.should == "current_user"
301
+ expect(node.argument.to_s).to eq "current_user"
302
302
  end
303
303
  end
304
304
 
305
305
  describe "all" do
306
306
  it "should get all arguments" do
307
307
  node = parse_content("puts 'hello', 'world'").grep_node(sexp_type: :args_add_block)
308
- node.all.map(&:to_s).should == ["hello", "world"]
308
+ expect(node.all.map(&:to_s)).to eq ["hello", "world"]
309
309
  end
310
310
 
311
311
  it "should get all arguments with &:" do
312
312
  node = parse_content("user.posts.map(&:title)").grep_node(sexp_type: :args_add_block)
313
- node.all.map(&:to_s).should == ["title"]
313
+ expect(node.all.map(&:to_s)).to eq ["title"]
314
314
  end
315
315
 
316
316
  it "should get all arguments with command_call node" do
317
317
  node = parse_content("options_for_select(Account.get_business current_user)").grep_node(sexp_type: :args_add)
318
318
  if RUBY_VERSION == "1.9.2"
319
- node.all.should == [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))]
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
320
  else
321
- node.all.should == [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))]
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
322
  end
323
323
  end
324
324
 
325
325
  it "no error for args_add_star" do
326
326
  node = parse_content("send(:\"\#{route}_url\", *args)").grep_node(sexp_type: :args_add_block)
327
- lambda { node.all }.should_not raise_error
327
+ expect { node.all }.not_to raise_error
328
328
  end
329
329
  end
330
330
 
@@ -363,41 +363,41 @@ describe Sexp do
363
363
  describe "all_conditions" do
364
364
  it "should get all conditions" do
365
365
  node = parse_content("user == current_user && user.valid? || user.admin?").grep_node(sexp_type: :binary)
366
- node.all_conditions.size.should == 3
366
+ expect(node.all_conditions.size).to eq 3
367
367
  end
368
368
  end
369
369
 
370
370
  describe "method_name" do
371
371
  it "should get the method name of def" do
372
372
  node = parse_content("def show; end").grep_node(sexp_type: :def)
373
- node.method_name.to_s.should == "show"
373
+ expect(node.method_name.to_s).to eq "show"
374
374
  end
375
375
 
376
376
  it "should get the method name of defs" do
377
377
  node = parse_content("def self.find; end").grep_node(sexp_type: :defs)
378
- node.method_name.to_s.should == "find"
378
+ expect(node.method_name.to_s).to eq "find"
379
379
  end
380
380
  end
381
381
 
382
382
  describe "body" do
383
383
  it "should get body of class" do
384
384
  node = parse_content("class User; end").grep_node(sexp_type: :class)
385
- node.body.sexp_type.should == :bodystmt
385
+ expect(node.body.sexp_type).to eq :bodystmt
386
386
  end
387
387
 
388
388
  it "should get body of def" do
389
389
  node = parse_content("def login; end").grep_node(sexp_type: :def)
390
- node.body.sexp_type.should == :bodystmt
390
+ expect(node.body.sexp_type).to eq :bodystmt
391
391
  end
392
392
 
393
393
  it "should get body of defs" do
394
394
  node = parse_content("def self.login; end").grep_node(sexp_type: :defs)
395
- node.body.sexp_type.should == :bodystmt
395
+ expect(node.body.sexp_type).to eq :bodystmt
396
396
  end
397
397
 
398
398
  it "should get body of module" do
399
399
  node = parse_content("module Enumerable; end").grep_node(sexp_type: :module)
400
- node.body.sexp_type.should == :bodystmt
400
+ expect(node.body.sexp_type).to eq :bodystmt
401
401
  end
402
402
 
403
403
  it "should get body of if" do
@@ -439,139 +439,139 @@ describe Sexp do
439
439
  describe "block" do
440
440
  it "sould get block of method_add_block node" do
441
441
  node = parse_content("resources :posts do; resources :comments; end").grep_node(sexp_type: :method_add_block)
442
- node.block_node.sexp_type.should == :do_block
442
+ expect(node.block_node.sexp_type).to eq :do_block
443
443
  end
444
444
  end
445
445
 
446
446
  describe "statements" do
447
447
  it "should get statements of do_block node" do
448
448
  node = parse_content("resources :posts do; resources :comments; resources :like; end").grep_node(sexp_type: :do_block)
449
- node.statements.size.should == 2
449
+ expect(node.statements.size).to eq 2
450
450
  end
451
451
 
452
452
  it "should get statements of bodystmt node" do
453
453
  node = parse_content("class User; def login?; end; def admin?; end; end").grep_node(sexp_type: :bodystmt)
454
- node.statements.size.should == 2
454
+ expect(node.statements.size).to eq 2
455
455
  end
456
456
  end
457
457
 
458
458
  describe "exception_classes" do
459
459
  it "should get exception classes of rescue node" do
460
460
  node = parse_content("def test; rescue CustomException; end").grep_node(sexp_type: :rescue)
461
- node.exception_classes.first.to_s.should == "CustomException"
461
+ expect(node.exception_classes.first.to_s).to eq "CustomException"
462
462
  end
463
463
 
464
464
  it "should get empty of empty rescue node" do
465
465
  node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
466
- node.exception_classes.first.to_s.should == ""
466
+ expect(node.exception_classes.first.to_s).to eq ""
467
467
  end
468
468
 
469
469
  it "should get exception classes of rescue node for multiple exceptions" do
470
470
  node = parse_content("def test; rescue StandardError, CustomException; end").grep_node(sexp_type: :rescue)
471
- node.exception_classes.first.to_s.should == "StandardError"
472
- node.exception_classes.last.to_s.should == "CustomException"
471
+ expect(node.exception_classes.first.to_s).to eq "StandardError"
472
+ expect(node.exception_classes.last.to_s).to eq "CustomException"
473
473
  end
474
474
  end
475
475
 
476
476
  describe "exception_variable" do
477
477
  it "should get exception varible of rescue node" do
478
478
  node = parse_content("def test; rescue => e; end").grep_node(sexp_type: :rescue)
479
- node.exception_variable.to_s.should == "e"
479
+ expect(node.exception_variable.to_s).to eq "e"
480
480
  end
481
481
 
482
482
  it "should get empty of empty rescue node" do
483
483
  node = parse_content("def test; rescue; end").grep_node(sexp_type: :rescue)
484
- node.exception_variable.to_s.should == ""
484
+ expect(node.exception_variable.to_s).to eq ""
485
485
  end
486
486
  end
487
487
 
488
488
  describe "hash_value" do
489
489
  it "should get value for hash node" do
490
490
  node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
491
- node.hash_value("first_name").to_s.should == "Richard"
492
- node.hash_value("last_name").to_s.should == "Huang"
491
+ expect(node.hash_value("first_name").to_s).to eq "Richard"
492
+ expect(node.hash_value("last_name").to_s).to eq "Huang"
493
493
  end
494
494
 
495
495
  it "should get value for bare_assoc_hash" do
496
496
  node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
497
- node.hash_value("first_name").to_s.should == "Richard"
498
- node.hash_value("last_name").to_s.should == "Huang"
497
+ expect(node.hash_value("first_name").to_s).to eq "Richard"
498
+ expect(node.hash_value("last_name").to_s).to eq "Huang"
499
499
  end
500
500
  end
501
501
 
502
502
  describe "hash_size" do
503
503
  it "should get value for hash node" do
504
504
  node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
505
- node.hash_size.should == 2
505
+ expect(node.hash_size).to eq 2
506
506
  end
507
507
 
508
508
  it "should get value for bare_assoc_hash" do
509
509
  node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
510
- node.hash_size.should == 2
510
+ expect(node.hash_size).to eq 2
511
511
  end
512
512
  end
513
513
 
514
514
  describe "hash_keys" do
515
515
  it "should get hash_keys for hash node" do
516
516
  node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
517
- node.hash_keys.should == ["first_name", "last_name"]
517
+ expect(node.hash_keys).to eq ["first_name", "last_name"]
518
518
  end
519
519
 
520
520
  it "should get hash_keys for bare_assoc_hash" do
521
521
  node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
522
- node.hash_keys.should == ["first_name", "last_name"]
522
+ expect(node.hash_keys).to eq ["first_name", "last_name"]
523
523
  end
524
524
  end
525
525
 
526
526
  describe "hash_values" do
527
527
  it "should get hash_values for hash node" do
528
528
  node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
529
- node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
529
+ expect(node.hash_values.map(&:to_s)).to eq ["Richard", "Huang"]
530
530
  end
531
531
 
532
532
  it "should get hash_values for bare_assoc_hash" do
533
533
  node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
534
- node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
534
+ expect(node.hash_values.map(&:to_s)).to eq ["Richard", "Huang"]
535
535
  end
536
536
  end
537
537
 
538
538
  describe "array_size" do
539
539
  it "should get array size" do
540
540
  node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
541
- node.array_size.should == 2
541
+ expect(node.array_size).to eq 2
542
542
  end
543
543
 
544
544
  it "should get 0" do
545
545
  node = parse_content("[]").grep_node(sexp_type: :array)
546
- node.array_size.should == 0
546
+ expect(node.array_size).to eq 0
547
547
  end
548
548
  end
549
549
 
550
550
  describe "array_values" do
551
551
  it "should get array values" do
552
552
  node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
553
- node.array_values.map(&:to_s).should == ["first_name", "last_name"]
553
+ expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
554
554
  end
555
555
 
556
556
  it "should get empty array values" do
557
557
  node = parse_content("[]").grep_node(sexp_type: :array)
558
- node.array_values.should == []
558
+ expect(node.array_values).to eq []
559
559
  end
560
560
 
561
561
  it "should get array value with array and words_add" do
562
562
  node = parse_content("%W{day week fortnight}").grep_node(sexp_type: :array)
563
- node.array_values.map(&:to_s).should == ["day", "week", "fortnight"]
563
+ expect(node.array_values.map(&:to_s)).to eq ["day", "week", "fortnight"]
564
564
  end
565
565
 
566
566
  it "should get array value with array and qwords_add" do
567
567
  node = parse_content("%w(first_name last_name)").grep_node(sexp_type: :array)
568
- node.array_values.map(&:to_s).should == ["first_name", "last_name"]
568
+ expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
569
569
  end
570
570
 
571
571
  if RUBY_VERSION.to_i > 1
572
572
  it "should get array value with array and qsymbols_add" do
573
573
  node = parse_content("%i(first_name last_name)").grep_node(sexp_type: :array)
574
- node.array_values.map(&:to_s).should == ["first_name", "last_name"]
574
+ expect(node.array_values.map(&:to_s)).to eq ["first_name", "last_name"]
575
575
  end
576
576
  end
577
577
  end
@@ -583,11 +583,11 @@ describe Sexp do
583
583
  end
584
584
 
585
585
  it "should get old_method" do
586
- @node.old_method.to_s.should == "old"
586
+ expect(@node.old_method.to_s).to eq "old"
587
587
  end
588
588
 
589
589
  it "should get new_method" do
590
- @node.new_method.to_s.should == "new"
590
+ expect(@node.new_method.to_s).to eq "new"
591
591
  end
592
592
  end
593
593
 
@@ -597,11 +597,11 @@ describe Sexp do
597
597
  end
598
598
 
599
599
  it "should get old_method" do
600
- @node.old_method.to_s.should == "old"
600
+ expect(@node.old_method.to_s).to eq "old"
601
601
  end
602
602
 
603
603
  it "should get new_method" do
604
- @node.new_method.to_s.should == "new"
604
+ expect(@node.new_method.to_s).to eq "new"
605
605
  end
606
606
  end
607
607
  end
@@ -609,95 +609,100 @@ describe Sexp do
609
609
  describe "to_object" do
610
610
  it "should to array" do
611
611
  node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
612
- node.to_object.should == ["first_name", "last_name"]
612
+ expect(node.to_object).to eq ["first_name", "last_name"]
613
613
  end
614
614
 
615
615
  it "should to array with %w()" do
616
616
  node = parse_content("%w(new create)").grep_node(sexp_type: :array)
617
- node.to_object.should == ["new", "create"]
617
+ expect(node.to_object).to eq ["new", "create"]
618
618
  end
619
619
 
620
620
  it "should to array with symbols" do
621
621
  node = parse_content("[:first_name, :last_name]").grep_node(sexp_type: :array)
622
- node.to_object.should == ["first_name", "last_name"]
622
+ expect(node.to_object).to eq ["first_name", "last_name"]
623
623
  end
624
624
 
625
625
  it "should to empty array" do
626
626
  node = parse_content("[]").grep_node(sexp_type: :array)
627
- node.to_object.should == []
627
+ expect(node.to_object).to eq []
628
628
  end
629
629
 
630
630
  it "should to string" do
631
631
  node = parse_content("'richard'").grep_node(sexp_type: :string_literal)
632
- node.to_object.should == "richard"
632
+ expect(node.to_object).to eq "richard"
633
633
  end
634
634
  end
635
635
 
636
636
  describe "to_s" do
637
637
  it "should get to_s for string" do
638
638
  node = parse_content("'user'").grep_node(sexp_type: :string_literal)
639
- node.to_s.should == "user"
639
+ expect(node.to_s).to eq "user"
640
640
  end
641
641
 
642
642
  it "should get to_s for symbol" do
643
643
  node = parse_content(":user").grep_node(sexp_type: :symbol_literal)
644
- node.to_s.should == "user"
644
+ expect(node.to_s).to eq "user"
645
645
  end
646
646
 
647
647
  it "should get to_s for const" do
648
648
  node = parse_content("User").grep_node(sexp_type: :@const)
649
- node.to_s.should == "User"
649
+ expect(node.to_s).to eq "User"
650
650
  end
651
651
 
652
652
  it "should get to_s for ivar" do
653
653
  node = parse_content("@user").grep_node(sexp_type: :@ivar)
654
- node.to_s.should == "@user"
654
+ expect(node.to_s).to eq "@user"
655
655
  end
656
656
 
657
657
  it "should get to_s for class with module" do
658
658
  node = parse_content("ActiveRecord::Base").grep_node(sexp_type: :const_path_ref)
659
- node.to_s.should == "ActiveRecord::Base"
659
+ expect(node.to_s).to eq "ActiveRecord::Base"
660
660
  end
661
661
 
662
662
  it "should get to_s for label" do
663
663
  node = parse_content("{first_name: 'Richard'}").grep_node(sexp_type: :@label)
664
- node.to_s.should == "first_name"
664
+ expect(node.to_s).to eq "first_name"
665
665
  end
666
666
 
667
667
  it "should get to_s for call" do
668
668
  node = parse_content("current_user.post").grep_node(sexp_type: :call)
669
- node.to_s.should == "current_user.post"
669
+ expect(node.to_s).to eq "current_user.post"
670
+ end
671
+
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"
670
675
  end
671
676
  end
672
677
 
673
678
  describe "const?" do
674
679
  it "should return true for const with var_ref" do
675
680
  node = parse_content("User.find").grep_node(sexp_type: :var_ref)
676
- node.should be_const
681
+ expect(node).to be_const
677
682
  end
678
683
 
679
684
  it "should return true for const with @const" do
680
685
  node = parse_content("User.find").grep_node(sexp_type: :@const)
681
- node.should be_const
686
+ expect(node).to be_const
682
687
  end
683
688
 
684
689
  it "should return false for ivar" do
685
690
  node = parse_content("@user.find").grep_node(sexp_type: :@ivar)
686
- node.should_not be_const
691
+ expect(node).not_to be_const
687
692
  end
688
693
  end
689
694
 
690
695
  describe "present?" do
691
696
  it "should return true" do
692
697
  node = parse_content("hello world")
693
- node.should be_present
698
+ expect(node).to be_present
694
699
  end
695
700
  end
696
701
 
697
702
  describe "blank?" do
698
703
  it "should return false" do
699
704
  node = parse_content("hello world")
700
- node.should_not be_blank
705
+ expect(node).not_to be_blank
701
706
  end
702
707
  end
703
708
 
@@ -3,10 +3,11 @@ require 'spec_helper'
3
3
  module CodeAnalyzer
4
4
  describe Warning do
5
5
  it "should return error with filename, line number and message" do
6
- Warning.new(
7
- filename: "app/models/user.rb",
8
- line_number: "100",
9
- message: "not good").to_s.should == "app/models/user.rb:100 - not good"
6
+
7
+ expect(Warning.new(
8
+ filename: "app/models/user.rb",
9
+ line_number: "100",
10
+ message: "not good").to_s).to eq "app/models/user.rb:100 - not good"
10
11
  end
11
12
  end
12
13
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: a code analyzer tool which extracted from rails_best_practices, it helps
@@ -60,11 +60,9 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .rspec
65
- - .ruby-gemset
66
- - .ruby-version
67
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
68
66
  - Gemfile
69
67
  - LICENSE
70
68
  - README.md
@@ -99,17 +97,17 @@ require_paths:
99
97
  - lib
100
98
  required_ruby_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
- - - '>='
100
+ - - ">="
103
101
  - !ruby/object:Gem::Version
104
102
  version: '0'
105
103
  required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
- - - '>='
105
+ - - ">="
108
106
  - !ruby/object:Gem::Version
109
107
  version: '0'
110
108
  requirements: []
111
109
  rubyforge_project:
112
- rubygems_version: 2.0.14
110
+ rubygems_version: 2.2.0.rc.1
113
111
  signing_key:
114
112
  specification_version: 4
115
113
  summary: a code analyzer helps you build your own code analyzer tool.
@@ -1 +0,0 @@
1
- code_analyzer
@@ -1 +0,0 @@
1
- ruby-2.0.0