From 408174f2c5e923aaa76c8e3e199d7554ac577329 Mon Sep 17 00:00:00 2001 From: Daniel Duvall Date: Tue, 5 Mar 2013 10:27:44 -0800 Subject: [PATCH] Refactored error-generation spec to use inline fixture --- .../matchers/active_model/helpers_spec.rb | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/spec/shoulda/matchers/active_model/helpers_spec.rb b/spec/shoulda/matchers/active_model/helpers_spec.rb index 291e93d9..9921f462 100644 --- a/spec/shoulda/matchers/active_model/helpers_spec.rb +++ b/spec/shoulda/matchers/active_model/helpers_spec.rb @@ -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