Permalink
Browse files

Further refactoring - just making things cleaner.

  • Loading branch information...
1 parent 362ab2e commit 0a3bf79f132153b988b61188091241d6fe52c090 @gilesbowkett committed Oct 2, 2008
Showing with 29 additions and 18 deletions.
  1. +1 −1 lib/controller.rb
  2. +4 −8 lib/node_analysis.rb
  3. +24 −9 spec/towelie_spec.rb
View
2 lib/controller.rb
@@ -13,7 +13,7 @@ def delegate_thru_model(*method_names)
method_names.each do |method_name|
class_eval <<-METHOD
def #{method_name}(*args)
- @model.#{method_name}(*args)
+ @model.#{method_name} *args
end
METHOD
end
View
12 lib/node_analysis.rb
@@ -1,24 +1,20 @@
class Model
module NodeAnalysis
- def duplication?(dir)
- parse dir
+ def duplication?
not duplicates.empty?
end
- def duplicated(dir)
- parse dir
+ def duplicated
duplicates
end
def duplicates
(@method_definitions.collect do |node|
node if @method_definitions.duplicates? node
end).compact.uniq
end
- def unique(dir)
- parse dir
+ def unique
@method_definitions - duplicates
end
- def homonyms(dir)
- parse dir
+ def homonyms
homonyms = []
# this picks up duplicates as well as homonyms, since a duplicate is technically also a homonym;
# and I should probably run .uniq on it also.
View
33 spec/towelie_spec.rb
@@ -92,33 +92,48 @@ def foo
TWO_NODE_DIFF_BLOCK
end
it "identifies duplication" do
- @towelie.duplication?("spec/test_data").should be_true
- @towelie.duplication?("spec/classes_modules").should be_true
+ @towelie.parse("spec/test_data")
+ @towelie.duplication?.should be_true
+
+ @towelie.parse("spec/classes_modules")
+ @towelie.duplication?.should be_true
end
it "returns no false positives when identifying duplication" do
- @towelie.duplication?("spec/non_duplicating_data").should be_false
+ @towelie.parse("spec/non_duplicating_data")
+ @towelie.duplication?.should be_false
end
it "extracts :defn nodes" do
@towelie.parse("spec/test_data")
@towelie.method_definitions.should == @the_nodes
+
@towelie.parse("spec/classes_modules")
@towelie.method_definitions.should == @the_nodes
end
it "isolates duplicated blocks" do
- @towelie.duplicated("spec/test_data").should == @duplicated_block
- @towelie.duplicated("spec/classes_modules").should == @duplicated_block
+ @towelie.parse("spec/test_data")
+ @towelie.duplicated.should == @duplicated_block
+
+ @towelie.parse("spec/classes_modules")
+ @towelie.duplicated.should == @duplicated_block
end
it "reports unique code" do
- @towelie.unique("spec/test_data").should == @unique_block
- @towelie.unique("spec/classes_modules").should == @unique_block
+ @towelie.parse("spec/test_data")
+ @towelie.unique.should == @unique_block
+
+ @towelie.parse("spec/classes_modules")
+ @towelie.unique.should == @unique_block
end
it "reports distinct methods with the same name" do
- @towelie.homonyms("spec/test_data").should == @homonym_block
- @towelie.homonyms("spec/classes_modules").should == @homonym_block
+ @towelie.parse("spec/test_data")
+ @towelie.homonyms.should == @homonym_block
+
+ @towelie.parse("spec/classes_modules")
+ @towelie.homonyms.should == @homonym_block
end
it "reports methods which differ only by one node" do
@towelie.parse("spec/one_node_diff")
@towelie.diff(1).should == @one_node_diff_block
+
@towelie.parse("spec/larger_one_node_diff")
@towelie.diff(1).should == @bigger_one_node_diff_block
end

0 comments on commit 0a3bf79

Please sign in to comment.