Refactored error-generation spec to use inline fixture

This commit is contained in:
Daniel Duvall 2013-03-05 10:27:44 -08:00 committed by Jason Draper
parent 26e12e98ca
commit 408174f2c5
1 changed files with 12 additions and 9 deletions

View File

@ -80,16 +80,11 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
if active_model_3_0? if active_model_3_0?
context 'if ActiveModel::Errors#generate_message behavior has changed' do context 'if ActiveModel::Errors#generate_message behavior has changed' do
subject { define_model(:divergent_example, :attr => :string) { validates_presence_of :attr }.new } it 'provides the right error message for validate_presence_of' do
stub_active_model_message_generation(:type => :blank,
let(:message) { 'Oh snap. Behavior has diverged.' } :message => 'Behavior has diverged.')
assert_presence_validation_has_correct_message
before(:each) do
store_translations
ActiveModel::Errors.any_instance.expects(:generate_message).with(:attr, :blank, {}).at_least_once.returns(message)
end end
it { should validate_presence_of(:attr) }
end end
end end
end end
@ -152,4 +147,12 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
I18n.backend.store_translations(:en, translations) I18n.backend.store_translations(:en, translations)
end end
def stub_active_model_message_generation(options = {})
attribute = options.delete(:attribute) || :attr
message = options.delete(:message)
type = options.delete(:type)
ActiveModel::Errors.any_instance.expects(:generate_message).with(attribute, type, {}).at_least_once.returns(message)
end
end end