html - rspec 测试失败,但应该通过

标签 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 发送带有 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/

相关文章:

python - Python 单元测试应该在一个单独的模块中吗?

jquery - 滚动背景

javascript - 显示 AM 但不显示年/月/日的 Datetime-local 值

html - h1 元素的有效角色属性值

Javascript 打印 div 在 Safari 中不起作用

ruby-on-rails - 简单的测试应用程序部署到 Heroku 但无法运行

database - JMeter 线程运行一次,而循环计数器设置为 'forever',具有恒定的吞吐量计时器

ruby-on-rails - bundler ,Rails3 : how to avoid git check of edge gems in :test group during deploying?

ruby-on-rails - 密码更新时出现未经授权的错误设计

java - Junit 4,如何禁用每个测试方法创建新的测试实例