質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

506閲覧

rails tutorial 6章を終えて起きるテストのエラー

hiei1

総合スコア52

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

1グッド

1クリップ

投稿2022/05/14 03:33

初心者です。
rails tutorial 6章まで終えてgitにあげる前にrails testを行ったらこのようなエラーが出ました。

error

1# Running: 2 3E 4 5Error: 6StaticPagesControllerTest#test_should_get_help: 7ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked 8 9 10Error: 11StaticPagesControllerTest#test_should_get_help: 12NoMethodError: undefined method `each' for nil:NilClass 13 14 15 16rails test test/controllers/static_pages_controller_test.rb:10 17 18E 19 20Error: 21StaticPagesControllerTest#test_should_get_about: 22RuntimeError: database is locked 23 24 25Error: 26StaticPagesControllerTest#test_should_get_about: 27NoMethodError: undefined method `each' for nil:NilClass 28 29 30 31rails test test/controllers/static_pages_controller_test.rb:16 32 33E 34 35Error: 36StaticPagesControllerTest#test_should_get_contact: 37RuntimeError: database is locked 38 39 40Error: 41StaticPagesControllerTest#test_should_get_contact: 42NoMethodError: undefined method `each' for nil:NilClass 43 44 45 46rails test test/controllers/static_pages_controller_test.rb:22 47 48E 49 50Error: 51StaticPagesControllerTest#test_should_get_home: 52ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked 53 54 55Error: 56StaticPagesControllerTest#test_should_get_home: 57NoMethodError: undefined method `each' for nil:NilClass 58 59 60 61rails test test/controllers/static_pages_controller_test.rb:4 62 63E 64 65Error: 66ApplicationHelperTest#test_full_title_helper: 67RuntimeError: database is locked 68 69 70Error: 71ApplicationHelperTest#test_full_title_helper: 72NoMethodError: undefined method `each' for nil:NilClass 73 74 75 76rails test test/helpers/application_helper_test.rb:4 77 78.....E 79 80Error: 81UserTest#test_name_should_be_present: 82ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked 83 test/models/user_test.rb:13:in `block in <class:UserTest>' 84 85 86rails test test/models/user_test.rb:11 87 88.....

エラーに書いてあるファイル書きます。

static_pages_controller_test.rb

1require 'test_helper' 2 3class StaticPagesControllerTest < ActionDispatch::IntegrationTest 4 test "should get home" do 5 get root_path 6 assert_response :success 7 assert_select "title", "Ruby on Rails Tutorial Sample App" 8 end 9 10 test "should get help" do 11 get help_path 12 assert_response :success 13 assert_select "title", "Help | Ruby on Rails Tutorial Sample App" 14 end 15 16 test "should get about" do 17 get about_path 18 assert_response :success 19 assert_select "title", "About | Ruby on Rails Tutorial Sample App" 20 end 21 22 test "should get contact" do 23 get contact_path 24 assert_response :success 25 assert_select "title", "Contact | Ruby on Rails Tutorial Sample App" 26 end 27 28end 29

application_helper_test.rb

1require 'test_helper' 2 3class ApplicationHelperTest < ActionView::TestCase 4 test "full title helper" do 5 assert_equal full_title, "Ruby on Rails Tutorial Sample App" 6 assert_equal full_title("Help"), "Help | Ruby on Rails Tutorial Sample App" 7 end 8 9end

user_test.rb

1require 'test_helper' 2 3class UserTest < ActiveSupport::TestCase 4 def setup 5 @user = User.new(name: "Example User", email: "user@example.com", 6 password: "foobar", password_confirmation: "foobar") 7 end 8 test "should be valid" do 9 assert @user.valid? 10 end 11 12 test "name should be present" do 13 @user.name = "" 14 assert_not @user.valid? 15 end 16 test "email should be present" do 17 @user.email = "" 18 assert_not @user.valid? 19 end 20 test "name should not be too long" do 21 @user.name = "a" * 51 22 assert_not @user.valid? 23 end 24 25 test "email should not be too long" do 26 @user.email = "a" * 244 + "@example.com" 27 assert_not @user.valid? 28 end 29 test "email validation should accept valid addresses" do 30 valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org 31 first.last@foo.jp alice+bob@baz.cn] 32 valid_addresses.each do |valid_address| 33 @user.email = valid_address 34 assert @user.valid?, "#{valid_address.inspect} should be valid" 35 end 36 end 37 test "email addresses should be unique" do 38 duplicate_user = @user.dup 39 @user.save 40 assert_not duplicate_user.valid? 41 end 42 test "password should be present (nonblank)" do 43 @user.password = @user.password_confirmation = " " * 6 44 assert_not @user.valid? 45 end 46 47 test "password should have a minimum length" do 48 @user.password = @user.password_confirmation = "a" * 5 49 assert_not @user.valid? 50 end 51end 52

user.yml

1

database.yml

1default: &default 2 adapter: sqlite3 3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 20 } %> 4 timeout: 20000 5 6development: 7 <<: *default 8 database: db/development.sqlite3 9 10# Warning: The database defined as "test" will be erased and 11# re-generated from your development database when you run "rake". 12# Do not set this db to the same as development or production. 13test: 14 <<: *default 15 database: db/test.sqlite3 16 17production: 18 <<: *default 19 database: db/production.sqlite3 20

試したこと

SQLite3::BusyException: database is locked:のエラーの解決を試しましたがダメでした。
何かいい解決策はあるでしょうか?

shinoharat👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問