我的应用程序发送包含绝对 URL 的电子邮件。
我在 config/environment/development.rb 中设置了主机
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
现在我想测试电子邮件是否包含有效的 url。使用正则表达式,我从电子邮件中取出完整的 url,并希望使用 Capybara 函数访问该地址。
mail = ActionMailer::Base.deliveries.last
address = mail.body.to_s[%r{http.+/edit}]
visit address;
但我不知道应该在 config/environment/test.rb 中设置什么主机
当我设置 localhost:3000 时,它会尝试连接到由rails server
命令启动的本地服务器。
你有什么想法来解决这个问题吗?