如何使用rspec为名为Test的模型编写规范



当试图为名为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模块匹配。

相关内容

最新更新