Skip to content

Commit 6ae4760

Browse files
committed
Make sure that test is less sensitive
Before test failures would pop up because the repository object was connected to this repository's git repo (see #1) With this change we make sure that churn values are mocked/stubbed
1 parent 8cc4c7e commit 6ae4760

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Diff for: test/lib/skunk/cli/commands/status_reporter_test.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
before do
1212
# capture_output_streams do
13-
RubyCritic::Config.source_control_system = RubyCritic::SourceControlSystem::Git.new
13+
RubyCritic::Config.source_control_system = MockGit.new
1414
runner = RubyCritic::AnalysersRunner.new(paths)
1515
analysed_modules = runner.run
1616
@reporter = Skunk::Command::StatusReporter.new({})
1717
@reporter.analysed_modules = analysed_modules
18+
analysed_modules.first.churn = 1
1819
@reporter.score = analysed_modules.score
1920
# end
2021
end
@@ -27,3 +28,9 @@
2728
end
2829
end
2930
end
31+
32+
class MockGit < RubyCritic::SourceControlSystem::Git
33+
def revisions_count(_)
34+
1
35+
end
36+
end

Diff for: test/lib/skunk/rubycritic/analysed_module_test.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,29 @@
2828
let(:coverage) { 0 }
2929

3030
it "should be 99.32" do
31-
@analysed_module.stink_score.must_equal 85.92
31+
@analysed_module.stub(:churn, 1) do
32+
_(@analysed_module.stink_score).must_equal 85.92
33+
end
3234
end
3335
end
3436

3537
context "when there is near-perfect code coverage" do
3638
let(:coverage) { 95 }
3739

3840
it "should be penalized slightly" do
39-
@analysed_module.stink_score.must_equal 4.3
41+
@analysed_module.stub(:churn, 1) do
42+
_(@analysed_module.stink_score).must_equal 4.3
43+
end
4044
end
4145
end
4246

4347
context "when there is perfect code coverage" do
4448
let(:coverage) { 100 }
4549

4650
it "should not be penalized" do
47-
@analysed_module.stink_score.must_equal 0.86
51+
@analysed_module.stub(:churn, 1) do
52+
_(@analysed_module.stink_score).must_equal 0.86
53+
end
4854
end
4955
end
5056
end

Diff for: test/samples/console_output.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
+-----------------------------------------+-------------------------------+-------------------------------+------------------------------+------------------------------+------------------------------+
22
| file | stink_score | churn_times_cost | churn | cost | coverage |
33
+-----------------------------------------+-------------------------------+-------------------------------+------------------------------+------------------------------+------------------------------+
4-
| lib/skunk/rubycritic/analysed_module.rb | 24.06 | 0.8592 | 1 | 0.8592 | 72.72727272727273 |
4+
| lib/skunk/rubycritic/analysed_module.rb | 0.86 | 0.8592 | 1 | 0.8592 | 100.0 |
55
+-----------------------------------------+-------------------------------+-------------------------------+------------------------------+------------------------------+------------------------------+
66

7-
StinkScore Total: 24.06
7+
StinkScore Total: 0.86
88
Modules Analysed: 1
9-
StinkScore Average: 0.2406e2
10-
Worst StinkScore: 24.06 (lib/skunk/rubycritic/analysed_module.rb)
9+
StinkScore Average: 0.86e0
10+
Worst StinkScore: 0.86 (lib/skunk/rubycritic/analysed_module.rb)

0 commit comments

Comments
 (0)