-
Notifications
You must be signed in to change notification settings - Fork 11
/
repository_spec.rb
57 lines (47 loc) · 2 KB
/
repository_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
48
49
50
51
52
53
54
55
56
57
require 'rspec'
require_relative 'code_event.rb'
require_relative 'repository.rb'
describe "RepoDepot::Repository" do
it "should not populate classes when not given events" do
repository = RepoDepot::Repository.new('example', [])
repository.classes.should be_empty
end
it "should add a class when there is an event for a class" do
event = CodeEvent.new(class_name: "A")
repository = RepoDepot::Repository.new('example', [event])
repository.classes.count.should == 1
end
it "should generate no commits when there are no events" do
RepoDepot::Repository.new('example', []).commits.should be_empty
end
it "should create a list of commits for events" do
events = [CodeEvent.new(commit: '9e9273dcbbc7bcc882520f2a8ffe13e4f3b273ac', date: '1/1/2000'),
CodeEvent.new(commit: 'e9c1c0adb4e92d4b2c4117dbc139821ccf2b2851', date: '1/1/2001')]
RepoDepot::Repository.new('', events).commits.count == 2
end
it "should not populate files when not given events" do
repository = RepoDepot::Repository.new('', [])
repository.source_files.should be_empty
end
it "should add a file when there is an event for a file" do
event = CodeEvent.new(file_name: "A")
repository = RepoDepot::Repository.new('', [event])
repository.source_files.count.should == 1
end
it "can calculate its total complexity" do
events = [
CodeEvent.new(class_name: "A", method_name: "a", complexity: 0.2),
CodeEvent.new(class_name: "B", method_name: "a", complexity: 0.4)
]
RepoDepot::Repository.new('', events).complexity.should be_within(0.1).of(0.6)
end
it "should return methods for all of its classes" do
events = [
CodeEvent.new(class_name: "A", method_name: "a", date: '1/1/2000'),
CodeEvent.new(class_name: "B", method_name: "a", date: '1/1/2001'),
CodeEvent.new(class_name: "B", method_name: "b", date: '1/1/2002')
]
methods = RepoDepot::Repository.new('', events).methods
methods.map(&:name).should == ["a", "a", "b"]
end
end