这是我的错误:
1) Shows Movie show singular movie
Failure/Error: expect(page).to have_text(movie.total_gross)
expected to find text "40200000.0" in "Catwoman Description Patience Philips has a more than respectable career as a graphic designer Rating PG-13 Released On 2004-07-23 Total Gross $40,200,000.00 Cast Halle Berry, Sharon Stone and Benjamin Bratt Director Jean-Christophe 'Pitof' Comar Duration 101 min All Movies Edit Delete"
attributes.rb
def movie_attributes(overrides = {})
{
title: "Catwoman",
rating: "PG-13",
total_gross: 40200000.00,
description: "Patience Philips has a more than respectable career as a graphic designer",
released_on: "2004-07-23",
cast: "Halle Berry, Sharon Stone and Benjamin Bratt",
director: "Jean-Christophe 'Pitof' Comar",
duration: "101 min"
}.merge(overrides)
end
show_movie.spec.rb
it "Shows Flop! if total gross is under $20m " do
movie = Movie.create(movie_attributes(total_gross: 15000000.00))
visit movie_url(movie)
expect(page).to have_text("Flop!")
end
it "Shows total gross if total gross is between $20m and $50m" do
movie = Movie.create(movie_attributes(total_gross: 30000000.00))
visit movie_url(movie)
expect(page).to have_text("$30,000,000.00")
end
it "Shows Hot! if total gross is over $50m" do
movie = Movie.create(movie_attributes(total_gross: 60000000.00))
visit movie_url(movie)
expect(page).to have_text("Hot!")
end
由于某种原因,movie_attributes在第二次测试中未成功加载overiden 30000000。我不知道为什么,因为我已经在测试中设置了覆盖。
答案 0 :(得分:0)
顶部的错误消息来自期望找到" 40200000.0"在页面中 - 即expect(page).to have_text("40200000.0")
。您列出的测试都没有预料到这一点。
您可能看到的错误是否真的来自另一个寻找原始浮点值的测试,而不是格式化的值?