2016-05-25 12 views
2

は、だから私は実際にValid nameValid contentと入力フィールドを記入していない私のRailsアプリRails。カピバラFILL_INは、テキスト入力を見つけたが、

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_inに、この機能の仕様を持ってFILL_INしません。私は保存してページを開くことによってそれをデバッグし、値は同じですので、私はそれが私のRailsアプリケーションではなく、Capybaraで何か問題はないと思います。他の将来の仕様では:

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

あなたのテストはjs:trueとタグ付けされていないので、ラックテストドライバを使用しているようです。その場合は、articleが既にメモリにあり、名前の変更を確認する前にDBからリロードされないという問題があります。以下に、あなたのテストを更新すると、リロードを強制し、あなたがしてclick_buttonが非同期になりますラックのテストドライバーを使用していない場合は、あなたのテストは

expect(article.reload.name).to eq 'Valid name' 

を渡す必要がありますし、あなたがしているので、あなたは他の問題があるでしょうデータベースオブジェクトの変更をチェックする前に、ブラウザーの変更をチェックしないでください。

+0

素晴らしい!ありがとう、それは問題を解決しました。 –

関連する問題