Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rspec测试SMTP连接_Ruby_Ruby On Rails 4_Rspec_Smtp_Actionmailer - Fatal编程技术网

Ruby Rspec测试SMTP连接

Ruby Rspec测试SMTP连接,ruby,ruby-on-rails-4,rspec,smtp,actionmailer,Ruby,Ruby On Rails 4,Rspec,Smtp,Actionmailer,使用RSpec,我想测试我的应用程序是否能够连接到我的SMTP服务器,而无需发送任何邮件 如何打开SMTP电子邮件服务器的连接(登录)并测试/查看收到的响应 smtp = Net::SMTP.new 'mail.example.com', example_port # smtp.enable_starttls_auto # uncomment this if starttls is needed # smtp.enable_tls # uncomment this if ss

使用RSpec,我想测试我的应用程序是否能够连接到我的SMTP服务器,而无需发送任何邮件

如何打开SMTP电子邮件服务器的连接(登录)并测试/查看收到的响应

smtp = Net::SMTP.new 'mail.example.com', example_port
# smtp.enable_starttls_auto # uncomment this if starttls is needed
# smtp.enable_tls           # uncomment this if ssl/tls is needed but starttls is not supported
smtp.start('mydomain.example.com') do
  expect{ smtp.authenticate 'me@mydomain.example.com', 'mypassword', 'plain' }.to_not raise_error
end
如果身份验证失败,调用
authenticate
将引发
Net::SMTPAuthenticationError


否则,它将返回一个<代码>::SMTP::响应< /代码>,并调用响应<代码>状态>代码>将返回<代码>“235”< /代码>。< /P>有两个邮件嘲弄的宝石(如嘲弄邮件),您可以使用,或者您可以考虑使用更多的系统测试。谢谢。我认为mailcatcher可能完成了我希望通过测试完成的大部分内容。为了使我的测试更精细,我希望测试电子邮件创建过程的元素,包括验证smtp设置。我知道我可以在配置中将smtp设置从测试切换到smtp,但这会使测试比我希望的更脆弱,或者至少是一个只在您必须记住切换某些其他设置的情况下才有效的测试。按照惯例,配置(包括smtp配置)是在文件中声明的(例如,

application.yml
),然后将其分解为几个阶段(
development
test
production
)。因此,您不必切换任何内容,测试也不会很脆弱-测试配置不应该是测试功能的一部分…另请参阅