Rspec模型验证

时间:2013-04-06 19:51:00

标签: ruby-on-rails-3 rspec

我尝试在轨道3中使用TDD Rspec进行模型验证。
我的user_spec.rb文件看起来像

require 'spec_helper'

describe User do

before { @user = User.new(name: "eric", country: "hawaii", email: "nice@nice.ch", password: "nicenice") }

subject { @user }

it { should respond_to(:name) }
it { should respond_to(:email) }

it { should be_valid }

end  

运行rspec spec / models / user_spec.rb后,收到错误消息

No DRb server is running. Running in local process instead ...
..F

Failures:

  1) User 
     Failure/Error: it { should be_valid }
     TypeError:
       type mismatch: String given
     # ./spec/models/user_spec.rb:37:in `block (2 levels) in <top (required)>'

Finished in 0.09495 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/models/user_spec.rb:37 # User 

Randomized with seed 42015

应该be_valid预期一个字符串吗?

0 个答案:

没有答案