mhennemeyer / testing

A slick testing framework with nested TestCases and chained Setup/Teardown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing

A slick Testing Framework for Ruby and Ruby on Rails that provides nested TestCases and chained Setup/Teardown.

Features:

Nested TestCases

Chained Setup/Teardown

Fast

No dependencies outside Ruby Standard Library.

100% Ruby 1.9 and 1.8 compatible

Rails out of the box!

< 300 LOC (sans doc)

Wraps around default UnitTest Framework, be it MiniTest or classic Test/Unit.

Installation:

> sudo gem install mhennemeyer-testing

Using Testing

Create a testfile:

# test_object.rb

require “rubygems”

require “testing”

testing Object do

setup do

@obj = Object.new

end test “is not nil” do assert_not_nil @obj end

test “can be frozen” do @obj.freeze assert @obj.frozen? end end Run it with the ruby command: > $ ruby test_object.rb

>Loaded suite -

>Started

>..

>Finished in 0.001820 seconds.

> >2 tests, 2 assertions, 0 failures, 0 errors

Using Testing with autotest

  1. Name your testfiles test_whatever.rb

  2. Start autotest

  3. There is no step three …

Using Testing with Rails

Use the default rails test directory/structure, testhelpers, assertions and infrastructure.

  1. require ‘testing’ in ‘test_helper.rb`

  2. write a test.

  3. There is no step three …

Tell Testing TestCase what kind of testcase he is, by passing one of the following options to the describe method:

  • :type => ActiveSupport::TestCase

  • :type => ActionController::TestCase

  • :type => ActionMailer::TestCase

  • :type => ActionView::TestCase

Example, Functional Test:

testing HorstsController, :type => ActionController::TestCase do test “should get index” do get :index

assert_response :success
assert_not_nil assigns(:horsts)

end testing “some other functionality” do # I’m still a ActionController::TestCase test “get index” do get :index

assert_response :success
assert_not_nil assigns(:horsts)

end end end

License

(The MIT License)

Copyright © Matthias Hennemeyer

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.

About

A slick testing framework with nested TestCases and chained Setup/Teardown


Languages

Language:Ruby 100.0%