進出口新的軌道:) 我嘗試運行我的第一次測試。爲什麼這個測試通過?用戶名應至少有2個字符,我的用戶名更多,它仍然通過測試。RSpec的與色器件
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: "[email protected]",
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個則通過驗證。 – 2013-03-04 19:22:01