【发布时间】:2018-12-18 08:03:07
【问题描述】:
我的产品类别规范:-
require 'rails_helper'
RSpec.describe ProductCategory, type: :model do
before(:each) do
@product_category = create(:product_category)
end
context "validations" do
it "should have valid factory" do
expect(@product_category).to be_valid
end
it "should have unique name" do
product_category_new = build(:product_category, name: @product_category.name)
expect(product_category_new.save).to be false
end
end
end
规范运行良好,但是当我使用 before(:all) 而不是 before(:each) 时,第二个示例失败 -expected false got true 我知道 before(:all) 和 before(:each) 之间的区别) 但我无法找到第二个示例在 before(:all) 失败的确切原因
【问题讨论】:
-
失败并出现什么错误?
-
因预期错误而失败?还是有其他错误?我猜对了类别名称应该是唯一的吗?你使用数据库清理器还是
config.use_transactional_fixtures?
标签: ruby-on-rails rspec ruby-on-rails-5 factory-bot