Coder Social home page Coder Social logo

minitest-lucid's Introduction

Minitest Lucid

Note: The gem is not yet released.

Gem

When you test using gem minitest, a failed assertion for a large or complex object can be difficult to understand.

Using method make_my_diffs_pretty! (it's part of minitest) can sometimes help, but sometimes not enough.

Use gem minitest-lucid to get detailed elucidations for certain failures.

Is This Overkill?

Yes! (Until it isn't.)

Because when you have a failed assertion:

  • How much information is enough?
  • More is better.
  • Too much is just about right.

Usage

To use minitest-lucid:

  1. Install the gem: gem install minitest-lucid.
  2. In your tests, change require 'minitest/autorun' to require 'minitest/lucid'.

That's it. No other code change is required.

See example elucidations below.

Supported Classes

For supported classes, method assert_equal gets elucidated handling.

For other classes and assertion methods, the original assertion behaviors are unchanged.

The supported classes:

Each example below shows:

  • The message from a normal failed assertion.
  • The message as modified by the use of make_my_diffs_pretty! (which is part of minitest itself).
  • The detailed elucidation from minitest-lucid.

Set

assert_equal

Here are sets, expected and actual, to be compared.

data.rb:

def expected
  Set.new([
              'Eia do elab same.',
              'Uati nua iaam caea.',
              'Nulla paal dolor maatat.',
              'Exerad iame ulpa ipari.',
              'Veaat ea conaaectat noat.',
              'Euaab voat doloa caecat.',
              'Idatia naat paaat inia.',
              'Prem fatiaa fad ulpaat.',
              'Ea re deni utat.',
              'Irud ming fat int.',
              'Utaag quis aut ing.',
              'Siaa miaation vagna alaa.',
              'Ut dolla laat nonse.',
              'Enaat alam nonse magnaat.',
              'Sequaa nulp duisic na.',
              'Seqa quips sitataa exae.',
              'Vate eu adip quata.',
              'Tatua ididun offia doaut.',
          ])
end
def actual
  Set.new([
              'Euaab voat doloa caecat.',
              'Suntat fugiame sici exad.',
              'Idatia naat paaat inia.',
              'Ea re deni utat.',
              'Eia do elab same.',
              'Nulla paal dolor maatat.',
              'Dolo mod eaamet ena.',
              'Exerad iame ulpa ipari.',
              'Ut dolla laat nonse.',
              'Sequaa nulp duisic na.',
              'Dat dolor laboat caalit.',
              'Seqa quips sitataa exae.',
              'Dolo esera id samcomaa.',
              'Irud ming fat int.',
              'Siaa miaation vagna alaa.',
              'Cuate adid do nim.',
              'Tatua ididun offia doaut.',
              'Ocaada iaamaa fatioa anaat.',
          ])
end

The default Minitest::Assertion message:

default.txt:

--- expected
+++ actual
@@ -1 +1 @@
-#<Set: {"Eia do elab same.", "Uati nua iaam caea.", "Nulla paal dolor maatat.", "Exerad iame ulpa ipari.", "Veaat ea conaaectat noat.", "Euaab voat doloa caecat.", "Idatia naat paaat inia.", "Prem fatiaa fad ulpaat.", "Ea re deni utat.", "Irud ming fat int.", "Utaag quis aut ing.", "Siaa miaation vagna alaa.", "Ut dolla laat nonse.", "Enaat alam nonse magnaat.", "Sequaa nulp duisic na.", "Seqa quips sitataa exae.", "Vate eu adip quata.", "Tatua ididun offia doaut."}>
+#<Set: {"Euaab voat doloa caecat.", "Suntat fugiame sici exad.", "Idatia naat paaat inia.", "Ea re deni utat.", "Eia do elab same.", "Nulla paal dolor maatat.", "Dolo mod eaamet ena.", "Exerad iame ulpa ipari.", "Ut dolla laat nonse.", "Sequaa nulp duisic na.", "Dat dolor laboat caalit.", "Seqa quips sitataa exae.", "Dolo esera id samcomaa.", "Irud ming fat int.", "Siaa miaation vagna alaa.", "Cuate adid do nim.", "Tatua ididun offia doaut.", "Ocaada iaamaa fatioa anaat."}>

Message using make_my_diffs_pretty!:

better.txt:

--- expected
+++ actual
@@ -1,18 +1,18 @@
-#<Set: {"Eia do elab same.",
- "Uati nua iaam caea.",
- "Nulla paal dolor maatat.",
- "Exerad iame ulpa ipari.",
- "Veaat ea conaaectat noat.",
- "Euaab voat doloa caecat.",
+#<Set: {"Euaab voat doloa caecat.",
+ "Suntat fugiame sici exad.",
  "Idatia naat paaat inia.",
- "Prem fatiaa fad ulpaat.",
  "Ea re deni utat.",
- "Irud ming fat int.",
- "Utaag quis aut ing.",
- "Siaa miaation vagna alaa.",
+ "Eia do elab same.",
+ "Nulla paal dolor maatat.",
+ "Dolo mod eaamet ena.",
+ "Exerad iame ulpa ipari.",
  "Ut dolla laat nonse.",
- "Enaat alam nonse magnaat.",
  "Sequaa nulp duisic na.",
+ "Dat dolor laboat caalit.",
  "Seqa quips sitataa exae.",
- "Vate eu adip quata.",
- "Tatua ididun offia doaut."}>
+ "Dolo esera id samcomaa.",
+ "Irud ming fat int.",
+ "Siaa miaation vagna alaa.",
+ "Cuate adid do nim.",
+ "Tatua ididun offia doaut.",
+ "Ocaada iaamaa fatioa anaat."}>

Elucidation using minitest-lucid:

minitest-lucid's People

Contributors

burdettelamar avatar

Watchers

 avatar  avatar  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.