Skip to content

Instantly share code, notes, and snippets.

@zachinglis
Forked from MrJaba/scenario_blueprints.rb
Created August 22, 2011 14:15
Show Gist options
  • Save zachinglis/1162477 to your computer and use it in GitHub Desktop.
Save zachinglis/1162477 to your computer and use it in GitHub Desktop.
Scenario Blueprints
##In test file
#setup do
# load_scenario("bookshop_a")
#end
#
#test "Franks has 5 books" do
# assert_equal 5, @frank.books.count
#end
#
##In test helper or some other such solution
#def load_scenario(scenario_name)
# create(:bookshop_owner, name:"Frank")
# create(:bookshop, name: "A lotta books")
# create_list(5, :books)
#end
FactoryGirl.define do
factory :user, :aliases => [:owner] do
name "Bernard"
end
factory :book do
# ...
end
factory :bookshop do
name "Black Books"
trait :owner do
owner
end
trait :stocked do
books # Need to work out how to do this code correctly with new syntax
end
factory :bookshop_with_owner, :traits => [:owner]
factory :bookshop_with_owner_and_books, :traits => [:owner, :stocked]
end
end
####
setup do
@shop = FactoryGirl.create(:bookshop_with_owner_and_books)
end
test "Franks has 5 books" do
assert_equal 5, @shop.books.count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment