I'm trapped on one spec in RSpec. How can I update a model's attribute to make it nil? Is better to validate under update controller spec?
Below is a sample code.
describe User do
describe ".validation" do
before(:each) do
@user = User开发者_StackOverflow社区.create!({
:username => "dexter_morgan"
})
end
...
context "given invalid attributes" do
# how can I make the username nil?
it "rejects blank username"
end
end
end
This should be enough?
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
精彩评论