Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用RSpec新语法进行money-rails测试的模型_Ruby On Rails_Ruby_Rspec3_Money Rails - Fatal编程技术网

Ruby on rails 使用RSpec新语法进行money-rails测试的模型

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

这里是RubyonRails的新手

我正在做一个有资金支持的应用程序。我想测试一下你的钱

读了这本书,就有了

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)