Giter VIP home page Giter VIP logo

minitest.cr's Introduction

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

minitest.cr's People

Contributors

akzhan avatar asterite avatar bcardiff avatar brandondrew avatar dmitryrck avatar dsazup avatar felixbuenemann avatar maxfierke avatar sija avatar splattael avatar xfbs avatar ysbaddaden 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.