1
我在軌道上使用紅寶石。我也使用minitest框架進行測試,並使用mongoid作爲數據庫。我想寫一個模型測試。我的模型如下:測試字段在mongoid中輸入模型
class Identity
include Mongoid::Document
include OmniAuth::Identity::Models::Mongoid
field :name
field :email
field :password_digest
validates :name, uniqueness: true
end
模型試驗是:
describe Identity do
it "must include OmniAuth::Identity::Models::Mongoid" do
Identity.must_include OmniAuth::Identity::Models::Mongoid
end
it "should have name" do
Identity.new.must_respond_to :name
end
it "should have email" do
Identity.new.must_respond_to :email
end
it "should have password_digest" do
Identity.new.must_respond_to :password_digest
end
it "should type of String" do
Identity.new.name.type.must_equal "String"
end
end
我的問題是有關測試字段的類型
it "should type of String" do
Identity.new.name.type.must_equal "String"
end
如何測試一個字段的類型?提前致謝。
也許你需要像'Identity.new.name.is_a? String'? – 2013-03-08 09:00:55
太基地你不使用rspec:https://github.com/evansagge/mongoid-rspec – apneadiving 2013-03-08 09:19:18