17
Sự khác nhau giữa việc sử dụng eq
và eql
trong các thử nghiệm rspec là gì? Có một sự khác biệt giữa:Rspec `eq` so với` eql` trong các bài kiểm tra `mong đợi`
it "adds the correct information to entries" do
# book = AddressBook.new # => Replaced by line 4
book.add_entry('Ada Lovelace', '010.012.1815', '[email protected]')
new_entry = book.entries[0]
expect(new_entry.name).to eq('Ada Lovelace')
expect(new_entry.phone_number).to eq('010.012.1815')
expect(new_entry.email).to eq('[email protected]')
end
và:
it "adds the correct information to entries" do
# book = AddressBook.new # => Replaced by line 4
book.add_entry('Ada Lovelace', '010.012.1815', '[email protected]')
new_entry = book.entries[0]
expect(new_entry.name).to eql('Ada Lovelace')
expect(new_entry.phone_number).to eql('010.012.1815')
expect(new_entry.email).to eql('[email protected]')
end
Một chuyển đổi loại có nghĩa là nó đang tìm kiếm các đối tượng hoặc vật được so sánh với cùng một loại đối tượng? – austinthesing
@austinthesing nó có nghĩa là '42.0 == 42' tạo' true' và '42.0.eql? 42' tạo 'false'. –