Model: Traits - convio/watirmark GitHub Wiki
There are times where you'd like to be able to share sets of defaults across models. You can accomplish this by packaging defaults into 'traits' which can be reused across model definitions. The traits themselves can also take traits.
module Watirmark::Model
trait :some_trait_name do
keyword_name {value}
traits :nested_trait #This is only if you want to have nested traits
end
end
These traits are global to the Watirmark::Model namespace so be careful that you're using names that are generic but won't collide. This can then be included in a model definition.
class MyModel < Watirmark::Model::Factory
traits :some_trait_name # you can declare one or more traits here
end
Here's a more practical example of how traits could be used:
module Watirmark::Model
trait :billing_address do
billing_street {"555 Main St"}
billing_city {"Austin"}
billing_state {"TX"}
billing_zip {"78758"}
end
trait :credit_card do
cardnumber {4111111111111111}
end
end
module UserDonations
class DonorModel < Watirmark::Model::Factory
keywords DonorView.keywords
traits :billing_address, :credit_card
defaults do
first_name {"first_#{uuid}"}
last_name {"last_#{uuid}"}
end
end
class TeamRaiserDonorModel < Watirmark::Model::Factory
keywords TeamRaiserDonorView.keywords
traits :billing_address, :credit_card
defaults do
first_name {"first_#{uuid}"}
last_name {"last_#{uuid}"}
reg_user_name {"user_#{uuid}"}
reg_password {"password"}
end
end
end