diff --git a/lib/array.rb b/lib/array.rb index 6d00e9d..0be0869 100644 --- a/lib/array.rb +++ b/lib/array.rb @@ -12,7 +12,9 @@ def stepwise end def comparing_collect accumulator = [] # collect implementation copied from Rubinius - stepwise {|element1, element2| accumulator << element1 if yield(element1, element2)} + stepwise do |element1, element2| + accumulator << element1 if yield(element1, element2) + end accumulator.compact end end diff --git a/lib/node_analysis.rb b/lib/node_analysis.rb index 3037508..202cd12 100644 --- a/lib/node_analysis.rb +++ b/lib/node_analysis.rb @@ -18,7 +18,8 @@ def homonyms end def diff(threshold) @method_definitions.comparing_collect do |method_definition_1, method_definition_2| - threshold >= (method_definition_1.body - method_definition_2.body).size + next if method_definition_1.flatten.size < method_definition_2.flatten.size + threshold >= (method_definition_1.body.flatten - method_definition_2.body.flatten).size end end end diff --git a/spec/diff_false_positives/app/models/post.rb b/spec/diff_false_positives/app/models/post.rb new file mode 100644 index 0000000..35a77d6 --- /dev/null +++ b/spec/diff_false_positives/app/models/post.rb @@ -0,0 +1,5 @@ +class Post < ActiveRecord::Base + def recent + find(:all) + end +end diff --git a/spec/diff_false_positives/app/models/user.rb b/spec/diff_false_positives/app/models/user.rb new file mode 100644 index 0000000..badd793 --- /dev/null +++ b/spec/diff_false_positives/app/models/user.rb @@ -0,0 +1,9 @@ +class User < ActiveRecord::Base + def login(credentials) + find(:first, :conditions => ["name = ? and password = ?", credentials[:name], credentials[:password]]) + end + + def dropdown + find(:all).collect { |u| [u.name, u.name] } + end +end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 719f6c0..a3bc2d6 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -152,4 +152,12 @@ @model.parse("spec/two_node_diff") @model.method_definitions[0].filename.should == "spec/two_node_diff/second_file.rb" end + it "doesn't return false positives for one-node diffs" do + @model.parse("spec/diff_false_positives") + @model.diff(1).should == [] + end + it "doesn't return false positives for five-node diffs" do + @model.parse("spec/diff_false_positives") + @model.diff(5).should == [] + end end