Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (74 sloc) 2.961 kb
4edc3445 »
2011-06-06 Travis status fix
1 # fixturized [![Build Status](http://travis-ci.org/szarski/Fixturized.png)](http://travis-ci.org/szarski/Fixturized)
dcaae832 »
2011-06-06 updated readme
2
ce027dbd »
2011-06-06 added Travis ci build status to readme
3 Fixturized makes your tests' data generation take less time.
dcaae832 »
2011-06-06 updated readme
4
fb2044fe »
2011-06-06 readme fix
5 Remember how fast fixtures used to work? But they were really painfull if you added one more after_save in your model - that filled some field in - and you had to update your fixture files.
dcaae832 »
2011-06-06 updated readme
6
fb2044fe »
2011-06-06 readme fix
7 FactoryGirl for instance is awesome because it gives you extreme flexibility. But it is also very slow if you save a lot of records to your db.
dcaae832 »
2011-06-06 updated readme
8
fb2044fe »
2011-06-06 readme fix
9 Fixturized is a solution in between fixtures and whatever you want, which means it will generate fixtures out of your FactoryGirl (or whatever you use) calls and refresh them if anything changes.
dcaae832 »
2011-06-06 updated readme
10
4e4839fe »
2011-06-14 updated version and gemspec
11 ## installation
12
13 <pre>gem install fixturized</pre>
14
dcaae832 »
2011-06-06 updated readme
15 ## usage
16
fb2044fe »
2011-06-06 readme fix
17 Let's say you want to speed up an existing test.
dcaae832 »
2011-06-06 updated readme
18
fb2044fe »
2011-06-06 readme fix
19 Test case like:
20
21 ```ruby
dcaae832 »
2011-06-06 updated readme
22
23 describe User do
24 before :each do
25 @user = Factory :user
26 @dog = Factory :dog
27 end
28
29 it "should know the dog's name" do
30 @user.get_dog @dog
31 @user.dog_name.should == @dog.name
32 end
33 end
34
fb2044fe »
2011-06-06 readme fix
35 ```
dcaae832 »
2011-06-06 updated readme
36
37 Becomes:
38
fb2044fe »
2011-06-06 readme fix
39 ```ruby
dcaae832 »
2011-06-06 updated readme
40
41 describe User do
42 before :each do
43 fixturized do |o|
44 o.user = Factory :user
45 o.dog = Factory :dog
46 end
47 end
48
49 it "should know the dog's name" do
50 @user.get_dog @dog
51 @user.dog_name.should == @dog.name
52 end
53 end
54
fb2044fe »
2011-06-06 readme fix
55 ```
56
57 ## the way it works
58
59 When fixturized gets a block it:
dcaae832 »
2011-06-06 updated readme
60
fb2044fe »
2011-06-06 readme fix
61 * check if fixtures exist for this block
dcaae832 »
2011-06-06 updated readme
62
fb2044fe »
2011-06-06 readme fix
63 If so:
dcaae832 »
2011-06-06 updated readme
64
65 * clears the database
fb2044fe »
2011-06-06 readme fix
66 * loads database content and variables
dcaae832 »
2011-06-06 updated readme
67
fb2044fe »
2011-06-06 readme fix
68 If not:
dcaae832 »
2011-06-06 updated readme
69
fb2044fe »
2011-06-06 readme fix
70 * clears the database
71 * runs the fixturized block
72 * dumps db content
73 * saves variable values
dcaae832 »
2011-06-06 updated readme
74
fb2044fe »
2011-06-06 readme fix
75 The first run will be slightly slower than usualy.
dcaae832 »
2011-06-06 updated readme
76
fb2044fe »
2011-06-06 readme fix
77 Each time the block's been changed, fixturized will generate the fixture for this particular block from stretch.
dcaae832 »
2011-06-06 updated readme
78
fb2044fe »
2011-06-06 readme fix
79 If you change your models in a way that affects their database layouts, you can just <pre>rm fixturized/*</pre> and it will create all the fixtures once again.
dcaae832 »
2011-06-06 updated readme
80
81 ## drawbacks
82
fb2044fe »
2011-06-06 readme fix
83 There are two main problems with fixturized:
dcaae832 »
2011-06-06 updated readme
84
85 * you can not stack fixturized blocks (each erases the database)
fb2044fe »
2011-06-06 readme fix
86 * instead of using instance variables you need to use the Fixturized::Wrapper's methods:
8b1539e6 »
2011-06-06 readme fix
87
fb2044fe »
2011-06-06 readme fix
88 ```ruby
dcaae832 »
2011-06-06 updated readme
89 @user = Factory :user
fb2044fe »
2011-06-06 readme fix
90 ```
8b1539e6 »
2011-06-06 readme fix
91
dcaae832 »
2011-06-06 updated readme
92 becomes:
8b1539e6 »
2011-06-06 readme fix
93
fb2044fe »
2011-06-06 readme fix
94 ```ruby
dcaae832 »
2011-06-06 updated readme
95 fixturized do |o|
96 o.user = Factory :user
97 end
fb2044fe »
2011-06-06 readme fix
98 ```
dcaae832 »
2011-06-06 updated readme
99
100 ## compatibility
101
102 Fixturized consits of several classes, each responsible for interactions with different interfaces:
103
104 * DatabaseHandler - clears database, dumps db, loads db content, loads db records
105 * FileHandler - reads and writes YAML files
106 * Runner - runs the fixturized block, determines whether fixtures are up to date, hooks up the Wrapper
107 * Wrapper - loads and saves all the data from the block using the rest of the modules
108
109 These classes currently support ActiveReord with an sql database and classic YAML fixtures.
fb2044fe »
2011-06-06 readme fix
110 To use different software you just need to replace one of the classes.
dcaae832 »
2011-06-06 updated readme
111
112 ## Copyright
113
114 Copyright (c) 2010 Jacek Szarski. See LICENSE for details.
Something went wrong with that request. Please try again.