【发布时间】:2021-06-16 12:06:25
【问题描述】:
minitest 返回Expected nil to be truthy.
控制器动作处理以下语句
@cu = current_user.roleshopusers.where(shop_id: @site.shop_id).first
@cu_role = @cu.try(:role_id)
@cu_buyer = @cu.buyer
Rails.logger.info @cu.inspect
Rails.logger.info @cu.buyer
并且测试日志返回:
#<Roleshopuser id: 434940726, user_id: 7, shop_id: 31, role_id: 1, buyer: true, special_support: false, special_needs: nil, notes: nil, discount: 0.0, created_at: "2021-06-16 13:56:37.288691000 +0200", updated_at: "2021-06-16 13:56:37.288691000 +0200">
true
但是测试,同时返回具有相同方法定义的正确值,
puts current_user.id
puts current_user.roleshopusers.where(shop_id: @site.shop_id).first.buyer
puts @cu.inspect
assert @cu_buyer
没有可用的实例变量。
7
true
nil
那么这个测试应该怎么写呢?
【问题讨论】: