Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added #changed_methods, and #added_methods

  • Loading branch information...
commit fbcc22331ac30f11dbe2fd19ff1138f048994e48 1 parent ea055fa
Michael Feathers authored

Showing 2 changed files with 40 additions and 8 deletions. Show diff stats Hide diff stats

  1. +12 1 delta.rb
  2. +28 7 delta_spec.rb
13 delta.rb
@@ -9,7 +9,18 @@ def initialize events, first_commit, second_commit
9 9 end
10 10
11 11 def removed_methods
12   - @repository.methods.select {|m| m.events.count == 1 && m.events.first.commit == @first_commit }.map(&:full_name)
  12 + @repository.methods.select { |m| m.events.count == 1 }
  13 + .select { |m| m.events.first.commit == @first_commit }
  14 + end
  15 +
  16 + def added_methods
  17 + @repository.methods.select {|m| m.events.count == 1 }
  18 + .select { |m| m.events.first.commit == @second_commit }
  19 + end
  20 +
  21 + def changed_methods
  22 + @repository.methods.select { |m| m.events.count == 2 }
  23 + .select { |m| m.events[0].complexity != m.events[1].complexity }
13 24 end
14 25 end
15 26
35 delta_spec.rb
@@ -4,23 +4,44 @@
4 4
5 5 describe "RepoDepot::Delta" do
6 6 context "#removed_methods" do
7   - it "reports zero when the commits are empty" do
  7 + it "reports when commits are empty" do
8 8 r = RepoDepot::Repository.new('', [])
9   - r.delta_for_commits('1a2', '3b4').removed_methods.count.should eq(0)
  9 + r.delta_for_commits('1a2', '3b4').removed_methods.should be_empty
10 10 end
11 11
12   - it "reports 1 when a method disappears between commits" do
  12 + it "reports a method that disappears between commits" do
13 13 event = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a')
14 14 r = RepoDepot::Repository.new('', [event])
15   - r.delta_for_commits('a', 'b').removed_methods.count.should eq(1)
  15 + r.delta_for_commits('a', 'b').removed_methods.first.name.should eq('method_a')
16 16 end
17   -
18 17 end
19 18
20 19 context "#added_methods" do
21   - it "reports zero when commits are empty" do
  20 + it "reports when commits are empty" do
22 21 r = RepoDepot::Repository.new('', [])
23   - r.delta_for_commits('1a2', '3b4').removed_methods.count.should eq(0)
  22 + r.delta_for_commits('1a2', '3b4').added_methods.should be_empty
  23 + end
  24 +
  25 + it "reports a method that appears between commits" do
  26 + event = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a')
  27 + r = RepoDepot::Repository.new('', [event])
  28 + r.delta_for_commits('a', 'b').added_methods.first.name.should eq('method_a')
  29 + end
  30 + end
  31 +
  32 + context "#changed_methods" do
  33 + it "reports no changed methods when all methods have the same complexity across commits" do
  34 + eventA = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
  35 + eventB = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
  36 + r = RepoDepot::Repository.new('', [eventA, eventB])
  37 + r.delta_for_commits('a', 'b').changed_methods.should be_empty
  38 + end
  39 +
  40 + it "reports a change when a method changes in complexity" do
  41 + eventA = CodeEvent.new(commit: 'a', class_name: 'class_a', method_name: 'method_a', complexity: 3.0)
  42 + eventB = CodeEvent.new(commit: 'b', class_name: 'class_a', method_name: 'method_a', complexity: 2.0)
  43 + r = RepoDepot::Repository.new('', [eventA, eventB])
  44 + r.delta_for_commits('a', 'b').changed_methods.first.name.should eq('method_a')
24 45 end
25 46 end
26 47 end

0 comments on commit fbcc223

Please sign in to comment.
Something went wrong with that request. Please try again.