Skip to content

Commit

Permalink
Implementation of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vegantech committed Dec 19, 2008
1 parent 55def15 commit 114936f
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 3 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 20 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
Coveralls
=========

Introduction goes here.
A rails plugin to make sure all files are required and show up in the code coverage report. (Untouched files are excluded and can thus inflate the overall code coverage.) If you forget to test a new library or module, it may not show up on the report, and thus you won't see that the coverage for that file is low.




Example
=======

Example goes here.
After installing the plugin create a test or spec that contains Coverall.require_all_ruby_files

This will require all ruby files in /lib and /app if they haven't already been required.

You can also pass in an array of directories to require.

Coverall.require_all_ruby_files ["/app/models","/app/lib"]




Thanks
=======

Special thanks go to Stephen Anderson for the name and for encouraging me to create this plugin.


Copyright (c) 2008 Shawn Balestracci, released under the MIT license

Copyright (c) 2008 [name of plugin creator], released under the MIT license
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the coveralls plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the coveralls plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Coveralls'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'coveralls'
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
21 changes: 21 additions & 0 deletions lib/coveralls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Coveralls
# Method to require all ruby classes when calculating code coverage.
# Call this to not leave untested files out of the code coverage percentages.
def self.require_all_ruby_files(target_dirs=["/lib", "/app"])
Array(target_dirs).collect do |target_dir|
dir = "#{RAILS_ROOT}#{target_dir}/**/*.rb"
Dir.glob(dir).each do |ruby_file|
obj = ruby_file.split("#{target_dir}/",2).last.split(".rb").first
obj = obj.split("/",2).last if target_dir == "/app"
begin
# trigger the normal Rails mechanism to require files
obj.classify.constantize
rescue NameError, LoadError
require obj
end
end
end

end

end
4 changes: 4 additions & 0 deletions tasks/coveralls_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :coveralls do
# # Task goes here
# end
28 changes: 28 additions & 0 deletions test/coveralls_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test/unit'
ENV['RAILS_ENV'] = 'test'
ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))

class CoverallsTest < Test::Unit::TestCase
def test_default_require_all
all_files = Coveralls.require_all_ruby_files
controllers = (Dir.glob(File.join(RAILS_ROOT,"/app","controllers","**","*.rb")))
libs = (Dir.glob(File.join(RAILS_ROOT,"/lib","*.rb")))

assert_equal libs,all_files.flatten & libs
assert_equal controllers,all_files.flatten & controllers
end

def test_invalid_require
all_files = Coveralls.require_all_ruby_files "/dog_not_here_zzz"
assert_equal [],all_files.flatten
end

def test_specify_directory
all_files = Coveralls.require_all_ruby_files "/app/controllers"
controllers = (Dir.glob(File.join(RAILS_ROOT,"/app","controllers","**","*.rb")))

assert_equal controllers, all_files.flatten
end

end
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit 114936f

Please sign in to comment.