Learn Ruby With the Edgecase Ruby Koans Online

about_asserts


class AboutAsserts < EdgeCase::Koan

  # We shall contemplate truth by testing reality, via asserts.
  The answers which you seek:
  <false> is not true.
  def test_assert_truth
    assert                 # This should be true
  end


  # Enlightenment may be more easily achieved with appropriate
  # messages.
  The answers which you seek:
  This should be true -- Please fix this. <false> is not true.
  def test_assert_with_message
    assert , "This should be true -- Please fix this"
  end


  # To understand reality, we must compare our expectations against
  # reality.
  The answers which you seek:
  <false> is not true.
  def test_assert_equality
    expected_value = 
    actual_value = 1 + 1

    assert expected_value == actual_value
  end


  # Some ways of asserting equality are better than others.
  Please meditate on the following.
  def test_a_better_way_of_asserting_equality
    expected_value = 
    actual_value = 1 + 1

    assert_equal expected_value, actual_value
  end


  # Sometimes we will ask you to fill in the values
  Please meditate on the following.
  def test_fill_in_values
    assert_equal , 1 + 1
  end

end
Content

Thanks for trying the Ruby Koans Online. We hope you're having fun.

Issues

Submit issues to the Github project.


Cheers

Blog about it or send us an email.


Get More

Download the official Ruby Koans and get the full experience.