Skip to content

Instantly share code, notes, and snippets.

@ltello
Created September 19, 2012 15:41
Show Gist options
  • Save ltello/3750352 to your computer and use it in GitHub Desktop.
Save ltello/3750352 to your computer and use it in GitHub Desktop.
Validate uniqueness with Rspec matchers (not shoulda)
describe 'Category' do
context '#create' do
before(:all) do
@properties = {:code => 'TST', :description => 'Test Category'}
@category = Category.create(@properties)
@same_category = Category.create(@properties)
end
context 'When right properties given' do
it 'the category gets persisted' do
@category.should be_persisted
end
it 'unless code is not unique' do
@same_category.should_not be_persisted
@same_category.should have_at_least(1).errors_on(:code)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment