0.0
No commit activity in last 3 years
No release in over 3 years
This project adds some additional assertions to Test::Unit::Assertions, including assert_raise_message (allowing verification of error messages) and assert_greater_than.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

assertions¶ ↑

DESCRIPTION:¶ ↑

This package adds some additional assertions to Test::Unit::Assertions, including:

  • Assertions for all of the comparison operators (Test::Unit::Assertions#assert_greater_than, Test::Unit::Assertions#assert_less_than_or_equal_to, etc.). Shorter aliases also are provided for these (Test::Unit::Assertions#assert_gt, Test::Unit::Assertions#assert_le, etc.).

  • An assertion that verifies that a given block raises a specified exception with a specified message (Test::Unit::Assertions#assert_raise_message). This allows full testing of error messages.

  • An assertion that verifies that a given block contains an assertion that fails (Test::Unit::Assertions#assert_fail), which can be used to test new assertions.

  • An assertion that verifies that a given value is false or nil (Test::Unit::Assertions#assert_not)

  • Assertions that verify enumerables are sorted (Test::Unit::Assertions#assert_sorted, Test::Unit::Assertions#assert_sorted_desc, Test::Unit::Assertions#assert_sorted_by, Test::Unit::Assertions#assert_sorted_by_desc)

  • An assertion that verifies x1 < y < x2 (Test::Unit::Assertion#assert_between)

PROBLEMS:¶ ↑

None (known).

SYNOPSIS:¶ ↑

examples/example.rb:¶ ↑
#!/usr/bin/env ruby
require 'rubygems'
require 'assertions'

require 'test/unit'

class Tests < Test::Unit::TestCase
  def test_assertions
    #
    # Verify that 4 > 5 is false.
    #
    assert_not(4 > 5)

    #
    # Verify that 4 < 5
    #
    assert_less_than(4, 5)

    #
    # Verify that 4 < 5 again, but this time with the
    # shorter alias.
    #
    assert_lt(4, 5)

    #
    # Verify that 5 >= 5
    #
    assert_ge(5, 5)

    #
    # Verify that the specified exception is raised.
    #
    assert_raise_message("Hello, exception!", RuntimeError) do
      raise "Hello, exception!"
    end

    #
    # Verify that an assertion failed.
    #
    assert_fail do
      assert_equal(5, 4)
    end

    #
    # Verify an enumerable is sorted
    #
    assert_sorted([1,2,3])

    #
    # Verify an enumerable is sorted descending
    #
    assert_sorted_desc([3,2,1])

    #
    # Verify an enumerable is sorted based on a key
    #
    assert_sorted_by(:key, [{:key => 1}, {:key => 2}])

    #
    # Verify an enumerable is sorted descending based on a key
    #
    assert_sorted_by(:key, [{:key => 2}, {:key => 1}])

   #
   # Verify a thing is between two other things
   #
   assert_between(1, 3, 2)
  end
end

INSTALL:¶ ↑

gem install assertions

AUTHORS:¶ ↑

Designing Patterns¶ ↑

Expected Behavior¶ ↑

Contributing¶ ↑

  1. Fork it

  2. Create your feature branch (‘git checkout -b my-new-feature`)

  3. Run the tests until they all pass (‘rake test`)

  4. Commit your changes (‘git commit -am ’Added some feature’‘)

  5. Push to the branch (‘git push origin my-new-feature`)

  6. Create new Pull Request

Meta¶ ↑

Originally Created by Designing Patterns

Maintained by Expected Behavior

Released under the MIT license. github.com/expected-behavior/assertions

SHARE AND ENJOY!¶ ↑