Ruby on rails 使用RSpec新语法进行money-rails测试的模型
这里是RubyonRails的新手 我正在做一个有资金支持的应用程序。我想测试一下你的钱 读了这本书,就有了Ruby on rails 使用RSpec新语法进行money-rails测试的模型,ruby-on-rails,ruby,rspec3,money-rails,Ruby On Rails,Ruby,Rspec3,Money Rails,这里是RubyonRails的新手 我正在做一个有资金支持的应用程序。我想测试一下你的钱 读了这本书,就有了 let(:product) do Product.create(:price_cents => 3000, :discount => 150, :bonus_cents => 200, :sale_price_amount => 1200) end ... describe "monetize matcher" do ... it
let(:product) do
Product.create(:price_cents => 3000, :discount => 150,
:bonus_cents => 200,
:sale_price_amount => 1200)
end
...
describe "monetize matcher" do
...
it "matches model attribute with currency specified by :with_currency chain" do
product.should monetize(:bonus_cents).with_currency(:gbp)
end
...
end
如有关的
所以测试通过了。我将如何按照最近的语法重写该测试?我会试试看
expect(monetize(:bonus_cents).with_currency(:gbp)).to be true
但它失败了
product.should monetize(:bonus_cents).with_currency(:gbp)
结果是:
expect(product).to monetize(:bonus_cents).with_currency(:gbp)
expect
只需包装被测试的对象,其余的匹配器通常是相同的。尝试:expect(产品)。使用货币(:gbp)进行货币化(:奖金)
并且您不应该测试gem功能,因为它已经存在tested@IS04不要那样做。
expect(product).to monetize(:bonus_cents).with_currency(:gbp)