黄瓜来测试电子邮件解析?

发布于 2024-10-21 21:38:29 字数 629 浏览 2 评论 0原文

这是我的第一个 stackoverflow 问题。

我正在构建一个从 SendGrid 发布电子邮件的应用程序,然后我想在延迟的作业中解析该电子邮件。

我关心的是如何对此进行质量检查。我一直在阅读有关 Cucumber 的内容,这听起来像是一个很好的解决方案,但我无法弄清楚端到端的测试流程。

到目前为止,这就是我所在的位置。

  1. 我想要一个包含各种类型的电子邮件正文的 TXT 文件的大列表
  2. ,然后迭代每个 txt 文件,并确保当传递到我的 lib 目录 /mailingjob.rb 中的方法时,返回的内容与定义的内容匹配在黄瓜中。

所以到目前为止我所得到的是这样的:

expected = File.open('???/mail1.txt', 'r') do |f|
  f.read
end

那就是我要开始的地方。因此,如果可以的话,请帮助我理解以下内容:

  1. 所有这些 TXT 文件应该位于 Rails 项目目录中的哪里?
  2. 一个 e2e 示例展示了如何获取本地文本文件,将其传递给 /lib 目录中的方法,然后确保返回的内容等于为该文件路径设置的内容。

谢谢您提供的任何帮助

this is my first stackoverflow question.

I am building an app that gets posted an email from SendGrid, which I then want to parse in a delayed job.

My concern is how do I QA this. I have been reading about Cucumber and that sounds like a good solution but I can't figure out the end to end test flow.

Here's where I am so far.

  1. I want to have a large list of TXT files that include various types of email body's
  2. I then iterate through each txt file, and make sure that when passed to a method in my lib directory /mailingjob.rb, that what is returned matches something defined in cucumber.

So what I have so far is something like:

expected = File.open('???/mail1.txt', 'r') do |f|
  f.read
end

That's where I'm starting. So if you can, please help me understand the following:

  1. Where should all these TXT files be located in the rails project directory?
  2. One e2e example showing how to grab a local text file, pass it to a method in the /lib directory, and then make sure what is returned equals what is set for that file path.

Thank you thank you for any help you can provide

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执妄 2024-10-28 21:38:29
  1. 我可能会将这些文件存储在您的 testspec 目录中(取决于您使用的测试框架;您提到了 Cucumber,我对此不太熟悉)与,但我认为它使用一个名为 features 的目录)。实际上,您可以将它们放在您想要的任何位置,但是测试目录的某些子目录是有意义的。

  2. 如果您不熟悉 Cucumber 测试,我建议使用 Railscast 第 155 集 和第 159 集帮助您入门。要回答您的直接问题,您可以从文本文件中读取电子邮件

    email_text = File.read("#{Rails.root}/test/path/to/email.txt")
    

    Rails.root 始终引用项目的根目录,并且可以轻松构建其他文件或文件夹的路径。

  1. I would probably store these files somewhere in your test or spec directory (depending on what testing framework you use; you mentioned Cucumber, which I'm not super familiar with, but I think it uses a directory called features). Really, you could put them anywhere you want, but some subdirectory of your test directory makes sense.

  2. If you're not familiar with testing with Cucumber, I recommend Railscast episode 155 and episode 159 to get you started. To answer your direct question, you would read the email from the text file as such

    email_text = File.read("#{Rails.root}/test/path/to/email.txt")
    

    Rails.root always refers to the root directory for your project, and makes it easy to build paths to other files or folders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文