Refactored error-generation spec to use inline fixture
This commit is contained in:
parent
26e12e98ca
commit
408174f2c5
|
@ -80,16 +80,11 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
|
|||
|
||||
if active_model_3_0?
|
||||
context 'if ActiveModel::Errors#generate_message behavior has changed' do
|
||||
subject { define_model(:divergent_example, :attr => :string) { validates_presence_of :attr }.new }
|
||||
|
||||
let(:message) { 'Oh snap. Behavior has diverged.' }
|
||||
|
||||
before(:each) do
|
||||
store_translations
|
||||
ActiveModel::Errors.any_instance.expects(:generate_message).with(:attr, :blank, {}).at_least_once.returns(message)
|
||||
it 'provides the right error message for validate_presence_of' do
|
||||
stub_active_model_message_generation(:type => :blank,
|
||||
:message => 'Behavior has diverged.')
|
||||
assert_presence_validation_has_correct_message
|
||||
end
|
||||
|
||||
it { should validate_presence_of(:attr) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -152,4 +147,12 @@ describe Shoulda::Matchers::ActiveModel::Helpers do
|
|||
|
||||
I18n.backend.store_translations(:en, translations)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue