次の分類モデルがあります。
# Mass assignable fields
attr_accessible :name, :classification, :is_shown
# Add validation
validates :name, :presence => true, :uniqueness => true
validates :classification, :presence => true
rspec + capybara を使用して、一意性バリデーターをテストしたいと考えています。
Taxonomy.create(:name => 'foo', :classification => 'activity').save!(:validate => false)
it { should validate_uniqueness_of(:name).scoped_to(:classification) }
このテストは次のエラーで失敗します。
Failure/Error: it { should validate_uniqueness_of(:name).scoped_to(:classification) }
Expected errors to include "has already been taken" when name is set to "foo", got errors: ["name has already been taken (\"foo\")", "classification is not included in the list (:activitz)"] (with different value of classification)
# ./spec/models/taxonomy_spec.rb:14:in `block (3 levels) in <top (required)>'
テストに合格するはずです。私は何が欠けていますか?