rspec测试失败,但应该通过

时间:2013-10-20 05:01:19

标签: html ruby-on-rails testing rspec

我一直在分析代码,但我找不到答案。

运行下一个规范时出错:

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发送闪存哈希并成功成功:

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

甚至成功注册都会在页面中发送带有class =“alert alert-success”的标记div:

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

有没有办法知道在测试中呈现 click_button submit 的内容,以便我可以看到发生了什么?某种方法可以在控制台中查看由此产生的HTML

注意值得一提的是,如果我将测试更改为仅应该has_selector('div.alert',文字:“欢迎”(没有 alert-success 类),它通过

提前致谢

1 个答案:

答案 0 :(得分:2)

用“成功”找到并取代“成功”。应该帮忙