No commit activity in last 3 years
No release in over 3 years
Makes Test::Unit::TestCases 'contextable' and thus much easier to read and write. If you've seen RSpec than it's the very same 'context do ... end' re-invendet for Test::Unit. Inspired by gem 'context' that does a similar job for the 'old' Test::Unit bundled with Ruby 1.8.x standard libraries.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0

Runtime

>= 2.4.0
 Project Readme

Test::Unit::Context

Build Status

Makes Test::Unit::TestCase 'context-able' and thus (subjectively - hopefully) much easier to read and write. If you have ever seen RSpec than it's the very same context do ... end re-invented for Test::Unit.

Inspired by gem 'context' that does the same for the good 'old' test-unit 1.2.3 bundled with Ruby 1.8.x standard libraries.

Installation

Add it to your application's Gemfile (along with test-unit) e.g. :

group :test do
  gem 'test-unit'
  gem 'test-unit-context'
end

Or install it yourself, if you're not using Bundler :

$ gem install test-unit-context

Usage

class ChuckNorrisTest < Test::Unit::TestCase

  setup do
    @subject = ChuckNorris.new
  end

  test "can be divided by zero"
    assert_equal @subject * 2, @subject / 0
  end

  context 'frozen' do

    setup { @subject.freeze }

    test "won't answer" do
      assert_raise NoMemoryError do
        @subject.frozen?
      end
    end

    test "sqrt works"
      assert_nothing_raised do
        Math.sqrt -2
      end
    end

  end

  shared 'elementary math facts' do

    test "square root is rational"
      assert_kind_of Rational, Math.sqrt(@subject)
    end

    test "greater than infinity"
      assert @infinity < @subject
    end

    private

    setup
    def create_infinity
      @infinity = 1 / 0.0
    end

  end

  uses 'elementary math facts'

  context 'cloned' do

    setup do
      @subject = @subject.clone
    end

    test 'is Arnold Schwarzenegger' do
      assert_instance_of Terminator, @subject
      assert_nil @subject.is_a?(ChuckNorris)
    end

    like 'elementary math facts'

  end

end

Spec Mode

require 'test/unit/context/spec'

describe ChuckNorris, '#fart' do

  setup do
    @subject = ChuckNorris.new
    @subject.fart
  end

  it "creates a parallel universe" do
    assert Object.const_defined?(:Universe)
    assert_equal @subject, Universe.instance
    assert_empty ObjectSpace.each_object(Universe).to_a
  end

end
# NOTE: do not try running this at home!

Copyright

Copyright (c) 2016 Karol Bucek. See LICENSE (http://www.apache.org/licenses/LICENSE-2.0) for details.