ArgumentError: SMTP To address may not be blank: []
ArgumentError: SMTP To address may not be blank: []
这里有点困惑,我正在 运行 rspec 测试我的 rails 应用程序并有一个模型规格:
it { should validate_uniqueness_of(:email).case_insensitive }
这是针对电子邮件对象的 3 个测试之一,它一直失败并出现以下错误:
1) User should validate that :email is case-insensitively unique
Failure/Error: it { should validate_uniqueness_of(:email).case_insensitive }
ArgumentError:
SMTP To address may not be blank: []
# ./spec/models/user_spec.rb:43:in `block (2 levels) in <top (required)>'
我不明白为什么在模型中测试该电子邮件地址需要任何 SMTP 收件人地址。
不确定要看什么帮助会很好,因为它是我唯一失败的测试:(
我认为唯一可能有帮助的其他东西是我 运行:
- ruby v2.5.0p0
- rails v5.1.6
- RSpec 3.7
- rspec-核心 3.7.1
- rspec-期望值 3.7.0
- rspec-模拟 3.7.0
- rspec-rails 3.7.2
- rspec-支持3.7.1
它似乎抛出了关于 看似 不相关元素的错误。然而,问题实际上出在您添加的用于发送电子邮件的代码中。您需要回顾您实际发送电子邮件的代码并检查您的 "To:" 属性.
就我而言,我收到了关于毫无意义的工厂的投诉......至少一开始没有。
An error occurred in a `before(:suite)` hook.
Failure/Error: FactoryBot.lint
FactoryBot::InvalidFactoryError:
The following factories are invalid:
* attachment - SMTP To address may not be blank: [] (ArgumentError)
* distance - SMTP To address may not be blank: [] (ArgumentError)
* structure - SMTP To address may not be blank: [] (ArgumentError)
然后我挖得更深。我追踪到邮件程序代码的错误,或者我认为:
admins = @organization.users.where(role: "org_admin").map(&:email)
mail(to: admins, subject: "New Structure Created")
但随后其他测试仍然失败。
事实证明,有时 to:
字段传递的实际值 缺失 由于某些测试 admins
和电子邮件不存在在场(因为他们不需要参加那些测试)。所以我 "protected" 通过简单的 if
检查来调用邮件程序:
mail(to: admins, subject: "New Structure Created") if admins.any?
这里有点困惑,我正在 运行 rspec 测试我的 rails 应用程序并有一个模型规格:
it { should validate_uniqueness_of(:email).case_insensitive }
这是针对电子邮件对象的 3 个测试之一,它一直失败并出现以下错误:
1) User should validate that :email is case-insensitively unique
Failure/Error: it { should validate_uniqueness_of(:email).case_insensitive }
ArgumentError:
SMTP To address may not be blank: []
# ./spec/models/user_spec.rb:43:in `block (2 levels) in <top (required)>'
我不明白为什么在模型中测试该电子邮件地址需要任何 SMTP 收件人地址。
不确定要看什么帮助会很好,因为它是我唯一失败的测试:(
我认为唯一可能有帮助的其他东西是我 运行:
- ruby v2.5.0p0
- rails v5.1.6
- RSpec 3.7
- rspec-核心 3.7.1
- rspec-期望值 3.7.0
- rspec-模拟 3.7.0
- rspec-rails 3.7.2
- rspec-支持3.7.1
它似乎抛出了关于 看似 不相关元素的错误。然而,问题实际上出在您添加的用于发送电子邮件的代码中。您需要回顾您实际发送电子邮件的代码并检查您的 "To:" 属性.
就我而言,我收到了关于毫无意义的工厂的投诉......至少一开始没有。
An error occurred in a `before(:suite)` hook.
Failure/Error: FactoryBot.lint
FactoryBot::InvalidFactoryError:
The following factories are invalid:
* attachment - SMTP To address may not be blank: [] (ArgumentError)
* distance - SMTP To address may not be blank: [] (ArgumentError)
* structure - SMTP To address may not be blank: [] (ArgumentError)
然后我挖得更深。我追踪到邮件程序代码的错误,或者我认为:
admins = @organization.users.where(role: "org_admin").map(&:email)
mail(to: admins, subject: "New Structure Created")
但随后其他测试仍然失败。
事实证明,有时 to:
字段传递的实际值 缺失 由于某些测试 admins
和电子邮件不存在在场(因为他们不需要参加那些测试)。所以我 "protected" 通过简单的 if
检查来调用邮件程序:
mail(to: admins, subject: "New Structure Created") if admins.any?