• Stars
    star
    144
  • Rank 247,024 (Top 6 %)
  • Language
    Crystal
  • License
    MIT License
  • Created about 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Test Unit for the Crystal programming language

Minitest for Crystal

Unit tests and assertions for the Crystal programming language, using the fantastic minitest as reference.

Getting Started

Given that you'd like to test the following class:

class Meme
  def i_can_has_cheezburger?
    "OHAI!"
  end

  def will_it_blend?
    "YES!"
  end
end

Unit Tests

Define your tests as methods beginning with test_:

require "minitest/autorun"

class MemeTest < Minitest::Test
  def meme
    @meme ||= Meme.new
  end

  def test_that_kitty_can_eat
    assert_equal "OHAI!", meme.i_can_has_cheezburger?
  end

  def test_that_it_will_not_blend?
    refute_match /^no/i, meme.will_it_blend?
  end

  def test_that_will_be_skipped
    skip "test this later"
  end
end

Specs

Specs follow the same design rationale as the original Minitest: describe generates classes that inherit from Minitest::Spec, and it generates test methods.

require "minitest/autorun"

describe Meme do
  let(:meme) { Meme.new }

  describe "when asked about cheeseburgers" do
    it "must respond positively" do
      meme.i_can_has_cheezburger?.must_equal("OHAI!")
    end
  end

  describe "when asked about blending possibilities" do
    it "won't say no" do
      meme.will_it_blend?.wont_match(/^no/i)
    end
  end
end

You may use assertions in your specs (they'll work the same) or you may prefer the expect syntax:

expect(meme.i_can_haz_cheezeburger?).must_equal("OHAI!")
expect(meme.will_it_blend?).wont_match(/^no/i)

Run Tests

Eventually run the tests:

$ crystal run test/meme_test.cr spec/meme_spec.cr -- --verbose

You may filter your tests using an exact test name, or a regexp:

$ crystal run test/meme_test.cr -- -n test_that_kitty_can_eat
$ crystal run test/meme_test.cr -- -n /will/

When using Minitest::Spec with assertions or the expect syntax, you can avoid to taint Object with all the #must_ and #wont_ expectations:

$ crystal run -Dmt_no_expectations spec/meme_spec.cr

License

Distributed under the MIT License. Please see LICENSE for details.

Credits

  • Julien Portalier @ysbaddaden for the Crystal implementation
  • Ryan Davis @zenspider and seattle.rb for the original Ruby gem

More Repositories

1

prax

Rack proxy server for development
Ruby
475
star
2

prax.cr

Rack proxy server for development (Crystal port)
Crystal
150
star
3

frost

Web Framework for Crystal
Crystal
117
star
4

sdl.cr

SDL2 bindings for Crystal
Crystal
99
star
5

earl

Service Objects for Crystal (Agents, Artists, Supervisors, Pools, ...)
Crystal
94
star
6

http2

HTTP/2 Protocol Implementation for the Crystal Language
Crystal
93
star
7

gc

A garbage collector for Crystal
C
91
star
8

pool

Generic (connection) pools for Crystal
Crystal
76
star
9

artanis

Sinatra-like DSL for the Crystal language (abusing macros)
Crystal
56
star
10

selenium-webdriver-crystal

Selenium Webdriver client for the Crystal programming language
Crystal
56
star
11

posix

POSIX/C bindings generator for the Crystal programming language
Crystal
33
star
12

panzer

Multi-process, zero-downtime service monitor for Crystal
Crystal
29
star
13

android.cr

Create Android applications using Crystal and the NDK
Crystal
22
star
14

java.cr

Java Native Interface (JNI) bindings (and generator) for Crystal
Crystal
22
star
15

scrypt-crystal

Crystal bindings for Colin Percival's scrypt key derivation function
Crystal
21
star
16

muco

Multithreaded Coroutines library
C
20
star
17

crystal_library

Static/Shared libraries written in Crystal (Proof of Concept)
Crystal
20
star
18

crystal-cmark

Crystal wrapper for libcmark, the reference CommonMark C library
Crystal
18
star
19

syn

Synchronization primitives to build concurrent and parallel-safe data structures in Crystal
Crystal
17
star
20

nanolib.cr

Crystal
15
star
21

ruby-akismet

Ruby library for the Akismet anti-spam service.
Ruby
13
star
22

rome

Crystal
12
star
23

janus

Authentication engine for Ruby on Rails.
Ruby
12
star
24

shards-registry

Crystal
8
star
25

minitest-js

A JavaScript port of the minitest ruby gem
JavaScript
7
star
26

sql

SQL query builder for Crystal
Crystal
7
star
27

jsruby

Ruby Virtual Machine using node.js
JavaScript
6
star
28

microtest.cr

A test framework for raw Crystal (empty prelude)
Crystal
6
star
29

siphash.cr

SipHash family of pseudo random functions implemented in Crystal
Crystal
5
star
30

php5-redis

Yet another Redis client for PHP.
PHP
5
star
31

teascript

An attempt at creating a Ruby inspired language that compiles to JavaScript.
JavaScript
4
star
32

misago

Yet Another PHP 5 Framework
PHP
4
star
33

sinapse

Push service for Ruby using EventSource
Ruby
4
star
34

alpha

JavaScript
4
star
35

calliope

Blog engine for Ruby on Rails
Ruby
3
star
36

earl.rb

Service Objects for Ruby (Agents, Artists, Supervisors, Pools, ...)
Ruby
3
star
37

acts_as_enum

Treat an integer or string ActiveRecord column as a list of symbols.
Ruby
3
star
38

960-atatonic

CSS framework experiment based on 960 and Atatonic
3
star
39

pdoc

A minimalistic documentation tool for PHP.
PHP
3
star
40

ewkb

Crystal
2
star
41

pake

pake is meant to provide centralized CLI scripts to your PHP 5 projects
PHP
2
star
42

ng-rails-ujs

Angular directives for Rails UJS
JavaScript
2
star
43

markup

Ruby
2
star
44

redis_model

Ruby
2
star
45

zombie_admin

A brainless alternative to ActiveAdmin that speaks zombie fluently.
Ruby
2
star
46

mdown

Markdown editor with live preview (web app experiment)
Ruby
2
star
47

wyme

JavaScript
2
star
48

imhotep

Wiki engine for Ruby on Rails.
Ruby
2
star
49

acts_as_publish

Provides ActiveRecords with publishing capabilities
Ruby
2
star
50

alpha-control

JavaScript
2
star
51

ejs

ruby-like template engine for javascript
JavaScript
2
star
52

alpha-core

An obstrusive JavaScript library that aims at fixing, implementing and emulating standard JavaScript and DOM in broken and old browsers.
JavaScript
2
star
53

acts_as_sanitize

Sanitizes user data within ActiveRecord
Ruby
2
star
54

commentable

Ruby
2
star
55

sechat

Q&A engine for Ruby on Rails
Ruby
2
star
56

erb_assets

Render your Rails views into the Assets Pipeline
Ruby
1
star
57

rbs

Ruby inspired language that transcompiles to simple JavaScript
Ruby
1
star
58

dockerdev.cr

Crystal
1
star
59

swagger.cr

Crystal
1
star
60

brium-app

Crystal
1
star
61

calliper

Protractor for Ruby, or testing your Angular application with elegance
Ruby
1
star
62

execution_context

Crystal
1
star