Ruby on rails Rspec覆盖未通过
这是我的错误:Ruby on rails Rspec覆盖未通过,ruby-on-rails,rspec,Ruby On Rails,Rspec,这是我的错误: 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
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_属性无法成功加载overiden 30000000。我不知道为什么,因为我已经在测试中设置了覆盖。顶部的错误消息来自一个测试,该测试希望在页面中找到40200000.0,即expectpage.to have_text40200000.0。您列出的测试中,没有一个会出现这种情况
您看到的错误是否可能来自另一个正在查找原始浮点值的测试,而不是格式良好的浮点值?您列出的测试错误似乎与您列出的任何测试都不对应,没有一个测试需要字符串40200000.0。是的,这就是问题所在,中间的测试是失败的,它从属性中提取40200000,并且不接受覆盖,正如你看到的30000000:-我不理解。顶部的错误消息来自一个测试,该测试希望在页面中找到40200000.0,即expectpage.to有_text40200000.0。您列出的测试中,没有一个会出现这种情况。您是否可以包含运行您发布的3个测试的输出。您看到的错误是否可能来自另一个测试,该测试寻找原始浮点值,而不是格式良好的值?嗯,我看到了Alex。说到点子上,我会快速看一看。啊,你说的对,这是另一个测试,如果你把你的评论写在一个答案里,我会认为是正确的,为此干杯。