Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

More Assertions for Test::Unit::Assertions

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 History.txt
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 README.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 assertions.gemspec
README.rdoc

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!

Something went wrong with that request. Please try again.