simplificator-flogger 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/flogger.rb +8 -0
- data/lib/flogger/assertions.rb +85 -0
- metadata +54 -0
data/lib/flogger.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module Flogger
|
2
|
+
module InstanceMethods
|
3
|
+
#
|
4
|
+
# assert the flog score of file(s) is below a treshold.
|
5
|
+
#
|
6
|
+
# = Samples:
|
7
|
+
# == Flog a file or all ruby files in a directory
|
8
|
+
# assert_flog(file_or_dir)
|
9
|
+
# == Flog several files or directories
|
10
|
+
# assert_flog(file_or_dir_1, file_or_dir_2, file_or_fir_n)
|
11
|
+
# == set your own flog threshold
|
12
|
+
# assert_flog(file_or_dir, :threshold => 20)
|
13
|
+
# == set your own flog threshold for a specific method
|
14
|
+
# assert_flog(file_or_dir, :thresholds => {'FooClass#bar_method'})
|
15
|
+
#
|
16
|
+
# == options
|
17
|
+
# * :treshold what flog score do we allow at most. __default__ is 20.
|
18
|
+
# * :tresholds customize tresholds on a per class/method base, overrides :treshold option
|
19
|
+
#
|
20
|
+
# == Message
|
21
|
+
# This assertion does not support passing in your own message like
|
22
|
+
# other assertions do (optional last parameter) because the error message
|
23
|
+
# lists all failures from flog.
|
24
|
+
#
|
25
|
+
def assert_flog(*args)
|
26
|
+
files, options = extract_files_and_options(args)
|
27
|
+
options = {:treshold => 20}.merge(options)
|
28
|
+
flogger = Flog.new()
|
29
|
+
flogger.flog_files(files)
|
30
|
+
failures = reject_success(flogger.totals, options)
|
31
|
+
assert_block(build_flog_message(failures, options)) do
|
32
|
+
failures.size == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def assert_floq_rails(*args)
|
38
|
+
assert_flog([RAILS_ROOT] + args)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
#
|
45
|
+
# Extracts an optional Hash (options) from an Array of Strings
|
46
|
+
#
|
47
|
+
def extract_files_and_options(args)
|
48
|
+
raise ArgumentError.new('To few argumnets') if args.size < 1
|
49
|
+
if args.size == 1 || args.last.is_a?(String)
|
50
|
+
[args, {}]
|
51
|
+
else
|
52
|
+
[args[0...-1], args.last]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
#
|
56
|
+
# Builds a 'nice' error message listing all failed methods
|
57
|
+
#
|
58
|
+
def build_flog_message(failures, options)
|
59
|
+
message = ['Error when flogging your files:']
|
60
|
+
failures.each do |key, value|
|
61
|
+
limit = treshold_for_key(key, options)
|
62
|
+
message << "#{key.ljust(40, ' ')} has a flog score of #{value} (exceeding treshold of #{limit} by #{value - limit})"
|
63
|
+
end
|
64
|
+
message.join("\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Remove all values which are not exceeding the limit
|
69
|
+
#
|
70
|
+
def reject_success(totals, options)
|
71
|
+
totals.reject do |key, value|
|
72
|
+
value < treshold_for_key(key, options)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def treshold_for_key(key, options)
|
78
|
+
options.has_key?(:tresholds) && options[:tresholds].has_key?(key) ?
|
79
|
+
options[:tresholds][key] : options[:treshold]
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplificator-flogger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simplificator GmbH
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-11 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: adds custom assertions to test/unit so you can test for your flog score
|
17
|
+
email: info@simplificator.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/flogger.rb
|
26
|
+
- lib/flogger/assertions.rb
|
27
|
+
has_rdoc: false
|
28
|
+
homepage: http://simplificator.com/en/lab
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.2.0
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: flog assertions for unit tests
|
53
|
+
test_files: []
|
54
|
+
|