Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my image_url Unit Test failing? (from Agile Web Development with Rails 'Depot' tutorial)
    primarykey
    data
    text
    <p>I'm new and trying to learn Rails using the book <em>Agile Web Development with Rails, Fourth Edition</em> (for Rails 3.2). Been able to get through all of the chapters so far without hiccups. If there were errors, it was usually my sloppy code (forgetting a comma, 'end' statement, etc.). But now I've hit a snag in the chapter on Unit Testing for Models. At the part where we're validating that the image URL ends with either .gif, .jpg, or .png.</p> <p>I copied the code verbatim from the book for the depot/test/product_test.rb file:</p> <pre><code>test "image url" do ok = %w{ fred.gif fred.jpg fred.png FRED.JPG FRED.Jpg http://a.b.c/x/y/z/fred.gif } bad = %w{ fred.doc fred.gif/more fred.gif.more } ok.each do |name| assert new_product(name).valid?, "#{name} shouldn't be invalid" end bad.each do |name| assert new_product(name).invalid?, "#{name} shouldn't be valid" end </code></pre> <p>But when I run the <strong>rake test:units</strong> command, I get the following failure...</p> <pre class="lang-none prettyprint-override"><code>1) Failure: test_image_url(ProductTest)[../depot/test/unit/product_test.rb:46]: fred.gif shouldn't be invalid 4 tests, 13 assertions, 1 failures, 0 errors, 0 skips rake aborted! </code></pre> <p>Does this mean that the image URL it's testing is invalid? Why is the test failing if what it says "fred.gif shouldn't be invalid" is correct?</p> <p>I'm pretty confident that it's this part of the test that must be incorrect because the other tests I have in there (ex. "product attributes must not be empty", "product price must be positive", etc.) run just fine. I get no failures if I take out the "test image url" code block.</p> <p>Please let me know what I'm doing wrong. If you need me to post the entirety of the ProductTest, I can.</p> <hr> <p><strong>UPDATE</strong>: There was a typo in my Products model that was causing the test to fail. All fixed now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload