質問編集履歴

1

現状の確認内容を追記しました。

2021/09/11 22:58

投稿

TakagiMarin
TakagiMarin

スコア13

test CHANGED
File without changes
test CHANGED
@@ -227,3 +227,53 @@
227
227
  Ruby on Rails6
228
228
 
229
229
  rspec-rails 5.0.1
230
+
231
+
232
+
233
+ ### 追記
234
+
235
+
236
+
237
+ 以下の様に状況を確認してみました。
238
+
239
+ ```ruby
240
+
241
+ #_spec.rb
242
+
243
+ #こちらのテストは通りました
244
+
245
+ subject { user.id }
246
+
247
+ it {is_expected.to eq(user_profile.user_id)}
248
+
249
+
250
+
251
+ #こちらは通りません
252
+
253
+ subject { user.user_profile }
254
+
255
+ it {is_expected.to eq(user_profile)}
256
+
257
+
258
+
259
+ Failure/Error: it {is_expected.to eq(user_profile)}
260
+
261
+
262
+
263
+ expected: #<UserProfile id: 15, user_id: 95, name: "テストユーザー", birth_year: 2001, birth_month... updated_at: "2021-09-12 07:52:49.000000000 +0900">
264
+
265
+ got: nil
266
+
267
+ ```
268
+
269
+
270
+
271
+ ```ruby
272
+
273
+ #show.html.erb
274
+
275
+ #こちらはきちんと表示されます
276
+
277
+ <%= current_user.user_profile.id %>
278
+
279
+ ```