Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Fixed method_location is now cleared on #reset. (makaroni4)

[git-p4: depot-paths = "//src/flog/dev/": change = 8504]
  • Loading branch information...
commit 439000105950d9df97e54432f1d6823c87d1a116 1 parent 0b72739
Ryan Davis zenspider authored
Showing with 50 additions and 5 deletions.
  1. +6 −5 lib/flog.rb
  2. +44 −0 test/test_flog.rb
11 lib/flog.rb
View
@@ -330,11 +330,12 @@ def process_until_empty exp
# Reset score data
def reset
- @totals = @total_score = nil
- @multiplier = 1.0
- @calls = Hash.new { |h,k| h[k] = Hash.new 0 }
- @method_scores = Hash.new { |h,k| h[k] = [] }
- @scores = Hash.new 0
+ @totals = @total_score = nil
+ @multiplier = 1.0
+ @calls = Hash.new { |h,k| h[k] = Hash.new 0 }
+ @method_scores = Hash.new { |h,k| h[k] = [] }
+ @scores = Hash.new 0
+ @method_locations = {}
end
##
44 test/test_flog.rb
View
@@ -596,6 +596,50 @@ def test_calculate
assert_equal({ 'MyKlass' => [["MyKlass::Base#mymethod", 42.0]] }, @flog.method_scores)
end
+ def test_reset
+ user_class = %(
+ class User
+ def blah n
+ puts "blah" * n
+ end
+ end
+ )
+ user_file = "user.rb"
+
+ @flog.flog_ruby user_class, user_file
+ @flog.calculate_total_scores
+ @flog.calculate
+
+ assert_equal({ 'User#blah' => 'user.rb:3' }, @flog.method_locations)
+ assert_equal({ "User#blah" => 2.2 }, @flog.totals)
+ assert_equal(2.2, @flog.total_score)
+ assert_equal(1.0, @flog.multiplier)
+ assert_equal({ "User#blah" => { :* => 1.2, :puts => 1.0 } }, @flog.calls)
+ assert_equal({ "User" => 2.2 }, @flog.scores)
+
+ @flog.reset
+
+ coder_class = %(
+ class Coder
+ def happy?
+ [true, false].sample
+ end
+ end
+ )
+ coder_file = "coder.rb"
+
+ @flog.flog_ruby coder_class, coder_file
+ @flog.calculate_total_scores
+ @flog.calculate
+
+ assert_equal({ 'Coder#happy?' => 'coder.rb:3' }, @flog.method_locations)
+ assert_equal({ "Coder#happy?" => 1.0 }, @flog.totals)
+ assert_equal(1.0, @flog.total_score)
+ assert_equal(1.0, @flog.multiplier)
+ assert_equal({ "Coder#happy?" => { :sample => 1.0 } }, @flog.calls)
+ assert_equal({ "Coder" => 1.0 }, @flog.scores)
+ end
+
def setup_my_klass
@flog.class_stack << "Base" << "MyKlass"
@flog.method_stack << "mymethod"
Please sign in to comment.
Something went wrong with that request. Please try again.