In Files

Hoe::Test

Test plugin for hoe.

Tasks Provided:

audit

Run ZenTest against the package.

default

Run the default task(s).

multi

Run the test suite using multiruby.

test

Run the test suite.

test_deps

Show which test files fail when run alone.

Constants

SUPPORTED_TEST_FRAMEWORKS

Configuration for the supported test frameworks for test task.

FILTER

Used to add flags to test_unit (e.g., -n test_borked).

eg FILTER=”-n test_blah“

Attributes

multiruby_skip[RW]

Optional: Array of incompatible versions for multiruby filtering. Used as a regex.

testlib[RW]

Optional: What test library to require [default: :testunit]

test_prelude[RW]

Optional: Additional ruby to run before the test framework is loaded.

rspec_dirs[RW]

Optional: RSpec dirs. [default: %w(spec lib)]

rspec_options[RW]

Optional: RSpec options. [default: []]

Public Instance Methods

define_test_tasks() click to toggle source

Define tasks for plugin.

     # File lib/hoe/test.rb, line 69
 69:   def define_test_tasks
 70:     default_tasks = []
 71: 
 72:     if File.directory? "test" then
 73:       desc 'Run the test suite. Use FILTER or TESTOPTS to add flags/args.'
 74:       task :test do
 75:         ruby make_test_cmd
 76:       end
 77: 
 78:       desc 'Run the test suite using multiruby.'
 79:       task :multi do
 80:         ENV["EXCLUDED_VERSIONS"] = multiruby_skip.join(":")
 81:         system "multiruby -S rake"
 82:       end
 83: 
 84:       desc 'Show which test files fail when run alone.'
 85:       task :test_deps do
 86:         tests = Dir["test/**/test_*.rb"]  +  Dir["test/**/*_test.rb"]
 87: 
 88:         paths = ['bin', 'lib', 'test'].join(File::PATH_SEPARATOR)
 89:         null_dev = Hoe::WINDOZE ? '> NUL 2>&1' : '&> /dev/null'
 90: 
 91:         tests.each do |test|
 92:           if not system "ruby -I#{paths} #{test} #{null_dev}" then
 93:             puts "Dependency Issues: #{test}"
 94:           end
 95:         end
 96:       end
 97: 
 98:       default_tasks << :test
 99:     end
100: 
101:     if File.directory? "spec" then
102:       found = try_loading_rspec2 || try_loading_rspec1
103: 
104:       if found then
105:         default_tasks << :spec
106:       else
107:         warn "Found spec dir, but couldn't load rspec (1 or 2) task. skipping."
108:       end
109:     end
110: 
111:     desc 'Run the default task(s).'
112:     task :default => default_tasks
113: 
114:     unless default_tasks.empty? then
115:       ##
116:       # This is for Erik Hollensbe's rubygems-test project. Hoe is
117:       # test-happy, so by using this plugin you're already testable. For
118:       # more information, see: <https://github.com/erikh/rubygems-test>
119:       # and/or <http://www.gem-testers.org/>
120: 
121:       gemtest = ".gemtest"
122: 
123:       gemtest.encode!(Encoding::UTF_8) if gemtest.respond_to?(:encoding)
124: 
125:       self.spec.files += [gemtest]
126: 
127:       pkg  = pkg_path
128:       turd = "#{pkg}/.gemtest"
129: 
130:       file turd => pkg_path do
131:         touch turd
132:       end
133: 
134:       file "#{pkg}.gem" => turd
135:     end
136: 
137:     desc 'Run ZenTest against the package.'
138:     task :audit do
139:       libs = %(lib test ext).join(File::PATH_SEPARATOR)
140:       sh "zentest -I=#{libs} #{spec.files.grep(/^(lib|test)/).join(' ')}"
141:     end
142:   end
initialize_test() click to toggle source

Initialize variables for plugin.

    # File lib/hoe/test.rb, line 58
58:   def initialize_test
59:     self.multiruby_skip ||= []
60:     self.testlib        ||= :testunit
61:     self.test_prelude   ||= nil
62:     self.rspec_dirs     ||= %(spec lib)
63:     self.rspec_options  ||= []
64:   end
make_test_cmd() click to toggle source

Generate the test command-line.

     # File lib/hoe/test.rb, line 147
147:   def make_test_cmd
148:     unless SUPPORTED_TEST_FRAMEWORKS.has_key?(testlib)
149:       raise "unsupported test framework #{testlib}"
150:     end
151: 
152:     framework = SUPPORTED_TEST_FRAMEWORKS[testlib]
153: 
154:     tests = ["rubygems"]
155:     tests << framework if framework
156:     tests << test_globs.sort.map { |g| Dir.glob(g) }
157:     tests.flatten!
158:     tests.map! {|f| %(require "#{f}")}
159: 
160:     tests.insert 1, test_prelude if test_prelude
161: 
162:     "#{Hoe::RUBY_FLAGS} -e '#{tests.join("; ")}' -- #{FILTER}"
163:   end
try_loading_rspec1() click to toggle source

Attempt to load RSpec 1, returning true if successful

     # File lib/hoe/test.rb, line 187
187:   def try_loading_rspec1
188:     require 'spec/rake/spectask'
189: 
190:     desc "Run all specifications"
191:     Spec::Rake::SpecTask.new(:spec) do |t|
192:       t.libs = self.rspec_dirs
193:       t.spec_opts = self.rspec_options
194:     end
195:     true
196:   rescue LoadError => err
197:     warn "%p while trying to load RSpec 1: %s" % [ err.class, err.message ]
198:     false
199:   end
try_loading_rspec2() click to toggle source

Attempt to load RSpec 2, returning true if successful

     # File lib/hoe/test.rb, line 168
168:   def try_loading_rspec2
169:     require 'rspec/core/rake_task'
170: 
171:     desc "Run all specifications"
172:     RSpec::Core::RakeTask.new(:spec) do |t|
173:       t.rspec_opts = self.rspec_options
174:       t.rspec_opts << "-I#{self.rspec_dirs.join(":")}" unless
175:       rspec_dirs.empty?
176:     end
177: 
178:     true
179:   rescue LoadError => err
180:     warn "%p while trying to load RSpec 2: %s" % [ err.class, err.message ]
181:     false
182:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.