Ruby on rails 轨道。水豚填充查找文本输入,但不';不要填写

Ruby on rails 轨道。水豚填充查找文本输入,但不';不要填写,ruby-on-rails,ruby,rspec,capybara,Ruby On Rails,Ruby,Rspec,Capybara,所以我在Rails应用程序中有这个特性规范 require 'rails_helper' feature 'As a signed in user' do let(:user) {create(:user)} let(:article) { create(:article)} before {login_as(user, :scope => :user )} scenario 'I can edit article with valid attributes' do

所以我在Rails应用程序中有这个特性规范

require 'rails_helper'

feature 'As a signed in user' do
  let(:user) {create(:user)}
  let(:article) { create(:article)}
  before {login_as(user, :scope => :user )}

  scenario 'I can edit article with valid attributes' do
    visit edit_article_path(article)
    puts current_path
    fill_in 'article_name', with: 'Valid name'
    fill_in 'article_content', with: 'Valid content'
    # save_and_open_page
    click_button 'Update Article'
    expect(article.name).to eq 'Valid name'
  end
end
fill\u in
实际上并没有用
有效名称
有效内容
填充输入字段。我通过保存和打开页面来调试它,值保持不变,所以我想这不是Rails应用程序的问题,而是水豚的问题。在未来的其他规范中:

require 'rails_helper'

feature 'As a signed in user' do
  let(:user) {create(:user)}
  let(:article) { build(:article)}
  before {login_as(user, :scope => :user )}

  scenario 'I can create article with valid attributes' do
    visit '/articles/new'
    fill_in 'Name', with: article.name
    fill_in 'article_content', with: article.content
    expect {click_button 'Create Article'}.to change {Article.count}.by(1)
  end
end
一切正常。我得到的错误是:

Failures:

  1) As a signed in user I can edit article with valid attributes
     Failure/Error: expect(article.name).to eq 'Valid name'

       expected: "Valid name"
            got: "Name1"

       (compared using ==)
     # ./spec/features/articles/article_update_spec.rb:15:in `block (2 levels) in <top (required)>'
故障:
1) 作为登录用户,我可以编辑具有有效属性的文章
失败/错误:预期(article.name)。为eq“有效名称”
应为“有效名称”
得到:“名字1”
(使用==进行比较)
#./spec/features/articles/article\u update\u spec.rb:15:in'block(2级)in'

原因是什么以及如何通过规范?

您似乎正在使用机架测试驱动程序,因为您的测试没有标记为js:true。假设这是真的,您的问题是
文章
已经在内存中,并且在检查名称更改之前没有从数据库重新加载。将测试更新为以下内容将强制重新加载,然后测试应通过

expect(article.reload.name).to eq 'Valid name'
如果您没有使用rack test驱动程序,则单击\按钮将是异步的,并且您将遇到其他问题,因为您在检查数据库对象更改之前没有在浏览器中检查更改