如何使用 rspec 在 Sinatra 应用程序中测试 Pony 电子邮件? [英] How do I test Pony emailing in a Sinatra app, using rspec?
问题描述
我正在试用 email_spec,它说它支持 Pony,但我不确定我将如何在 sinatra 应用程序中测试电子邮件.自述文件中的示例显示了 Rails ActionMailer
的用法,但 Pony 中没有.
I'm trying out email_spec, which says it supports Pony, but I'm not sure how I'd go about testing emails in a sinatra app. The examples in the readme show usages with rails ActionMailer
, but not in Pony.
使用 email_spec 并不宝贵,因此欢迎任何其他在 sinatra 中使用 rspec 测试电子邮件的想法 =)
Not precious about using email_spec, so any other ideas for testing emails using rspec in sinatra are welcomed =)
推荐答案
我最终查看了 小马规范文件,并从中窃取代码来编写我的规范 =)
I ended up looking at the pony spec file, and stealing code from it to write my specs =)
这就是我所拥有的:
./spec/spec_helper.rb
./spec/spec_helper.rb
def do_not_send_email
Pony.stub!(:deliver) # Hijack deliver method to not send email
end
RSpec.configure do |conf|
conf.include Rack::Test::Methods
conf.mock_with :rspec
# ...
conf.before(:each) do
do_not_send_email
end
end
./spec/integration/invite_user_spec.rb
./spec/integration/invite_user_spec.rb
require_relative '../spec_helper'
feature "Invite user" do
scenario "should send an invitation email" do
visit "/"
click_link "start-btn"
within_fieldset("Invite new user") do
fill_in 'new_user_email', :with => 'franz@gmail.com'
Pony.should_receive(:mail) { |params|
params[:to].should == "franz@gmail.com"
params[:subject].should include("You are invited to blah")
params[:body].should include("You've been invited to blah")
params[:body].should include("/#{@account_id}/new-user/register")
}
click_button 'new_user'
end
page.should have_content("Invitation email has been sent")
end
end
这篇关于如何使用 rspec 在 Sinatra 应用程序中测试 Pony 电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!