Skip to content

Commit 67c7cf8

Browse files
committed
Add test for RailsStats::CodeStatistics#to_s and set up rake to run tests by default
Considering there were no tests, I decided to use minitest and set it up to run by default (`bundle exec rake`) I added a simple test to make sure that `to_s` is working as expected
1 parent 08c9c4c commit 67c7cf8

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Rakefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
require "rails_stats"
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
6+
Rake::TestTask.new do |task|
7+
task.libs.push "lib"
8+
task.libs.push "test"
9+
task.pattern = "test/**/*_test.rb"
10+
end
11+
12+
task default: %i[test]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
describe RailsStats::CodeStatistics do
6+
describe "#to_s" do
7+
TABLE = <<~EOS
8+
+----------------------+-------+-------+---------+---------+-----+-------+
9+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
10+
+----------------------+-------+-------+---------+---------+-----+-------+
11+
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
12+
| Models | 3 | 3 | 1 | 0 | 0 | 0 |
13+
| Javascripts | 27 | 7 | 0 | 0 | 0 | 0 |
14+
| Jobs | 7 | 2 | 1 | 0 | 0 | 0 |
15+
| Controllers | 3 | 3 | 1 | 0 | 0 | 0 |
16+
| Helpers | 3 | 3 | 0 | 0 | 0 | 0 |
17+
| Channels | 8 | 8 | 2 | 0 | 0 | 0 |
18+
| Configuration | 417 | 111 | 1 | 0 | 0 | 0 |
19+
+----------------------+-------+-------+---------+---------+-----+-------+
20+
| Total | 472 | 141 | 7 | 0 | 0 | 0 |
21+
+----------------------+-------+-------+---------+---------+-----+-------+
22+
Code LOC: 141 Test LOC: 0 Code to Test Ratio: 1:0.0
23+
24+
EOS
25+
26+
it "outputs useful stats for a Rails project" do
27+
root_directory = File.absolute_path("./test/dummy")
28+
assert_output(TABLE) do
29+
RailsStats::CodeStatistics.new(root_directory).to_s
30+
end
31+
end
32+
end
33+
end

test/test_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require "byebug"
4+
5+
require "minitest/autorun"
6+
require "minitest/pride"
7+
require "minitest/around/spec"
8+
9+
require "rails_stats/all"

0 commit comments

Comments
 (0)