Skip to content
This repository

When all you need is #assert

tree: addbf18de3

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 examples.rb
Octocat-spinner-32 gem.watchr
Octocat-spinner-32 specs.watchr
README.rdoc

Summary

Most. Mymynal. Test Framework. Ever! Perfect for DIY lovers. NanoTest provides the bare mynymum needed; for everything else, there's ruby.

Install

gem install nanotest --source http://gemcutter.org

Examples

require 'nanotest'
include NanoTest

assert { 1 == 1 }
assert { 1 >= 1 }
assert { 1 == 2 } #line 12

outputs:

..F
(examples.rb:12) assertion failed

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 (== false) it fails, otherwise it passes. Simple as that.

#assert also accepts a custom failure message (defaults to “assertion failed”):

assert("foo is too small") { @foo > 5 }

as well as a file name and line number, in case you want to do something fancy and call #assert from somewhere else in the stack

def assert_includes(collection, item)
  file = caller.first.split(':')[0]
  line = caller.first.split(':')[1]
  msg = "expected #{collection.inspect} to include #{item.inspect}"
  assert(msg, file, line) { collection.include?(item) }
end

foos = [1,2,3]
assert_includes(foos, 3)
assert_includes(foos, 4) #line 46

outputs:

.F
(examples.rb:46) expected [1, 2, 3] to include 4

Links

source

github.com/mynyml/nanotest

docs

rdoc.info/projects/mynyml/nanotest

wiki

wiki.github.com/mynyml/nanotest

bugs

github.com/mynyml/nanotest/issues

tl;dr: is small test fw. is fun. assert(“msg”) { bool }

Something went wrong with that request. Please try again.