当试图为名为Test
的模型编写规范时,我会与Test:Module
发生冲突。
这是我的代码:
require 'rails_helper'
RSpec.describe Test, :type => :model do
before { @test = Test.new(title: "Sample Test", description: "Description of sample test") }
subject { @test }
it { should respond_to(:title)}
it { should respond_to(:description)}
end
我得到错误
undefined method `new' for Test:Module
如果有人知道如何正确地写这篇文章,谢谢。
您可以通过将外部命名空间的Test
常量引用为::Test来显式引用它。否则,它与Rspec相关的Test
模块匹配。