Coder Social home page Coder Social logo

assertions's Introduction

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!

assertions's People

Contributors

janxious avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.