0

我尝试在 rails 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 应该是一个字符串吗?

4

0 回答 0