/test/fixtures/). The fixture file ends with the .yml file extension (Rails example: "/test/fixtures/web_sites.yml"). The format of a YAML fixture file looks like this:
rubyonrails:
id: 1
name: Ruby on Rails
url: http://www.rubyonrails.org
google:
id: 2
name: Google
url: http://www.google.com
This YAML fixture file includes two fixtures. Each YAML fixture (ie. record) is given a name and is followed by an indented list of key/value pairs in the "key: value" format. Records are separated by a blank line for your viewing pleasure.
See the "API Docs for Fixtures":http://rails.rubyonrails.com/classes/Fixtures.html for more details on how to use YAML fixtures in your test.
[[YAML]] fixtures "are available as of Rails 0.9 (What's new in 0.9: New YAML fixture format)":http://manuals.rubyonrails.com/read/chapter/7#page14
h2. Questions
*Question:* is there a way to insert arbitrary Ruby code into a test fixture, and have it evaluated? (e.g. I want to assign Time.now to certain timestamp field)
-- AlexeyVerkhovsky
bq. You can now use erb in your fixture files, so <%= Time.now %> is absolutely valid.
bq. Though you will have _much_ better luck with <%=Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
-mml
*Question:* How do I use Fixture to test Class that belongs_to other Class because if I just add 'fixtures :parent' to my \ChildTest class. I will get data integrity error from DB when try to insert that Fixture into DB.
*Question:* could anyone look at Fixture code for 0.10.1? It seems to be so buggy compare to 0.9.5 I had. The code seems to be out of sync in how to use another code
*Question:* How do I keep the values @true@ and @false@ from turning into @1@ and @0@?
According to the YAML specs(http://www.yaml.org/refcard.html) "Yes", "yes", "true", 1 are all counted as 1. Same with false and friends.
The solution is quite simple. In your YAML file, quote the string like this:
record:
field: "true"
And the value should be the string "true" rather than 1.
*Question:* How to I create fixtures for the relationship between two models that @have_and_belongs_to@ each other?
bq. See [[Howto Use Fixtures with habtm]]