Browse files

added #changed_methods, and #added_methods

  • Loading branch information...
1 parent ea055fa commit fbcc22331ac30f11dbe2fd19ff1138f048994e48 @michaelfeathers committed May 19, 2011
Showing with 40 additions and 8 deletions.
  1. +12 −1 delta.rb
  2. +28 −7 delta_spec.rb
View
13 delta.rb
@@ -9,7 +9,18 @@ def initialize events, first_commit, second_commit
end
def removed_methods
- @repository.methods.select {|m| m.events.count == 1 && m.events.first.commit == @first_commit }.map(&:full_name)
+ @repository.methods.select { |m| m.events.count == 1 }
+ .select { |m| m.events.first.commit == @first_commit }
+ end
+
+ def added_methods
+ @repository.methods.select {|m| m.events.count == 1 }
+ .select { |m| m.events.first.commit == @second_commit }
+ end
+
+ def changed_methods
+ @repository.methods.select { |m| m.events.count == 2 }
+ .select { |m| m.events[0].complexity != m.events[1].complexity }
end
end
View
35 delta_spec.rb
@@ -4,23 +4,44 @@
describe "RepoDepot::Delta" do
context "#removed_methods" do
- it "reports zero when the commits are empty" do
+ it "reports when commits are empty" do
r = RepoDepot::Repository.new('', [])
- r.delta_for_commits('1a2', '3b4').removed_methods.count.should eq(0)
+ r.delta_for_commits('1a2', '3b4').removed_methods.should be_empty
end
- it "reports 1 when a method disappears between commits" do
+ 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.count.should eq(1)
+ r.delta_for_commits('a', 'b').removed_methods.first.name.should eq('method_a')
end
-
end
context "#added_methods" do
- it "reports zero when commits are empty" do
+ it "reports when commits are empty" do
r = RepoDepot::Repository.new('', [])
- r.delta_for_commits('1a2', '3b4').removed_methods.count.should eq(0)
+ 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

0 comments on commit fbcc223

Please sign in to comment.