Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## category.rb, using random data to find unknown edge cases minimum_example do set_name = Faker::Lorem.word sometimes { set_name = 'Materials' } { :name => Faker::Lorem.unique, :set_name => set_name } end ## product.rb model minimum_example do |attrs| # access the override attributes coming from the caller cat = attrs[:category] || example(:category) { # The category set_name is random, we might get a material :name => cat.is_material? ? nil : Faker::Lorem.unique, :category => cat, :material_type => cat.is_material? ? example(:material_type) : nil } end optional_example do |obj| # you can modify the object directly obj.color = 'blue' # or just return more attributes { :size => 23 } end # anything_example will be alternate types of examples material_example do { :inv_category => example(:inv_category, :set_name => 'Materials'), :material_type => example(:material_type) } end bob_example { { :color => 'blue' }} #any name works Product.material_example #use autogenerated examples Product.bob_example Product.example Product.example(:category => nil) Product.example(:category => nil, :save => false) # intantiate the object w/o saving # use optional_example, for non-required attributes Product.example(:category => nil, :full => true) # a more complete example excerpt should 'list unique purchase_quotes' do quote = Quote.example(:full => true) pq1 = PurchaseQuote.example pq2 = PurchaseQuote.example pq2.purchase_quote_items << PurchaseQuoteItem.example(:quotable => quote.quotables[0], :vendor => pq2.vendor) quote.quotables.each do |q| pq1.purchase_quote_items << PurchaseQuoteItem.example(:quotable => q, :vendor => pq1.vendor) end list = quote.purchase_quotes list2 = list.uniq assert_equal list2.size, list.size end
This paste will be private.
From the Design Piracy series on my blog: