Giter Club home page Giter Club logo

power_assert.cr's Introduction

power_assert.cr

docrystal.org

PowerAssert provides the more powerful assertion to you.

Usage

Very simple.

# spec/my_lib_spec.cr

describe MyLib do
  describe ".major_version" do
    it "should be equal 1" do
      assert MyLib.major_version == 1
    end
  end
end

If MyLib.major_version is 2:

F

Failures:

  1) MyLib .major_version should be equal 1
     Failure/Error: assert MyLib.major_version == 1

         MyLib.major_version == 1
         |                   |  |
         |                   |  1
         |                   false
         2

     # ./spec/my_lib_spec.cr:6

more examples in spec.

๐ŸŽ‰ Happy testing! ๐ŸŽ‰

Configure

  • global_indent : Int : A indent size of assertion messages.
  • sort_by : Symbol : Sort order of breakdowns. allowed: :default, :reverse, :left and :right.
  • expand_block : Bool : Show block's codes in the breakdown.

Example Outputs

Run crystal spec.

FFFFFF

Failures:

  1) PowerAssert Simple operators should be fail
     Failure/Error: assert 1 == 2

         1 == 2
         | |  |
         | false
         |    |
         |    2
         1

     # ./spec/power_assert_spec.cr:23

  2) PowerAssert Simple operators should be fail
     Failure/Error: assert 1 > 2

         1 > 2
         | | |
         | false
         |   |
         |   2
         1

     # ./spec/power_assert_spec.cr:27

  3) PowerAssert Method call should be fail
     Failure/Error: assert falsey == true

         falsey == true
         |      |  |
         |      false
         |         |
         |         true
         false

     # ./spec/power_assert_spec.cr:33

  4) PowerAssert Method call should be fail
     Failure/Error: assert example.falsey(one, two, three)

         example.falsey(one, two, three)
         |       |      |    |    |
         |       false  |    |    |
         |              1    |    |
         |                   2    |
         |                        3
         #<PowerAssert::Example:0x1087a6ee0>

     # ./spec/power_assert_spec.cr:42

  5) PowerAssert Method call should be fail
     Failure/Error: assert example.one == 2

         example.one == 2
         |       |   |  |
         |       |   false
         |       |      |
         |       |      2
         |       1
         #<PowerAssert::Example:0x1087a6e60>

     # ./spec/power_assert_spec.cr:48

  6) PowerAssert Method call should be fail
     Failure/Error: assert array.any? { |n| n == 0 }.nil?

         array.any? { ... }.nil?
         |     |            |
         |     |            false
         |     false
         [1, 2, 3]

     # ./spec/power_assert_spec.cr:54

Finished in 2.16 milliseconds
6 examples, 6 failures, 0 errors, 0 pending

Failed examples:

crystal spec ./spec/power_assert_spec.cr:22 # PowerAssert Simple operators should be fail
crystal spec ./spec/power_assert_spec.cr:26 # PowerAssert Simple operators should be fail
crystal spec ./spec/power_assert_spec.cr:32 # PowerAssert Method call should be fail
crystal spec ./spec/power_assert_spec.cr:36 # PowerAssert Method call should be fail
crystal spec ./spec/power_assert_spec.cr:45 # PowerAssert Method call should be fail
crystal spec ./spec/power_assert_spec.cr:51 # PowerAssert Method call should be fail
Program terminated abnormally with error code: 256

ToDo

  • Support a == b && c == d

License

Distributed under the MIT License. Please see LICENSE for details

Credits

  • Sho Kusano @rosylilly for the Crystal implementation
  • Takuto Wada @twada for the original JavaScript implementation. power_assert.cr is inspired by power-assert.

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.