I'm trying to execute the following code, but it is giving me an undefined method error:
require 'minitest/autorun'
require 'string_extension'
class StringExtensionTest < Minitest::Test
def test_humanize_returns_nothing
assert_not_nil "Yo".humanize, "humanize is returning nil."
end
end
I'm trying to execute this code from Codeschool's Rails course, but it seems that there is no method assert_not_nil. I've also checked the documentation for MiniTest framework, and neither it is defined there, but I'm not sure.
Here you can find the list of assertions defined by MiniTest.
As you can see, assert_not_nil is not defined. There's a lot of possible assertions that MiniTest doesn't define, but it's also true that any assertion can be defined with the simplest assertion ever possible assert.
In your specific case:
assert result != nil
You can also pass a custom message
assert result != nil, "Expected something to not be nil"
assert_not_nil is just an alias for refute_nil, but it's Rails-only, not part of standard Minitest. Changing your test to extend ActiveSupport::TestCase should do the trick:
class StringExtensionTest < ActiveSupport::TestCase
def test_humanize_returns_nothing
assert_not_nil "Yo".humanize, "humanize is returning nil."
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With