Skip to content

annotation Athena::Spec::TestCase::TestWith #

Instead of created a dedicated methods for use with DataProvider, you can define a data set using the TestWith annotation. The annotations accepts a variadic amount of Tuple positional/named arguments and will create a it case for each "set" of data.

Example#

require "athena-spec"

struct TestWithTest < ASPEC::TestCase
  @[TestWith(
    two: {2, 4},
    three: {3, 9},
    four: {4, 16},
    five: {5, 25},
  )]
  def test_squares(value : Int32, expected : Int32) : Nil
    (value ** 2).should eq expected
  end

  @[TestWith(
    {2, 8},
    {3, 27},
    {4, 64},
    {5, 125},
  )]
  def test_cubes(value : Int32, expected : Int32) : Nil
    (value ** 3).should eq expected
  end
end

TestWithTest.run # =>
# TestWithTest
#   squares two
#   squares three
#   squares four
#   squares five
#   cubes 0
#   cubes 1
#   cubes 2
#   cubes 3