Blueprints

Strategies

Each blueprint can define multiple strategies on how it can be built. For example this blueprint

blueprint :sample do
  12
end.blueprint :twice do
  24
end

will have 2 strategies: :default and :twice. Depending on what strategy you choose when building blueprint you will get different result. You can choose strategy by using build_with :strategy, :blueprint.

Short blueprint form

The short blueprint form (using Class.blueprint :name, :attribute => 'value') automatically defines 4 strategies: :default, :update, :new, :demolish.

# In blueprints file
User.blueprint(:user, :username => 'admin', :password => 'secret')

# In test case
it "should define attributes" do
  build_with(:new, :user).should be_a_new(User)
  @user.username.should == 'admin'
end

DSL and strategies

All blueprints DSL methods actually just build some strategy. Here's a list of methods with what strategies they use:

Method Strategy
build :default first time, :update subsequent times
build! :default
demolish :demolish