Skip to content

Commit

Permalink
more detailed message for #assert_date_sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfeathers committed May 19, 2011
1 parent d5f0603 commit 2fa3da5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
module RepoDepot
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?
transitions = events.select {|e| e.date }.each_cons(2).to_a
return unless transitions.map { |e1, e2| e1.date > e2.date }.any?

failure = transitions.detect { |e1, e2| e1.date > e2.date }
raise "events out of order #{failure[0].date}, #{failure[1].date}"
end
end
end

0 comments on commit 2fa3da5

Please sign in to comment.