Permalink
Browse files

added weaver for history analysis

  • Loading branch information...
1 parent 638068b commit e6a7679c0c66b441a2790a943f01357f55c1ce0c @michaelfeathers committed May 28, 2011
Showing with 45 additions and 0 deletions.
  1. +14 −0 weaver.rb
  2. +31 −0 weaver_spec.rb
View
14 weaver.rb
@@ -0,0 +1,14 @@
+
+
+def link events, link_symbol
+ assign_symbol = (link_symbol.to_s + "=").to_sym
+ events.each_cons(2).each { |e0, e1| e0.send(assign_symbol, e1) }
+end
+
+def weave events
+ RepoDepot::Repository.new('', events).methods.each do |m|
+ link m.events, :next_state
+ link m.events.reverse, :previous_state
+ end
+end
+
View
31 weaver_spec.rb
@@ -0,0 +1,31 @@
+
+require 'rspec'
+require_relative 'weaver.rb'
+
+describe "Weaver" do
+
+ it "should be able to link events" do
+ events = (0..2).map { |i| CodeEvent.new(name: i.to_s) }
+ link events, :next_state
+ events[0].next_state.should == events[1]
+ events[1].next_state.should == events[2]
+ end
+
+ it "should be able to weave events" do
+ events = []
+ events << CodeEvent.new(class_name: 'Foo', commit: 'a', method_name: 'moe')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'a', method_name: 'larry')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'a', method_name: 'curly')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'b', method_name: 'moe')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'b', method_name: 'larry')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'b', method_name: 'curly')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'c', method_name: 'moe')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'c', method_name: 'larry')
+ events << CodeEvent.new(class_name: 'Foo', commit: 'c', method_name: 'curly')
+
+ weave(events)
+ method_events = RepoDepot::Repository.new('', events).methods.first.events
+ method_events.each_cons(2).map { |e0, e1| e0.next_state.should == e1 }
+ end
+end
+

0 comments on commit e6a7679

Please sign in to comment.