我被困在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
答案 0 :(得分:5)
这应该够了吗?
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