A new line is added when submitting a form with Capybara

I have this test in a Rails application using Capybara:

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!')

Here is what I get from the test:

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

I never add a new line to the user_bio field manually.

Where could this come from?

Edit 1: after some Googling, there seems to be a PR on Github for this, and it merged. Therefore, I think this is not a bug from Capybara. See https://github.com/jnicklas/capybara/commit/755a724d4b10e6841a0eeb58af43375236b33247

+5
source share
1 answer

you can do a filter before saving to clear this new line

in your model add

 before_save :clear_new_lines

 protected
 def clear_new_lines
   self.user_bio = user_bio.gsub("\n",'')
 end
0
source

All Articles