Skip to content
프로젝트

소개

아주 간단한 Ruby 테스트 라이브러리

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original
 _            _                  _         _
| |_  ___ ___| |_ _ __ ___   ___| | __ ___| |_
| __|/ _ | __| __| '__/ _ \ / __| |/ // _ \ __|
| |_|  __|__ \ |_| | | (_) | (__|   <|  __/ |_
 \__|\___|___/\__|_|  \___/ \___|_|\_\\___|\__|

Testrocket is a super simple (as simple as it gets really) testing library for Ruby 2.0 and higher. It has also been modernized and tested to run on Ruby 3.4 and Ruby 4.0.2.

It was initially developed for a CodeBrawl contest and it got first place! People asked me to release it 'for real' so here we are.

To install:

gem install testrocket

.. or add it to your Gemfile in the usual way.

As yet there are no useful bits and pieces for creating test files (look at the example, it's easy!) or Rake tasks.

Note: Prior to version 1, TestRocket extended built-in classes to work, but has (in 2019) been modernized to use refinements to avoid it clashing with third party libraries in real world scenarios (yes, people use this library in real world code!)

Dependencies

  • Ruby 2.1 or higher (tested on Ruby 3.4 and 4.0.2)
  • minitest/spec

Example

require 'testrocket'
using TestRocket

# BASIC USAGE
# +-> { block that should succeed }
# --> { block that should fail }

+-> { Die.new(2) }
--> { raise }
+-> { 2 + 2 == 4 }

# These two tests will deliberately fail
+-> { raise }
--> { true }

# A 'pending' test
~-> { "this is a pending test" }

# A description
!-> { "use this for descriptive output and to separate your test parts" }

As well as running tests in separate test files in the 'traditional' way, TestRocket can also be used 'inline' with real world code. A trivial example:

class YourClass
  using TestRocket

  def initialize
  end

  def does_something
    # ...
  end

  +->{  # a test for does_something goes here }

  def does_something_else
    # ...
  end

  +->{  # a test for does_something_else goes here }
  -->{  # a test for does_something_else goes here }
end

In this way, your class is tested each time you run the app in development or test modes. Note that if TestRocket detects RACK_ENV is production, RAILS_ENV is production or Rails is running and Rails.env.production? is true, the usual TestRocket methods will simply pass straight through so as to not impede performance on the loading of your app.

Other Features

By default, output is written to $stderr (as well as returned by the test expressions themselves). You can override where test output goes like so:

TestRocket.out = File.new('/dev/null', 'w')

TestRocket.out also supports Logger instances.

Credits

Initial concept and maintenance by Peter Cooper

Extra concepts and code by Christoph Grabo

Thanks to Gary Bernhardt for often praising and shining attention on TestRocket :-)

Thanks to Serge Bedzhyk for modernizing the library to use refinements.

관련 프로젝트 살펴보기

불러오는 중…