आरएसपीईसी का उपयोग करके एक्शनमेलर का परीक्षण करने के तरीके पर good tutorial है। यह वह अभ्यास है जिसका मैंने पालन किया है और यह अभी तक मुझे विफल नहीं हुआ है।
निम्नलिखित Notifier
मेलर और User
मॉडल मानते हुए:
ट्यूटोरियल दोनों रेल 3 और 4
मामले में टूट जाता है ऊपर के लिंक में ट्यूटोरियल के लिए काम करेंगे, यहाँ प्रासंगिक हिस्से हैं
class Notifier < ActionMailer::Base
default from: '[email protected]'
def instructions(user)
@name = user.name
@confirmation_url = confirmation_url(user)
mail to: user.email, subject: 'Instructions'
end
end
class User
def send_instructions
Notifier.instructions(self).deliver
end
end
और निम्न परीक्षण विन्यास:
# config/environments/test.rb
AppName::Application.configure do
config.action_mailer.delivery_method = :test
end
इस विषय पर मूल ब्लॉग पोस्ट के लिए लुकास Caton को
# spec/models/user_spec.rb
require 'spec_helper'
describe User do
let(:user) { User.make }
it "sends an email" do
expect { user.send_instructions }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
# spec/mailers/notifier_spec.rb
require 'spec_helper'
describe Notifier do
describe 'instructions' do
let(:user) { mock_model User, name: 'Lucas', email: '[email protected]' }
let(:mail) { Notifier.instructions(user) }
it 'renders the subject' do
expect(mail.subject).to eql('Instructions')
end
it 'renders the receiver email' do
expect(mail.to).to eql([user.email])
end
it 'renders the sender email' do
expect(mail.from).to eql(['[email protected]'])
end
it 'assigns @name' do
expect(mail.body.encoded).to match(user.name)
end
it 'assigns @confirmation_url' do
expect(mail.body.encoded).to match("http://aplication_url/#{user.id}/confirmation")
end
end
end
प्रॉप्स: 0
ये चश्मा आप क्या चाहते हैं आप मिलना चाहिए।
यह सवाल ऑफ-विषय के रूप में क्यों बंद है? –