Project

huh

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
A tiny(<40 lines) library for unit testing
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

HUH

(Don't use this. I don't maintain it.)

Originally written in 2010 as an exercise in how small a test framework can be.

A tiny(<40 lines) library for unit testing

Install

gem install huh

or from source

git clone https://github.com/slayyyyer/huh.git
cd huh
rake
gem install huh-2.0.0.gem

Usage

class PostTest < Huh

  test "should_not_save" do
    @post = Post.new 
    assert !@post.save
  end

  finish!

end

Don't forget the finish!; it prints out number of tests, assertions, failures, as well as percentage of passing tests.

Running tests from irb or rails console

Just require huh, and call Huh#run with all test files as an argument.

require "huh"
Huh.run(Dir.glob("examples/*.rb"))

Assertions

The current list of assertions available:

  • assert(a): expects a to be true
  • assert_equal(a, b): expects a == b
  • assert_not_equal(a, b): expects a != b
  • assert_same(a, b): expects a.equal?(b)
  • assert_not_same(a, b): expects !a.equal?(b)
  • assert_nil(a): expects a == nil
  • assert_not_nil(a): expects a != nil
  • assert_instance_of(t, o): expects o.instance_of?(t)
  • assert_kind_of(t, o): expects o.kind_of?(t)
  • assert_match(p,s): expects p.match(s)
  • assert_no_match(p,s): expects !p.match(s)
  • assert_respond_to(m,o): expects o.respond_to?(m)
  • assert_raises(block): expects block.call to raise an error
  • assert_block(block): expects block.call to return true
  • assert_operator(a, b, o): expects a.send(o, b)
  • assert_send(array): expects array[0].send(array[1], array[REST OF ARRAY])
  • assert_in_delta(e,a,d): expects (e-a).abs to be less than or equal to d
  • assert_nothing_thrown(block): expects block to throw nothing
  • assert_nothing_raised(block): expects block to raise nothing
  • flunk: fails always

License

Copyright (c) 2015 Justin baker

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.