Skip to content

Commit d6512a0

Browse files
committed
Convert suite to rspec
1 parent efb8e76 commit d6512a0

File tree

7 files changed

+72
-72
lines changed

7 files changed

+72
-72
lines changed

Gemfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ gem "safe_yaml"
77
gem "pry", require: false
88

99
group :test do
10-
gem "mocha"
1110
gem "rake"
12-
gem "minitest"
13-
gem "minitest-reporters"
11+
gem "rspec"
1412
end

Gemfile.lock

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ GEM
77
minitest (~> 5.1)
88
thread_safe (~> 0.3, >= 0.3.4)
99
tzinfo (~> 1.1)
10-
ansi (1.5.0)
1110
ast (2.2.0)
12-
builder (3.2.2)
1311
coderay (1.1.0)
12+
diff-lcs (1.2.5)
1413
i18n (0.7.0)
1514
json (1.8.3)
16-
metaclass (0.0.4)
1715
method_source (0.8.2)
1816
minitest (5.8.4)
19-
minitest-reporters (1.1.7)
20-
ansi
21-
builder
22-
minitest (>= 5.0)
23-
ruby-progressbar
24-
mocha (1.1.0)
25-
metaclass (~> 0.0.1)
2617
parser (2.3.0.2)
2718
ast (~> 2.2)
2819
powerpack (0.1.1)
@@ -32,6 +23,19 @@ GEM
3223
slop (~> 3.4)
3324
rainbow (2.1.0)
3425
rake (10.5.0)
26+
rspec (3.3.0)
27+
rspec-core (~> 3.3.0)
28+
rspec-expectations (~> 3.3.0)
29+
rspec-mocks (~> 3.3.0)
30+
rspec-core (3.3.1)
31+
rspec-support (~> 3.3.0)
32+
rspec-expectations (3.3.0)
33+
diff-lcs (>= 1.2.0, < 2.0)
34+
rspec-support (~> 3.3.0)
35+
rspec-mocks (3.3.1)
36+
diff-lcs (>= 1.2.0, < 2.0)
37+
rspec-support (~> 3.3.0)
38+
rspec-support (3.3.0)
3539
rubocop (0.36.0)
3640
parser (>= 2.3.0.0, < 3.0)
3741
powerpack (~> 0.1)
@@ -50,11 +54,9 @@ PLATFORMS
5054

5155
DEPENDENCIES
5256
activesupport
53-
minitest
54-
minitest-reporters
55-
mocha
5657
pry
5758
rake
59+
rspec
5860
rubocop (~> 0.36.0)
5961
rubocop-rspec
6062
safe_yaml

Rakefile

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
require 'rake/testtask'
1+
require "rspec/core/rake_task"
22

3-
Rake.add_rakelib 'lib/tasks'
4-
5-
Rake::TestTask.new do |t|
6-
t.test_files = Dir.glob('spec/**/*_spec.rb')
7-
t.libs = %w[lib spec]
8-
end
9-
10-
task(default: :test)
3+
Rake.add_rakelib "lib/tasks"
4+
RSpec::Core::RakeTask.new(:spec)
5+
task default: :spec

spec/cc/engine/category_parser_spec.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33

44
module CC::Engine
55
describe CategoryParser do
6-
it "returns a category for the cop name" do
7-
CategoryParser.new("Rails/Delegate").category.must_equal("Clarity")
6+
it "returns the category mapped to the full cop name if present" do
7+
category_parser = CategoryParser.new("Rails/Delegate")
8+
9+
expect(category_parser.category).to eq("Clarity")
810
end
911

10-
it "returns a category for the cop" do
11-
CategoryParser.new("Performance/Sup").category.must_equal("BugRisk")
12+
it "returns the category mapped to the cop category if present" do
13+
category_parser = CategoryParser.new("Rails/ScopeArgs")
14+
15+
expect(category_parser.category).to eq("BugRisk")
1216
end
1317

14-
it "returns a default" do
15-
CategoryParser.new("Sup").category.must_equal("Style")
18+
it "returns Style as the default" do
19+
category_parser = CategoryParser.new("Pretend")
20+
21+
expect(category_parser.category).to eq("Style")
1622
end
1723
end
1824
end

spec/cc/engine/issue_spec.rb

+4-12
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ module CC::Engine
1515
offense = OpenStruct.new
1616
offense.cop_name = "Metrics/BlockNesting"
1717
offense.message = "This has no multiplier"
18-
1918
issue = Issue.new(offense, "/code/file", cop_list: cop_list)
2019

