简体   繁体   English

rspec测试失败,但应该通过

[英]Failed rspec test but it should be passed

I've been analizing the code but i can't find an answer. 我一直在分析代码,但我找不到答案。

i get an error running the next spec: 运行下一个规范时出错:

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

the error is with the "after saving the user" part, and checking the selector div.alert.alert-success : 错误是“保存用户后”部分,并检查选择器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

My users_controller sends the flash hash with key success: 我的users_controller发送闪存哈希,密钥成功:

flash[:succes] = "Welcome"
redirect_to @user

and even the success sign-up sends a tag div with class="alert alert-success" in the page: 甚至成功注册在页面中发送带有class =“alert alert-success”的标记div:

<div class="alert alert-succes">
  Welcome
</div>

Is there a way to know what is rendering the click_button submit in the test so i can see what is going on? 有没有办法知道什么是在测试中呈现click_button提交所以我可以看到发生了什么? Some way to see the resulting HTML resulting from it in the console 某种方法可以在控制台中查看由此产生的HTML

Note It's worth it to say that if i change the test to only should have_selector('div.alert', text: "Welcome" (without the alert-success class), it passes 注意值得一提的是,如果我将测试更改为只有have_selector('div.alert',text:“Welcome” (没有alert-success类),它会通过

Thanks in advance 提前致谢

Find and replace "succes" with "success". 找到并取代“成功”的“成功”。 Should help 应该有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM