0

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

运行下一个规范时出现错误:

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 提交的内容,以便我可以看到发生了什么?在控制台中查看由此产生的 HTML 的某种方式

注意值得一提的是,如果我将测试更改为 only should have_selector('div.alert', text: "Welcome"(没有alert-success类),它会通过

提前致谢

4

1 回答 1

2

查找并将“成功”替换为“成功”。应该有帮助

于 2013-10-20T09:43:25.773 回答