21-
issue.remediation_points.must_equal(300_000)
20+
expect(issue.remediation_points).to eq(300_000)
2221
end
2322
end
2423

@@ -33,13 +32,11 @@ module CC::Engine
3332
offense = OpenStruct.new
3433
offense.cop_name = "Metrics/AbcSize"
3534
offense.message = "This has a [32/20] multiplier"
36-
3735
issue = Issue.new(offense, "/code/file", cop_list: cop_list)
38-
3936
base_points = 5_000_000
4037
overage_points = 100_000 * 12
4138

42-
issue.remediation_points.must_equal(base_points + overage_points)
39+
expect(issue.remediation_points).to eq(base_points + overage_points)
4340
end
4441
end
4542
end
@@ -50,12 +47,9 @@ module CC::Engine
5047
offense = OpenStruct.new
5148
offense.cop_name = "Some/UnconfiguredCop"
5249
offense.message = "This has no multiplier"
53-
5450
issue = Issue.new(offense, "/code/file.rb")
5551

56-
issue.remediation_points.must_equal(
57-
Issue::DEFAULT_REMEDIATION_POINTS
58-
)
52+
expect(issue.remediation_points).to eq(Issue::DEFAULT_REMEDIATION_POINTS)
5953
end
6054
end
6155

@@ -64,13 +58,11 @@ module CC::Engine
6458
offense = OpenStruct.new
6559
offense.cop_name = "Some/UnconfiguredCop"
6660
offense.message = "This has a [22/20] multiplier"
67-
6861
issue = Issue.new(offense, "/code/file")
69-
7062
base_points = Issue::DEFAULT_BASE_POINTS
7163
overage_points = Issue::DEFAULT_OVERAGE_POINTS * 2
7264

73-
issue.remediation_points.must_equal(base_points + overage_points)
65+
expect(issue.remediation_points).to eq(base_points + overage_points)
7466
end
7567
end
7668
end

spec/cc/engine/rubocop_spec.rb

+35-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def method
1818

1919
output = run_engine
2020

21-
assert includes_check?(output, "Lint/UselessAssignment")
21+
expect(includes_check?(output, "Lint/UselessAssignment")).to be true
2222
end
2323

2424
it "reads the configured ruby_style file" do
@@ -38,8 +38,8 @@ def method
3838
config = { "config" => "rubocop.yml" }
3939
output = run_engine(config)
4040

41-
assert includes_check?(output, "Style/AndOr")
42-
assert !includes_check?(output, "Lint/UselessAssignment")
41+
expect(includes_check?(output, "Style/AndOr")).to be true
42+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
4343
end
4444

4545
it "respects the default .rubocop.yml file" do
@@ -58,8 +58,8 @@ def method
5858

5959
output = run_engine
6060

61-
assert includes_check?(output, "Style/AndOr")
62-
assert !includes_check?(output, "Lint/UselessAssignment")
61+
expect(includes_check?(output, "Style/AndOr")).to be true
62+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
6363
end
6464

6565
it "reads a file with a #!.*ruby declaration at the top" do
@@ -73,7 +73,8 @@ def method
7373
end
7474
EORUBY
7575
output = run_engine
76-
assert includes_check?(output, "Lint/UselessAssignment")
76+
77+
expect(includes_check?(output, "Lint/UselessAssignment")).to be true
7778
end
7879

7980
it "uses excludes from the specified YAML config" do
@@ -92,7 +93,8 @@ def method
9293
)
9394
config = { "config" => "rubocop.yml" }
9495
output = run_engine(config)
95-
assert !includes_check?(output, "Lint/UselessAssignment")
96+
97+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
9698
end
9799

98100
it "uses exclusions passed in via the config hash" do
@@ -107,7 +109,8 @@ def method
107109
EORUBY
108110
config = { "exclude_paths" => ["my_script"] }
109111
output = run_engine(config)
110-
assert !includes_check?(output, "Lint/UselessAssignment")
112+
113+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
111114
end
112115

113116
it "layers config exclusions on top of the YAML config" do
@@ -129,11 +132,12 @@ def method
129132
)
130133
config = { "config" => "rubocop.yml", "exclude_paths" => ["bar.rb"] }
131134
output = run_engine(config)
132-
assert !includes_check?(output, "Lint/UselessAssignment")
135+
136+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
133137
end
134138

