forked from michaelfeathers/repodepot-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta_spec.rb
47 lines (40 loc) · 1.94 KB
/
delta_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'rspec'
require_relative 'repository.rb'
describe "RepoDepot::Delta" do
context "#removed_methods" do
it "reports when commits are empty" do
r = RepoDepot::Repository.new('', [])
r.delta_for_commits('1a2', '3b4').removed_methods.should be_empty
end
it "reports a method that disappears between commits" do
event = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a')
r = RepoDepot::Repository.new('', [event])
r.delta_for_commits('a', 'b').removed_methods.first.name.should eq('method_a')
end
end
context "#added_methods" do
it "reports when commits are empty" do
r = RepoDepot::Repository.new('', [])
r.delta_for_commits('1a2', '3b4').added_methods.should be_empty
end
it "reports a method that appears between commits" do
event = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a')
r = RepoDepot::Repository.new('', [event])
r.delta_for_commits('a', 'b').added_methods.first.name.should eq('method_a')
end
end
context "#changed_methods" do
it "reports no changed methods when all methods have the same complexity across commits" do
eventA = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
eventB = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
r = RepoDepot::Repository.new('', [eventA, eventB])
r.delta_for_commits('a', 'b').changed_methods.should be_empty
end
it "reports a change when a method changes in complexity" do
eventA = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
eventB = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a', complexity: 2.0)
r = RepoDepot::Repository.new('', [eventA, eventB])
r.delta_for_commits('a', 'b').changed_methods.first.name.should eq('method_a')
end
end
end