【发布时间】:2012-01-14 05:00:45
【问题描述】:
我目前有以下测试,看起来适合进行一点 DRY 治疗:
describe League do
context 'attributes validation' do
before(:each) do
@league = League.new
end
it 'should be invalid without a short_name' do
@league.attributes = valid_league_attributes.except(:short_name)
@league.should_not be_valid
@league.should have(1).error_on(:short_name)
@league.errors[:short_name].should == ["can't be blank"]
@league.short_name = 'NFL'
@league.should be_valid
end
it 'should be invalid without a long_name' do
@league.attributes = valid_league_attributes.except(:long_name)
@league.should_not be_valid
@league.should have(2).error_on(:long_name)
@league.errors[:long_name].should == ["can't be blank", 'is not included in the list']
@league.long_name = 'National Football League'
@league.should be_valid
end
end
end
是否有可能使用自定义匹配器或其他一些实用程序使这个更干燥?
【问题讨论】:
标签: ruby-on-rails-3 refactoring rspec2 dry