Я использую рельсы 3.1 + rspec и factory girl.
Моя проверка обязательного поля (validates_presence_of) работает.Как заставить тест использовать этот факт как «успех», а не как «неудача»
Спецификация:
describe "Add an industry with no name" do
context "Unable to create a record when the name is blank" do
subject do
ind = Factory.create(:industry_name_blank)
end
it { should be_invalid }
end
end
, но я получаю ошибку:
Failures:
1) Add an industry with no name Unable to create a record when the name is blank
Failure/Error: ind = Factory.create(:industry_name_blank)
ActiveRecord::RecordInvalid:
Validation failed: Name can't be blank
# ./spec/models/industry_spec.rb:45:in `block (3 levels) in <top (required)>'
# ./spec/models/industry_spec.rb:47:in `block (3 levels) in <top (required)>'
Finished in 0.20855 seconds
8 examples, 1 failure
Код модели:
class Industry < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
end
Заводской код:
Factory.define :industry_name_blank, :class => 'industry' do |industry|
industry.name { nil }
end