次のコード:
describe Task do
let(:task) { Task.new }
subject { task }
before(:each) do
task.valid?
p task.errors.full_messages
end
it { should have(1).error_on(:title) }
it { should have(1).error_on(:description) }
end
出力:["Title can't be blank", "Title can't be blank", "Title can't be blank"]
そして私はこれが起こる特定の理由を理解することはできませんが、私が物事を経験する方法は、letとsubjectがあまりうまく機能しないということです笑
次のコードでも同じエラーが発生します。
it "should have 1 error on title" do
Task.new.should have(1).error_on(:title)
end
it "should have 1 error on description" do
Task.new.should have(1).error_on(:description)
end