Sha256: 384e7ddd253436e768519cef17fe7118b5ee1865247f0d787552ca5cd8eaa782

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

RSpec.shared_examples_for "an object supporting to_money" do
  it "supports to_money" do
    expect(@value.to_money).to eq(@money)
    expect(@value.to_money('CAD').currency).to eq(Money::Currency.find!('CAD'))
  end
end

RSpec.describe Integer do
  before(:each) do
    @value = 1
    @money = Money.new("1.00")
  end

  it_should_behave_like "an object supporting to_money"

  it "parses 0 to Money.zero" do
    expect(0.to_money).to eq(Money.zero)
  end
end

RSpec.describe Float do
  before(:each) do
    @value = 1.23
    @money = Money.new("1.23")
  end

  it_should_behave_like "an object supporting to_money"

  it "parses 0.0 to Money.zero" do
    expect(0.0.to_money).to eq(Money.zero)
  end
end

RSpec.describe String do
  before(:each) do
    @value = "1.23"
    @money = Money.new(@value)
  end

  it_should_behave_like "an object supporting to_money"

  it "parses an empty string to Money.zero" do
    expect(''.to_money).to eq(Money.zero)
    expect(' '.to_money).to eq(Money.zero)
  end
end

RSpec.describe BigDecimal do
  before(:each) do
    @value = BigDecimal("1.23")
    @money = Money.new("1.23")
  end

  it_should_behave_like "an object supporting to_money"

  it "parses a zero BigDecimal to Money.zero" do
    expect(BigDecimal("-0.000").to_money).to eq(Money.zero)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify-money-0.14.8 spec/core_extensions_spec.rb
shopify-money-0.14.7 spec/core_extensions_spec.rb
shopify-money-0.14.6 spec/core_extensions_spec.rb
shopify-money-0.14.5 spec/core_extensions_spec.rb
shopify-money-0.14.4 spec/core_extensions_spec.rb
shopify-money-0.14.3 spec/core_extensions_spec.rb
shopify-money-0.14.2 spec/core_extensions_spec.rb