我現在讓我的測試通過,但我想看看我是否可以重構一個let(:message)
測試或某種變量Rspec的和FactoryGirl.attributes_for PARAMS重構
梅勒的測試
describe "Contact Form" do
context "when a valid message" do
it "sends an email" do
post contact_create_path, message: FactoryGirl.attributes_for(:message)
expect(ActionMailer::Base.deliveries.last.to).to eq(["#{ENV["MVP_USERNAME"]}"])
end
end
我想要重構的部分是message: FactoryGirl.attributes_for(:message)
。 我試圖做這樣的事情
context "when a valid message" do
let(:message) { FactoryGirl.attributes_for(:message) }
it "sends an email" do
post contact_create_path, message
expect(ActionMailer::Base.deliveries.last.to).to eq(["#{ENV["MVP_USERNAME"]}"])
end
但輸出 ActionController::ParameterMissing: param not found: message
其他企圖
@message = FactoryGirl.attributes_for(:message)
message = FactoryGirl.attributes_for(:message)
我可以離開它這樣,但我覺得,我應該改變一些r陳奕迅。建議?