135139
it "handles different locations properly" do
136-
RuboCop::Cop::Team.any_instance.expects(:inspect_file).returns(
140+
allow_any_instance_of(RuboCop::Cop::Team).to receive(:inspect_file).and_return(
137141
[
138142
OpenStruct.new(
139143
location: RuboCop::Cop::Lint::Syntax::PseudoSourceRange.new(
@@ -164,7 +168,8 @@ def method
164168
"end" => { "column" => 1, "line" => 1 }
165169
}
166170
}
167-
assert_equal location, result["location"]
171+
172+
expect(result["location"]).to eq(location)
168173
end
169174

170175
it "includes complete method body for cyclomatic complexity issue" do
@@ -192,7 +197,7 @@ def method(a,b,c,d,e,f,g)
192197
end
193198
EORUBY
194199
output = run_engine
195-
assert includes_check?(output, "Metrics/CyclomaticComplexity")
200+
expect(includes_check?(output, "Metrics/CyclomaticComplexity")).to be true
196201

197202
json = JSON.parse('[' + output.split("\u0000").join(',') + ']')
198203

@@ -206,7 +211,8 @@ def method(a,b,c,d,e,f,g)
206211
"end" => { "column" => 14, "line" => 21 }
207212
}
208213
}
209-
assert_equal location, result["location"]
214+
215+
expect(result["location"]).to eq(location)
210216
end
211217

212218
it "includes issue content when available" do
@@ -215,7 +221,7 @@ def method(a,b,c,d,e,f,g)
215221

216222
output = run_engine
217223

218-
assert includes_content_for?(output, "Metrics/ClassLength")
224+
expect(includes_content_for?(output, "Metrics/ClassLength")).to be true
219225
end
220226

221227
it "uses only include_paths when they're passed in via the config hash" do
@@ -243,8 +249,9 @@ def method
243249
output = run_engine(
244250
"include_paths" => %w[included_root_file.rb subdir/]
245251
)
246-
assert !includes_check?(output, "Lint/UselessAssignment")
247-
assert !includes_check?(output, "Style/AndOr")
252+
253+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
254+
expect(includes_check?(output, "Style/AndOr")).to be false
248255
end
249256

250257
it "ignores non-Ruby files even when passed in as include_paths" do
@@ -253,9 +260,11 @@ def method
253260
output = run_engine(
254261
"include_paths" => %w[config.yml]
255262
)
256-
refute(issues(output).detect do |i|
263+
issue = issues(output).detect do |i|
257264
i["description"] == "unexpected token tCOLON"
258-
end)
265+
end
266+
267+
expect(issue).to be nil
259268
end
260269

261270
it "includes Ruby files even if they don't end with .rb" do
@@ -267,7 +276,8 @@ def method
267276
end
268277
EORUBY
269278
output = run_engine("include_paths" => %w[Rakefile])
270-
assert includes_check?(output, "Lint/UselessAssignment")
279+
280+
expect(includes_check?(output, "Lint/UselessAssignment")).to be true
271281
end
272282

273283
it "skips local disables" do
@@ -280,7 +290,8 @@ def method
280290
end
281291
EORUBY
282292
output = run_engine
283-
refute includes_check?(output, "Lint/UselessAssignment")
293+
294+
expect(includes_check?(output, "Lint/UselessAssignment")).to be false
284295
end
285296

286297
it "shows full source of long methods" do
@@ -296,8 +307,8 @@ def method
296307
i["check_name"] == "Rubocop/Metrics/MethodLength"
297308
end
298309

299-
assert_equal 1, issue["location"]["positions"]["begin"]["line"]
300-
assert_equal 14, issue["location"]["positions"]["end"]["line"]
310+
expect(issue["location"]["positions"]["begin"]["line"]).to eq(1)
311+
expect(issue["location"]["positions"]["end"]["line"]).to eq(14)
301312
end
302313

303314
it "shows full source of long classes" do
@@ -312,8 +323,8 @@ class Awesome
312323
i["check_name"] == "Rubocop/Metrics/ClassLength"
313324
end
314325

315-
assert_equal 1, issue["location"]["positions"]["begin"]["line"]
316-
assert_equal 105, issue["location"]["positions"]["end"]["line"]
326+
expect(issue["location"]["positions"]["begin"]["line"]).to eq(1)
327+
expect(issue["location"]["positions"]["end"]["line"]).to eq(105)
317328
end
318329

319330
def includes_check?(output, cop_name)

spec/spec_helper.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
require 'minitest/spec'
2-
require 'minitest/autorun'
3-
require "minitest/reporters"
4-
require "mocha/mini_test"
5-
Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new
1+
require "rspec"

0 commit comments

Comments
 (0)