我被困在RSpec中的一个规范上。如何更新模型的属性使其为零?在更新控制器规范下进行验证更好吗?
下面是一个示例代码。
describe User do
describe ".validation" do
before(:each) do
@user = User.create!({
:username => "dexter_morgan"
})
end
...
context "given invalid attributes" do
# how can I make the username nil?
it "rejects blank username"
end
end
end
这应该足够了吗?
describe User do
describe ".validation" do
before(:each) do
@user = User.create!({
:username => "dexter_morgan"
})
end
...
context "given invalid attributes" do
it "rejects blank username" do
@user.username = nil
@user.should_not be_valid
end
end
end
end