前提・実現したいこと
現在rails tutorialで勉強を進めているのですが、テストを行うと予期せぬエラーが出てきてしまい何度かテストを実行してみるとコードをなにも変更していないのにも関わらずテストの結果が毎回変わります。
そもそもeach文を使っている箇所がないのにも関わらず
NoMethodError: undefined method `each' for nil:NilClass
が出るのも意味が理解できません。
これはどういう現象が起こっているのでしょうか?
お力を貸していただけると助かります。
初心者なので、もし情報が足りていなければ追加させてもらうのでそこはすみません。。。!
発生している問題・エラーメッセージ
Run options: --seed 47654
Running:
E
Error:
SiteLayoutTest#test_layout_links:
RuntimeError: database is locked
Error:
SiteLayoutTest#test_layout_links:
NoMethodError: undefined method `each' for nil:NilClass
rails test test/integration/site_layout_test.rb:5
..........
Finished in 12.876502s, 0.8543 runs/s, 1.0873 assertions/s.
11 runs, 14 assertions, 0 failures, 1 errors, 0 skips
Run options: --seed 4647 # Running: E Error: StaticPagesControllerTest#test_should_get_help: RuntimeError: database is locked Error: StaticPagesControllerTest#test_should_get_help: NoMethodError: undefined method `each' for nil:NilClass rails test test/controllers/static_pages_controller_test.rb:20 E Error: StaticPagesControllerTest#test_should_get_about: RuntimeError: database is locked Error: StaticPagesControllerTest#test_should_get_about: NoMethodError: undefined method `each' for nil:NilClass rails test test/controllers/static_pages_controller_test.rb:26 E Error: StaticPagesControllerTest#test_should_get_home: RuntimeError: database is locked Error: StaticPagesControllerTest#test_should_get_home: NoMethodError: undefined method `each' for nil:NilClass rails test test/controllers/static_pages_controller_test.rb:14 E Error: SiteLayoutTest#test_layout_links: RuntimeError: database is locked Error: SiteLayoutTest#test_layout_links: NoMethodError: undefined method `each' for nil:NilClass rails test test/integration/site_layout_test.rb:5 ....... Finished in 28.069516s, 0.3919 runs/s, 0.2850 assertions/s. 11 runs, 8 assertions, 0 failures, 4 errors, 0 skips エラーメッセージ
該当のソースコード
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
def setup
@base_title = "Ruby on Rails Tutorial Sample App"
end
test "should get root" do
get root_path
assert_response :success
end
test "should get home" do
get root_path
assert_response :success
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
test "should get help" do
get help_path
assert_response :success
assert_select "title", "Help | #{@base_title}"
end
test "should get about" do
get about_path
assert_response :success
assert_select "title", "About | #{@base_title}"
end
test "should get contact" do
get contact_path
assert_response :success
assert_select "title", "Contact | #{@base_title}"
end
end
require 'test_helper'
class UsersControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get signup_path
assert_response :success
end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "user@example.com")
end
test "should be valid" do
assert @user.valid?
end
test "name should be present" do
@user.name = " "
assert_not @user.valid?
end
test "name should not be too long" do
@user.name = "a" * 51
assert_not @user.valid?
end
test "email should not be too long" do
@user.email = "a" * 244 + "@example.com"
assert_not @user.valid?
end
end
require 'test_helper'
class SiteLayoutTest < ActionDispatch::IntegrationTest
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_path, count: 2
assert_select "a[href=?]", help_path
assert_select "a[href=?]", about_path
assert_select "a[href=?]", contact_path
end
end
試したこと
一度全てコピペでやり直ししてみたのですが同じようなことが起こります。
補足情報(FW/ツールのバージョンなど)
Rails 6.0.3
windows10