5

このテストは、Capybaraを使用してRailsアプリで行います。

within "#register" do
  fill_in "Biography (optionnal)", :with => "Hello world!"
end

click_on "Save"

# Check that form is repopulated with old input
expect(find_field('user_bio').value).to eq('Hello world!')

これが私がテストから得たものです:

Failure/Error: expect(find_field('user_bio').value).to eq('Hello world!')   
expected: "Hello world!"
got: "\nHello world!"

user_bioフィールドに手動で改行を追加することはありません。

これはどこから来るのでしょうか?

編集1: グーグルをした後、GithubにそのためのPRがあったようで、マージされました。だから、それはカピバラのバグではないと思います。https://github.com/jnicklas/capybara/commit/755a724d4b10e6841a0eeb58af43375236b33247を参照してください

4

1 に答える 1

0

保存前にフィルターを実行して、その新しい行をクリアできます

あなたのモデルに追加

 before_save :clear_new_lines

 protected
 def clear_new_lines
   self.user_bio = user_bio.gsub("\n",'')
 end
于 2013-08-31T03:33:02.847 に答える