我想用Ruby on Rails和mongoDB开发一个小型web应用程序。我使用Rails 3.0.3和mongoid-gem。现在我想用rspec做一些测试,但它不像我预期的那样工作。测试没有给出正确的结果。 这里是我想测试模型:使用mongoDB进行Rspec测试不起作用
class User
include Mongoid::Document
field :nickname, :type => String
field :email, :type => String
field :firstname, :type => String
field :lastname, :type => String
field :birthday, :type => Date
field :picture, :type => String
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :nickname, :presence => true
validates :email, :presence => true,
:format => { :with => email_regex }
end
,这里是不起作用的测试:
require 'spec_helper'
describe User do
before(:each) do
@attr = { :nickname => "Example", :email => "[email protected]" }
@unvalid = {:nickname => "Bla"}
end
...
it "should reject invalid email addresses" do
address = "[email protected],com"
invalid_email_user = User.new(@attr.merge(:email => address))
invalid_email_user.should_not be_valid
end
是不是有什么特别的,我必须知道,当我想要做的使用RSpec测试和mongoDB/mongoid?
感谢您的回答
您可以添加spec_helper的源代码吗? – 2011-03-09 16:16:38