Home>

Currently, I am testing the instance variable of the article list display function using RSpec and factory_bot.
As shown below, I get an error, but I referred to the reference and other people's articles, but I could not understand what was the cause and the work stopped.
Excuse me, but if you have any knowledge, please teach me.

What is currently happening?
ArticlesController GET #index @articles contains the correct value
     Failure/Error: expect (assigns (: articles)). to match (articles.sort {| a, b | b.created_at<=>a.created_at})
       expected # ]>to match [# , # , # ]
       Diff:
       @@ -1,4 +1,22 @@
       -[# ,
       -# ,
       -# ]
       + [# ,
       + # ,
       + # ]
     # ./spec/controllers/articles_controller_spec.rb:30: in `block (3 levels) in<top (required)>'
association
//user.rb
has_many: articles, dependent:: destroy
//article.rb
belongs_to: user
articles_controller_spec.rb
describe'GET #index' do
    it "@articles contains the correct value" do
      articles = create_list (: article, 3)
      get: index
      expect (assigns (: articles)). to match (articles.sort {| a, b | b.created_at<=>a.created_at})
    end
articles_controller.rb
def index
    @articles = Article.includes (: user) .order (id: "DESC"). page (params [: page]). per (10)
  end
factories/articles.rb
FactoryBot.define do
  factory: article do
    title {"title"}
    content {"content"}
    created_at {Faker :: Time.between (from: DateTime.now --2, to: DateTime.now)}
    user
  end
end
factories/users.rb
FactoryBot.define do
  factory: user do
    nickname {"abe"}
    password {"00000000"}
    password_confirmation {"00000000"}
    sequence (: email) {Faker :: Internet.email}
  end
end
environment

Rails 6.0.3.4
Ruby 2.6.6
rspec-rails 4.0.1