nanotest-0.9.4.1/0000755000175000017500000000000012745113051012541 5ustar pravipravinanotest-0.9.4.1/gem.watchr0000644000175000017500000000140312745113051014521 0ustar pravipravi# Run me with: # # $ watchr gem.watchr # # Manifest file can be automatically generated with: # # $ cat .git/hooks/post-commit # #!bin/sh # git ls-files > Manifest # # -------------------------------------------------- # Helpers # -------------------------------------------------- def build system "rake -s gem"; puts end # -------------------------------------------------- # Watchr Rules # -------------------------------------------------- watch( '^Rakefile$' ) { build } watch( '^Manifest$' ) { build } # -------------------------------------------------- # Signal Handling # -------------------------------------------------- # Ctrl-\ Signal.trap('QUIT') do puts " --- Building Gem ---\n\n" build end # Ctrl-C Signal.trap('INT') { abort("\n") } nanotest-0.9.4.1/README.md0000644000175000017500000000310712745113051014021 0ustar pravipravi*"Frustra fit per plura quod potest fieri per pauciora."* --William of Ockham "It is futile to do with more things that which can be done with fewer." ### Summary Extremely minimal test framework. Perfect for DIY lovers. Nanotest provides the bare minimum needed; for everything else, there's ruby. ### Install gem install nanotest ### Examples require 'nanotest' include Nanotest assert { 1 == 1 } assert { 2 > 1 } assert { not 1 > 2 } assert { 1 == 2 } #line 12 outputs: ...F (examples.rb:012) assertion failed See actual use at ### API Nanotest has a single method: `#assert`. You can either include Nanotest as above, or use its method directly: `Nanotest.assert { true }`. Its block is expected to return a boolean. If it's false it fails, otherwise it passes. Simple as that. `#assert` also accepts a custom failure message: assert("foo is too small") { @foo > 5 } #line 36 #=> (examples.rb:036) foo is too small That's pretty much it. Maximum Simplicity. If you insist on doing something fancy, check out the wiki for a few tips and tricks. ### Stats $ rake -s loc lib contains 18 SLOCs ### See Also * [nanotest/extensions][1] * [redgreen][2] ### Links * code: * docs: * wiki: * bugs: [1]: http://github.com/mynyml/nanotest_extensions [2]: http://github.com/mynyml/redgreen nanotest-0.9.4.1/lib/0000755000175000017500000000000012745113051013307 5ustar pravipravinanotest-0.9.4.1/lib/nanotest.rb0000644000175000017500000000075312745113051015474 0ustar pravipravimodule Nanotest extend self @@failures, @@dots = [], [] def assert(msg=nil, file=nil, line=nil, stack=caller, &block) unless block.call f,l = stack.first.match(/(.*):(\d+)/)[1..2] @@failures << "(%s:%0.3d) %s" % [file || f, line || l, msg || "assertion failed"] @@dots << 'F' else @@dots << '.' end end def self.results #:nodoc: @@dots.join + "\n" + @@failures.join("\n") end at_exit { puts results unless results.strip.empty? } end nanotest-0.9.4.1/.gitignore0000644000175000017500000000003012745113051014522 0ustar pravipravidoc/ pkg/ .yardoc *.gem nanotest-0.9.4.1/LICENSE0000644000175000017500000000205212745113051013545 0ustar pravipraviCopyright © 2009 Martin Aumont (mynyml) 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. nanotest-0.9.4.1/Manifest0000644000175000017500000000025612745113051014235 0ustar pravipravi.gitignore LICENSE Manifest README.md Rakefile examples.rb gem.watchr lib/nanotest.rb markdown.watchr nanotest.gemspec specs.watchr test/test_helper.rb test/test_nanotest.rb nanotest-0.9.4.1/Rakefile0000644000175000017500000000275212745113051014214 0ustar pravipravi# -------------------------------------------------- # Tests # -------------------------------------------------- task(:default => "test:all") namespace(:test) do desc "Run all tests" task(:all) do tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb'] cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each {|file| require file }'" puts(cmd) if ENV['VERBOSE'] system(cmd) end desc "Run all tests on multiple ruby versions (requires rvm)" task(:portability) do versions = %w( 1.8.6 1.8.7 1.9 1.9.2 jruby ) versions.each do |version| system <<-BASH bash -c 'source ~/.rvm/scripts/rvm; rvm use #{version}; echo "--------- #{version} ----------"; rake -s test:all' BASH end end end # -------------------------------------------------- # Docs # -------------------------------------------------- desc "Generate YARD Documentation" task :yardoc do require 'yard' files = %w( lib/**/*.rb ) options = %w( -o doc/yard --readme README.md --files LICENSE ) YARD::CLI::Yardoc.run *(options + files) end # -------------------------------------------------- # Stats # -------------------------------------------------- desc "LOC count" task(:loc) do loc = 0 Dir['lib/**/*'].each do |file| next if File.directory?(file) File.read(file).each_line do |line| loc += 1 unless line.strip.empty? || line.strip =~ /^#/ end end puts "lib contains #{loc} SLOCs" end nanotest-0.9.4.1/test/0000755000175000017500000000000012745113051013520 5ustar pravipravinanotest-0.9.4.1/test/test_helper.rb0000644000175000017500000000044012745113051016361 0ustar pravipravirequire 'minitest/autorun' require 'nanotest' begin require 'redgreen' require 'phocus' require 'ruby-debug' rescue LoadError, RuntimeError end class MiniTest::Unit::TestCase def self.test(name, &block) define_method("test_#{name.gsub(/\s/,'_').downcase}", &block) end end nanotest-0.9.4.1/test/test_nanotest.rb0000644000175000017500000000426112745113051016742 0ustar pravipravirequire 'minitest/autorun' require 'test/test_helper' module Nanotest class << self def failures() @@failures end def dots() @@dots end end # don't autorun def at_exit() end end require 'nanotest' # fixture class for nanotest mixin class Foo include Nanotest end class TestNanotest < MiniTest::Unit::TestCase def self.test(name, &block) define_method("test_#{name.gsub(/\s/,'_')}", &block) end def teardown Nanotest::dots.clear Nanotest::failures.clear end test "api" do assert_respond_to Foo.new, :assert assert_respond_to Nanotest, :assert end test "assertion passes" do Nanotest.assert { true } assert_equal '.', Nanotest::dots.last assert_empty Nanotest::failures end test "assertion fails (false)" do Nanotest.assert { false } assert_equal 'F', Nanotest::dots.last refute_empty Nanotest::failures end test "assertion fails (nil)" do Nanotest.assert { nil } assert_equal 'F', Nanotest::dots.last refute_empty Nanotest::failures end test "failure message" do @line = __LINE__; Nanotest.assert { false } assert_equal 1, Nanotest::failures.size assert_includes Nanotest::failures, "(%s:%0.3d) assertion failed" % [__FILE__, @line] end test "custom failure message, file, line" do Nanotest.assert('foo','bar',2) { false } assert_includes Nanotest::failures, "(bar:002) foo" end test "displays results" do Nanotest.assert { true } Nanotest.assert { false }; line1 = __LINE__ Nanotest.assert { false }; line2 = __LINE__ expected = <<-OUT.gsub(/^\s*/,'').strip % [__FILE__, line1, __FILE__, line2] .FF (%s:%0.3d) assertion failed (%s:%0.3d) assertion failed OUT assert_equal expected, Nanotest.results end test "displays results with no assertions" do assert_empty Nanotest.results.strip end test "handles origin lines that contain colons" do stack = ['o:hai:e:20:blah'] Nanotest.assert('', nil, nil, stack) { false } assert_equal "(o:hai:e:020) ", Nanotest.failures.last stack = ['o:hai:e:20'] Nanotest.assert('', nil, nil, stack) { false } assert_equal "(o:hai:e:020) ", Nanotest.failures.last end end nanotest-0.9.4.1/examples.rb0000644000175000017500000000065512745113051014712 0ustar pravipravirequire 'nanotest' include Nanotest class Foo attr_accessor :bar end @foo = Foo.new assert { @foo.is_a?(Foo) } assert { @foo.respond_to?(:bar) } assert { @foo.bar.nil? } @foo.bar = 'a' @foo.bar << 'b' assert { @foo.bar == 'ab' } assert { not @foo.bar == 'xy' } @foo.bar = nil assert { @foo.bar == 'ab' } assert('boom') { false } __END__ output: .....FF (examples.rb:021) assertion failed (examples.rb:022) boom nanotest-0.9.4.1/nanotest.gemspec0000644000175000017500000000126112745113051015741 0ustar pravipraviGem::Specification.new do |s| s.name = "nanotest" s.summary = "When all you need is #assert" s.description = "Extremely mynymal test framework. Perfect for DIY lovers. Nanotest provides the bare mynymum needed; for everything else, there's ruby." s.author = "Martin Aumont" s.email = "mynyml@gmail.com" s.homepage = "http://github.com/mynyml/nanotest" s.rubyforge_project = "nanotest" s.has_rdoc = false s.require_path = "lib" s.version = "0.9.4.1" s.files = File.read("Manifest").strip.split("\n") s.add_development_dependency 'minitest' end nanotest-0.9.4.1/markdown.watchr0000755000175000017500000000157312745113051015606 0ustar pravipravi#!/usr/bin/env watchr require 'pathname' require 'rdiscount' # -------------------------------------------------- # Helpers # -------------------------------------------------- class ::String def md2html RDiscount.new(self).to_html end def save_as(path) Pathname(path).open('w') {|f| f << self } end end default_action do md = Pathname('README.md').expand_path html = Pathname('doc/README.html').expand_path puts "Translating #{md.basename} (file://#{html})" md.read.md2html.save_as(html) end # -------------------------------------------------- # Watchr Rules # -------------------------------------------------- watch( '^README\.md' ) # -------------------------------------------------- # Signal Handling # -------------------------------------------------- # Ctrl-\ Signal.trap('QUIT') { default_action.call } # Ctrl-C Signal.trap('INT') { abort("\n") } nanotest-0.9.4.1/specs.watchr0000644000175000017500000000204212745113051015066 0ustar pravipravi# Run me with: # # $ watchr specs.watchr # -------------------------------------------------- # Helpers # -------------------------------------------------- def run(cmd) puts(cmd) system(cmd) end def run_all_tests # see Rakefile for the definition of the test:all task system( "rake -s test:all VERBOSE=true" ) end # -------------------------------------------------- # Watchr Rules # -------------------------------------------------- watch( '^examples\.rb' ) { |m| system( "ruby -rubygems -Ilib %s" % m[0] ) } watch( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems -Ilib %s" % m[0] ) } watch( '^lib/(.*)\.rb' ) { |m| run( "ruby -rubygems -Ilib test/test_%s.rb" % m[1] ) } watch( '^test/test_helper\.rb' ) { run_all_tests } # -------------------------------------------------- # Signal Handling # -------------------------------------------------- # Ctrl-\ Signal.trap('QUIT') do puts " --- Running all tests ---\n\n" run_all_tests end # Ctrl-C Signal.trap('INT') { abort("\n") }