2
0

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 3 years have passed since last update.

Railsチュートリアル 第10章 - 「div.paginationが無い」と言われてテストが失敗する場合

Last updated at Posted at 2019-11-27

何が起こったか

Railsチュートリアルも第10章まで進み、ユーザー一覧のテストを一通り書き終えました。しかし、以下のように「div.paginationが無い」と言われてテストが通りません。

# rails test test/integration/users_index_test.rb
Running via Spring preloader in process 12045
Started with run options --seed 11902

 FAIL["test_index_including_pagination", UsersIndexTest, 2.137264299992239]
 test_index_including_pagination#UsersIndexTest (2.14s)
        Expected at least 1 element matching "div.pagination", found 0..
        Expected 0 to be >= 1.
        test/integration/users_index_test.rb:12:in `block in <class:UsersIndexTest>'

  1/1: [===================================] 100% Time: 00:00:02, Time: 00:00:02

Finished in 2.14716s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips

解決

app/views/users/index.html.erbapp/controllers/users_controller.rbの記述に間違いがないのにテストが通らない場合、fixtureの記述を間違えているのが原因かもしれません。

私の場合は、fixtureにおける以下の記述間違いが原因でした。

test/fixtures/users.yml(抜粋)
  ...
  <% 30.times do |n| %>
- user_<% n %>:
+ user_<%= n %>:
    name:  <%= "User #{n}" %>
    email: <%= "user-#{n}@example.com" %>
    password_digest: <%= User.digest('password') %>
  <% end %>

これは気が付きにくい。

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?