-
-
Save zachinglis/1162477 to your computer and use it in GitHub Desktop.
Scenario Blueprints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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