【发布时间】:2013-03-08 08:57:38
【问题描述】:
我在 Rails 上使用 ruby。我也使用 minitest 框架进行测试,使用 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之类的东西? -
太糟糕了,你不使用 rspec:github.com/evansagge/mongoid-rspec
标签: ruby-on-rails ruby testing model mongoid