0
當試圖編寫名爲Test
的模型的規格時,我與Test:Module
發生衝突。如何使用rspec編寫名爲Test的模型的規格
這裏是我的代碼:
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
如果有人知道如何正確地寫這個,謝謝。
我想,如果你走這條路,這可能不是你最後的障礙。我嘗試通過運行'rails generate scaffold Test title:string description:string'來重現它,但Rails用'The name'Test'已經在您的應用程序中使用或由Ruby on Rails保留的消息拒絕它。請選擇一個替代品並再次運行此生成器.' – Amir 2014-09-21 08:10:17
謝謝,我將使用替代名稱,如「Teste」 – 2014-09-21 11:32:13
使用「測試」作爲模型名稱可能是一個壞主意。它可能與Ruby或Rails中的保留字發生衝突。 – 2014-09-21 08:43:16