【发布时间】:2013-03-04 19:12:05
【问题描述】:
我是 Rails 新手 :) 我试图运行我的第一个测试。为什么这个测试会通过?用户名应该至少有 2 个字符,我的用户名有更多并且仍然通过测试。
user.rb:
validates :username, :length => { :minimum => 2 }
user_spec.rb
require 'spec_helper'
describe User do
before do
@user = User.new(username: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
describe "when name is not present" do
before { @user.username="aaaahfghg" }
it { should_not be_valid } end
end
【问题讨论】:
-
我没有看到用户名长度的测试。验证也是最小 2 的任何超过 2 的将通过验证。
标签: ruby-on-rails ruby-on-rails-3 rspec-rails