10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

テキストエリアの中身のテストをしたいときあるじゃん?

Last updated at Posted at 2014-04-11
new.html.haml
= form_for @course do |f|
  .field
    = f.label :title
    = f.text_field :title

  .field
    = f.label :body
    = f.text_area :body, value: '何かデフォルトの文章みたいなアレ'

  .submit-button
    = f.submit

的なテンプレートがあったとして、これの#course_bodyのデフォルト値がちゃんと正しく入ってるか的なテストを書きたいとする。
そんなときは、

course_spec.rb
require 'spec_helper'

feature 'Course' do
  describe 'new course' do
    scenario '新しいコースを作成する' do
      visit new_course_path

      fill_in 'course_title', with: 'なんかタイトル'

      # NOTE 大事なのココな
      textarea = find('#course_body')
      expect(textarea.value).to match /何かデフォルトの文章みたいなアレ/

      fill_in 'course_body', with: 'なんか違う文章'

      click_button 'Save'
    end
  end
end

って書くと上手くいくらしいよ( ˘ω˘)

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?