我是 Rails 新手 :) 我正在尝试运行我的第一个测试。为什么这个测试通过?用户名应该至少有 2 个字符,我的用户名有更多并且它仍然通过测试。
用户.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