First time RoR developer, working through 4th edition with Rails 3.2.1 and Ruby 1.9.3 on a Windows 7 installation.
When I run rake test:units I get one unexpected failure, always on the first item in the OK array (regardless of which element is first):
Finished tests in 0.569033s, 8.7868 tests/s, 26.3605 assertions/s.
1) Failure:
test_image_URL(ProductTest) [C:/Sites/depot/test/unit/product_test.rb:73]:
fred2.jpg shouldn't be invalid
5 tests, 15 assertions, 1 failures, 0 errors, 0 skips
Here’s my product_test.rb:
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
fixtures :products
def new_product(image_url)
Product.new(
title: "whatever",
description: "whatever",
image_url: image_url,
price: 14.99
)
end
test "image URL" do
ok = %w{ fred2.jpg fred1.GIF jones.gif fred3.png FRED4.JPG FRED5.Jpg http://a.b.c/x/y/z/fred6.gif }
bad = %w{ fred7.doc fred8.gif/more fred9.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
end
end
and here’s my product.rb:
class Product < ActiveRecord::Base
validates :title, :description, :image_url, presence: true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness:true
validates :description, :length => {:minimum => 10}
validates :image_url, allow_blank: true, format: {
with: %r{\.(jpg|gif|png)$}i,
message: 'must be a URL for GIF, JPG, or PNG image.'
}
end
I’ve restarted the server (no change), rearranged the validations in product.rb (no change),
stripped all other tests from product_test.rb (as shown above),
rearranged the items in the OK array, played with the spacing of the %w{} construct…
still get failure of first element in the OK array. According to everything I’ve read, this should work… scratching my now-bald head (after pulling all my hair out!)
Any ideas? Thanks in advance!