Sentite, altro problema che ho rilevato ora, sempre riguardo i test:
Per mantenere i test flessibili, se nel file di fixture ( ad esempio
products.yml ) ho
version_control_book:
id: 1
titolo: Pragmatic Version Control
descrizione: Come utilizzare il controllo di versione
image_url:
http://www.greenplanet.net/maxdev/upload/rte/vacca%20primo%20piano.jpg
prezzo: 29.95
date_available: 2005-01-26 00:00:00
automation_book:
id: 2
titolo: Pragmatic Project Automation
descrizione: Come automatizzare il vostro progetto
image_url:
http://www.greenplanet.net/maxdev/upload/rte/vacca%20primo%20piano.jpg
prezzo: 29.95
date_available: 2004-07-01 00:00:00
quando eseguo il test, Erb prende in considerazione questo file che i
test.
Ora, per mantenere flessibili i test, Rails ha pensato, secondo il
libro, di caricare in un array di tipo hash ciò che viene letto dal db,
come:
require File.dirname(FILE) + ‘/…/test_helper’
class ProductTest < Test::Unit::TestCase
fixtures :products
def setup
@product = Product.find(1)
end
def test_create
assert_kind_of Product, @product
vc_book = @products["version_control_book"]
assert_equal vc_book["id"], @product.id
assert_equal vc_book["titolo"], @product.titolo
assert_equal vc_book["descrizione"], @product.descrizione
assert_equal vc_book["prezzo"], @product.prezzo
assert_equal vc_book["date_available"],
@product.date_available_before_type_cast
end
end
Il problema è che questo hash sembra essere vuoto, in quanto, quando
eseguo i test viene fuori:
- Error:
test_create(ProductTest):
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
test/unit/product_test.rb:11:in `test_create’
Avete qualche idea del
perchè?
grazie
//\ariano Di Felice
Java PHP Python Ruby programmer
with MySQL, PostgreSql, SQLite and Oracle support
Linux Platform Developer
[email protected]
Tel. 0735 703735
Cell +39 339 6407211
Nota di riservatezza:
Il presente messaggio, corredato dei relativi allegati contiene
informazioni da considerarsi strettamente riservate, ed è destinato
esclusivamente al destinatario sopra indicato, il quale è l’unico
autorizzato ad usarlo, copiarlo e, sotto la propria responsabilità,
diffonderlo. Chiunque ricevesse questo messaggio per errore o comunque
lo leggesse senza esserne legittimato è avvertito che trattenerlo,
copiarlo, divulgarlo, distribuirlo a persone diverse dal destinatario è
severamente proibito, ed è pregato di rinviarlo immediatamente al
mittente distruggendo l’originale.
Confidentiality Notice:
This message, together with its annexes, contains information to be
deemed strictly confidential and is destined only to the addressee(s)
identified above who only may use, copy and, under his/their
responsibility, further disseminate it. If anyone received this message
by mistake or reads it without entitlement is forewarned that keeping,
copying, disseminating or distributing this message to persons other
than the addressee(s) is strictly forbidden and is asked to transmit it
immediately to the sender and to erase the original message received.