我是功能测试和水豚的新手,我现在有一个真正简单的功能测试,我无法通过,但我相信这是因为我在编写测试时做错了。我会发布我的测试,让我知道是否有任何人跳出来并且是一个明显的开发错误。我认为这是我正在检查的事情吗?
require "rails_helper"
RSpec.feature "Send a message" do
scenario "Staff can send a message" do
visit "/"
group = Group.create!(name: "Group A")
user = User.create!(email: "staff@example.com", password: "password")
fill_in "Email", with: "staff@example.com"
fill_in "Password", with: "password"
click_button "Sign in"
fill_in "Enter a Message:", with: "Test Message"
check("message_group_#{group.id}")
click_button "Send Message"
expect(page).to have_content("Messages on their way!")
end
这是我收到的错误消息。
Send a message Staff can send a message
Failure/Error: expect(page).to have_content("Messages on their way!")
expected to find text "Messages on their way!" in "Tulip Time Text Numbers Sent Messages Scheduled Messages Statistics staff@example.com Logout SMS Notifications Use this form to send SMS notifications to Visitors, Staff or Volunteers. Enter a Message: Groups: Group A Scheduled Text Message:"
Message.rb
def create
@message = Message.create(message_params)
if @message.save
run_at_time = @message.send_at.present? ? @message.send_at : Time.zone.now
people = Person.in_groups(message_params[:group_ids])
if people.any?
people.each do |person|
person.delay(run_at: run_at_time).send_message(@message.body)
end
flash[:success] = "Messages on their way!"
end
redirect_to root_path
else
render "new"
end
end
答案 0 :(得分:1)
您作为测试数据创建的组为空,因此未设置闪存消息。您可能希望使用其中一个工厂库(FactoryGirl,Machinist等)来帮助构建对象,而不必每次都提供所有值,并且还需要构建所需的关联。而不是手动创建对象。