我有一个请求规范,它一直传递到我需要检查页面上是否存在内容的地方,这是我page.should have_content
用来做的。内容实际上是在成功提交表单时出现的消息,它是从消息部分呈现的。即使我通过浏览器进行测试,测试也会失败,功能会按预期工作并且内容会按应有的方式显示。我还使用 FactoryGirl 生成用于表单提交的用户。
这是我在使用 --format d 选项运行规范后得到的错误:
UserSignup
shows a thank you message on successful form submission (FAILED - 1)
Failures:
1) UserSignup shows a thank you message on successful form submission
Failure/Error: page.should have_content("Thank you. You will be notified of our launch at #{user.email}.")
expected #has_content?("Thank you. You will be notified of our launch at quinn.purdy@casperzboncak.org.") to return true, got false
# ./spec/requests/user_signup_spec.rb:21:in `block (2 levels) in <top (required)>'
user_signup_spec.rb:
require 'spec_helper'
describe "UserSignup" do
it "shows a thank you message on successful form submission" do
user = FactoryGirl.create(:user)
visit sign_up_path
fill_in "user_fullname", with: user.fullname
fill_in "user_email", with: user.email
click_button "Sign up"
current_path.should eq(sign_up_path)
page.should have_content("Thank you. You will be notified of our launch at #{user.email}.")
end
end
users_controller.rb:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(secure_params)
if @user.valid?
@user.subscribe
flash[:notice] = "Thank you. You will be notified of our launch at #{@user.email}."
redirect_to sign_up_path
else
render :new
end
end
private
def secure_params
params.require(:user).permit(:fullname, :email)
end
end
我想知道是否可能是因为我将消息部分呈现在应用程序布局中,但是当它在用户视图中输出时,消息出现在body
源内部,但在main
类外部。