Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved lib_test reporting

  • Loading branch information...
commit 90c3c73d31720d3690749ef73d75efde6e38dde9 1 parent 9bd70bb
Sven Fuchs authored
Showing with 103 additions and 118 deletions.
  1. +86 −76 notes/problems.txt
  2. +9 −40 test/lib_test.rb
  3. +8 −2 test/lib_test_helper.rb
162 notes/problems.txt
View
@@ -1,99 +1,109 @@
-typo (active_record.rb:5)
-
- self.find(find_type, :conditions => ["#{field} = ?", value], *options)
- syntax error, unexpected tSTAR, expecting ')'
-
+http://gist.github.com/137398
+http://gist.github.com/137401
Do not use colons to separate if/unless/when conditions from expressions:
- # e.g. adva_cms, ansuz, cruisecontrol, freemium, merb, paperclip, radiant,
- # rbot, rfpdf, rghost, rstomp, shoulda, typus
- case true; when TrueClass: true; end
-
- # ruby 1.8.7
- => true
+ # e.g. adva_cms, ansuz, cruisecontrol, freemium, merb, paperclip, radiant,
+ # rbot, rfpdf, rghost, rstomp, shoulda, typus
+ case true; when TrueClass: true; end
- # ruby 1.9.1
- syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
+ # ruby 1.8.7
+ => true
+ # ruby 1.9.1
+ => syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
Do not use instance_variables, constants or hash access as block parameters:
- # e.g. in cruise_control, spree
- lambda { |@foo| }
-
- # ruby 1.8.7
- => #<Proc:0x00000000@(irb):1>
-
- # ruby 1.9.1
- formal argument cannot be an instance variable
-
- # e.g. in cruisecontrol (frozen rails)
- lambda { |foo[:bar]| }
-
- # ruby 1.8.7
- => #<Proc:0x00000000@(irb):1>
-
- # ruby 1.9.1
- formal argument cannot be a constant
+ # e.g. in cruise_control, spree
+ lambda { |@foo| }
- # e.g. in cruisecontrol (frozen rails)
- lambda { |foo[:bar]| }
-
- # ruby 1.8.7
- => #<Proc:0x00000000@(irb):1>
-
- # ruby 1.9.1
- syntax error, unexpected '[', expecting '|'
-
-
-Do not use ...
+ # ruby 1.8.7
+ => #<Proc:0x00000000@(irb):1>
+ # ruby 1.9.1
+ formal argument cannot be an instance variable
+
+ # e.g. in cruisecontrol (frozen rails)
+ lambda { |foo[:bar]| }
+
+ # ruby 1.8.7
+ => #<Proc:0x00000000@(irb):1>
+ # ruby 1.9.1
+ formal argument cannot be a constant
# e.g. in cruisecontrol (frozen rails)
- lambda { |(foo, )| }
+ lambda { |foo[:bar]| }
+
+ # ruby 1.8.7
+ => #<Proc:0x00000000@(irb):1>
+ # ruby 1.9.1
+ => syntax error, unexpected '[', expecting '|'
+
+
+Do not use dangling commas in parameter lists:
- # ruby 1.8.7
- => #<Proc:0x00000000@(irb):1>
+ # e.g. in cruisecontrol (frozen rails)
+ lambda { |(foo, )| }
- # ruby 1.9.1
- syntax error, unexpected ')'
+ # ruby 1.8.7
+ => #<Proc:0x00000000@(irb):1>
+ # ruby 1.9.1
+ => syntax error, unexpected ')'
Do not use commas to separate key and value in a Hash:
- # e.g. cosy, streamlined, webrat
- {1, 2}
+ # e.g. cosy, streamlined, webrat
+ {1, 2}
- # ruby 1.8.7
- => {1 => 2}
-
- # ruby 1.9.1
- syntax error, unexpected ',', expecting tASSOC
-
-
+ # ruby 1.8.7
+ => {1 => 2}
+ # ruby 1.9.1
+ => syntax error, unexpected ',', expecting tASSOC
+
+
Do not put spaces in front of parentheses (method call arguments):
-
- # e.g. in exception_logger (logged_exceptions_controller.rb:40, logged_exceptions_helper.rb:9)
- A.foo (:bar)
- syntax error, unexpected ',', expecting ')'
-
-
+
+ # e.g. in exception_logger (logged_exceptions_controller.rb:40, logged_exceptions_helper.rb:9)
+ A.foo (:bar)
+
+ # ruby 1.9.1
+ => syntax error, unexpected ',', expecting ')'
+
+
Do not put spaces in front of brackets (Hash access):
- # e.g. in ultrasphinx (configure.rb:247)
-
- entry ['association_name']
- syntax error, unexpected tLBRACK, expecting keyword_do or '{' or '('
-
-
+ # e.g. in ultrasphinx (configure.rb:247)
+ entry ['association_name']
+
+ # ruby 1.9.1
+ => syntax error, unexpected tLBRACK, expecting keyword_do or '{' or '('
+
+
Put a space between the operator and number when calculating:
- # e.g. in liquid (htmltags.rb:49, for.rb:104, paginate.rb:61)
- a - b -1
- syntax error, unexpected tUMINUS_NUM, expecting keyword_do or '{' or '('
-
- # e.g. in prawn (span.rb:36)
- a /2.0
- syntax error, unexpected tREGEXP_BEG, expecting keyword_do or '{' or '('
-
-
+ # e.g. in liquid (htmltags.rb:49, for.rb:104, paginate.rb:61)
+ a - b -1
+
+ # ruby 1.9.1
+ => syntax error, unexpected tUMINUS_NUM, expecting keyword_do or '{' or '('
+
+ # e.g. in prawn (span.rb:36)
+ a /2.0
+
+ # ruby 1.9.1
+ => syntax error, unexpected tREGEXP_BEG, expecting keyword_do or '{' or '('
+
+Don't use a star/splat operator on the righthand side of an options (bare) hash
+when calling a method.
+
+ # e.g. in typo (active_record.rb:5)
+ def foo(*args) ; end
+ foo(:baz => :buz, *options)
+
+ # ruby 1.8.7
+ nil
+ # ruby 1.9.1
+ => syntax error, unexpected tSTAR, expecting ')'
+
+
49 test/lib_test.rb
View
@@ -23,8 +23,9 @@ def test_library_build(*names)
lib = libs[name]
lib[:exclude] ||= []
- lib[:exclude] << "/vendor/" << # don't parse various plugins or frozen rails twice
- "/simple_benches" # looks like some pseudo code in merb
+ lib[:exclude] << "/vendor/" << # don't parse various plugins or frozen rails twice
+ "/simple_benches" << # looks like some pseudo code in merb
+ "/test/hoge.rb" << # an erubis file
errors[name] = []
filenames(File.expand_path(lib[:path])).each do |filename|
@@ -47,11 +48,12 @@ def test_library_build(*names)
end
end
- # report(errors, name)
+ puts
+ report(errors, name, lib[:path])
end
- puts
- names.each { |name| report(errors, name, libs[name][:path]) }
+ # puts
+ # names.each { |name| report(errors, name, libs[name][:path]) }
end
def test_tmp_file
@@ -85,39 +87,6 @@ def clone_libs
end
end
-# LIBS = {
-# :self => {
-# :path => File.dirname(__FILE__) + '/../',
-# :exclude => []
-# },
-# :rails => {
-# :path => '~/Development/shared/rails/rails',
-# :erb => %r(/templates/|environment\.rb),
-# :exclude => []
-# },
-# :ruby => {
-# :path => '/usr/local/ruby19/lib/ruby/1.9.1'
-# },
-# :parse_tree => {
-# :path => '/usr/local/lib/ruby/gems/1.8/gems/ParseTree-3.0.2'
-# },
-# :capistrano => {
-# :path => '/usr/local/lib/ruby/gems/1.8/gems/capistrano-2.5.3'
-# },
-# :cucumber => {
-# :path => '/usr/local/lib/ruby/gems/1.8/gems/cucumber-0.3.11',
-# :erb => %r(/templates/|environment\.rb)
-# },
-# :rack => {
-# :path => '/usr/local/lib/ruby/gems/1.8/gems/rack-0.9.1'
-# },
-# :adva_cms => {
-# :path => '~/Development/projects/adva_cms/adva_cms/vendor/adva',
-# :erb => %r(/templates/|environment\.rb),
-# :exclude => []
-# }
-# }
-
# BuildTest.new.clone_libs
-# BuildTest.new.test_library_build #(:active_shipping, :zentest)
-BuildTest.new.test_tmp_file
+BuildTest.new.test_library_build
+# BuildTest.new.test_tmp_file
10 test/lib_test_helper.rb
View
@@ -51,9 +51,15 @@ def strip_erb(src)
end
def report(errors, name, path)
- puts errors[name] && !errors[name].empty? ?
- "\n#{errors[name].count} problems found in #{name}:\n" + errors[name].map { |e| e.gsub(path, name.to_s) }.join + "\n":
+ errors = errors[name]
+ msg = if errors && !errors.empty?
+ # output the broken line
+ # suggest possible fixes
+ "#{errors.count} problems found in #{name}:\n" + errors.map { |e| e.gsub(path, name.to_s) }.join
+ else
"no problems found in #{name}"
+ end
+ puts msg
end
def highlight_diff(str)
Please sign in to comment.
Something went wrong with that request. Please try again.