我一直在分析代码,但找不到答案。
我在运行下一个规范时遇到错误:
describe 'with valid information' do
before {
fill_in 'Name', with: 'Example User'
fill_in 'Email', with: 'user@example.com'
fill_in 'Password', with: 'foobar'
fill_in 'Confirmation', with: 'foobar'
}
it 'should create a user' do
expect {click_button submit}.to change(User, :count).by(1)
end
describe "after saving the user" do
before {click_button submit}
let(:user) {User.find_by_email('user@example.com')}
it {should have_selector('title', text:user.name)}
it {should have_selector('div.alert.alert-success', text: "Welcome")}
end
end
错误出在“保存用户后”部分,并检查选择器 div.alert.alert-success:
Failure/Error: it {should have_selector('div.alert.alert-success', text: "Welcome")}
expected css "div.alert.alert-success" with text "Welcome" to return something
我的 users_controller 发送带有 key 成功的闪存哈希:
flash[:succes] = "Welcome"
redirect_to @user
甚至成功注册也会在页面中发送带有 class="alert alert-success"的标签 div:
<div class="alert alert-succes">
Welcome
</div>
有没有办法知道是什么在测试中呈现click_button 提交,以便我可以看到发生了什么?在控制台中查看生成的 HTML 的一些方法
注意 值得一提的是,如果我将测试更改为仅should have_selector('div.alert', text: "Welcome"(没有>alert-success 类),它通过了
提前致谢
最佳答案
查找并将“succes”替换为“success”。应该有帮助
关于html - rspec 测试失败,但应该通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19474103/