概要
RSpecを用いて、テストケースを実装しようとしました。
問題
bundle exec rspec spec/system/tasks_spec.rb
を実行したところ
以下のように文法エラーが出てテストが実行出来ない。
SyntaxError: (アプリのディレクトリ)/spec/system/tasks_spec.rb:17: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' ...ll_in 'パスワード', with 'password' ... ^
周りのコード
spec/system/tasks_spec.rb
Ruby
1require 'rails_helper' 2 3describe 'タスク管理機能', type: :system do 4 describe '一覧表示機能' do 5 before do 6 # ユーザーAを作成しておく 7 user_a = FactoryBot.create(:user, name: 'ユーザーA', email: 'a@example.com') 8 # 作成者がユーザーAであるタスクを作成しておく 9 FactoryBot.create(:task, name: '最初のタスク', user: user_a) 10 end 11 12 content 'ユーザーAがログインしているとき' do 13 before do 14 # ユーザーAでログインする 15 visit login_path 16 fill_in 'メールアドレス', with: 'a@example.com' 17 fill_in 'パスワード', with 'password' 18 click_button 'ログインする' 19 end 20 21 it 'ユーザーAが作成したタスクが表示される' do 22 # 作成済みのタスク名称が画面上に表示されていることを確認 23 expect(page).to have_content '最初のタスク' 24 end 25 end 26 end 27end
spec/factories/users.rb
ruby
1FactoryBot.define do 2 factory :user do 3 name { 'テストユーザー' } 4 email { 'test1@example.com' } 5 password { 'password' } 6 end 7 factory :task do 8 name { 'テストを書く' } 9 description { 'RSpec & Capybara & factoryを準備する' } 10 user 11 end 12end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/16 10:11