6
4

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.

Railsチュートリアル中にcould not find expected ':' while scanning a simple keyが出た時の対処法

Posted at

発生した章

13.2.3 プロフィール画面のマイクロポストをテストするにて、リスト 13.27: ユーザーと関連付けされたマイクロポストのfixtureの内容を修正したら、テストでエラーが出るようになった。

発生したエラー内容

ERROR["test_should_redirect_edit_when_not_logged_in", UsersControllerTest, 3.9885445390827954]
 test_should_redirect_edit_when_not_logged_in#UsersControllerTest (3.99s)
ActiveRecord::Fixture::FormatError:         ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/ubuntu/workspace/sample_app/test/fixtures/microposts.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html
        The exact error was:
          Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 24 column 1

原因

ymlファイル内の属性に:がないため。

今回の原因

micropost_<%= n %>に、:がついていない

/sample_app/test/fixtures/microposts.yml
<% 30.times do |n| %>
micropost_<%= n %>
  content: <%= Faker::Lorem.sentence(5) %>
  created_at: <%= 42.days.ago %>
  user: michael
<% end %>

修正方法

micropost_<%= n %>に、:をつける

/sample_app/test/fixtures/microposts.yml
<% 30.times do |n| %>
micropost_<%= n %>:

無事にエラーが解決しました。

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?