Permalink
Browse files

introduced assert_date_sorted and altered affected tests.

  • Loading branch information...
1 parent e3950fe commit b9b9545f1ec03869cb73eb0bae93cd46e4eaba9c @michaelfeathers committed May 19, 2011
Showing with 30 additions and 10 deletions.
  1. +1 −1 code_event.rb
  2. +11 −1 code_history.rb
  3. +1 −0 repository.rb
  4. +5 −5 repository_spec.rb
  5. +5 −2 utilities.rb
  6. +7 −1 utilities_spec.rb
View
@@ -38,7 +38,7 @@ def method_missing(sym, *args, &block)
define_attribute(reader_for(sym))
self.send(sym,*args)
elsif args.count == 0
- return 0
+ return nil
else
super
end
View
@@ -1,8 +1,18 @@
+require_relative 'utilities.rb'
module RepoDepot
- class CodeHistory < Struct.new(:name, :events)
+ class CodeHistory
+ include InstanceMethods
+
+ attr_reader :name, :events
+
+ def initialize name, events
+ assert_date_sorted events
+ @name = name
+ @events = events
+ end
def commits
@commits ||= events.map(&:commit).uniq
View
@@ -1,5 +1,6 @@
require_relative 'code_history.rb'
require_relative 'source_file.rb'
+require_relative 'class.rb'
require_relative 'delta.rb'
module RepoDepot
View
@@ -20,8 +20,8 @@
end
it "should create a list of commits for events" do
- events = [CodeEvent.new(commit: '9e9273dcbbc7bcc882520f2a8ffe13e4f3b273ac'),
- CodeEvent.new(commit: 'e9c1c0adb4e92d4b2c4117dbc139821ccf2b2851')]
+ 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
@@ -46,9 +46,9 @@
it "should return methods for all of its classes" do
events = [
- CodeEvent.new(class_name: "A", method_name: "a"),
- CodeEvent.new(class_name: "B", method_name: "a"),
- CodeEvent.new(class_name: "B", method_name: "b")
+ 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"]
View
@@ -1,6 +1,9 @@
module RepoDepot
- def assert_date_sorted events
- raise "events out of date order" unless events.each_cons(2).map {|e1, e2| e1.date < e2.date }.all?
+ module InstanceMethods
+ def assert_date_sorted events
+ events_to_check = events.select {|e| e.date }
+ raise "events out of date order" unless events_to_check.each_cons(2).map {|e1, e2| e1.date < e2.date }.all?
+ end
end
end
View
@@ -4,7 +4,7 @@
require_relative 'utilities.rb'
describe "assert_date_sorted" do
- include RepoDepot
+ include RepoDepot::InstanceMethods
it "doesn't throw when dates are in order" do
events = [CodeEvent.new(date: '1/1/2011'),
@@ -18,4 +18,10 @@
lambda { assert_date_sorted(events) }.should raise_error
end
+ it "ignores events without dates" do
+ events = [CodeEvent.new(complexity: 2.1),
+ CodeEvent.new(date: '2/1/2011')]
+ lambda { assert_date_sorted(events) }.should_not raise_error
+ end
+
end

0 comments on commit b9b9545

Please sign in to comment.