diff --git a/lib/money/bank/base.rb b/lib/money/bank/base.rb index a791f79f44..2bf81eb5f8 100644 --- a/lib/money/bank/base.rb +++ b/lib/money/bank/base.rb @@ -2,7 +2,6 @@ class Money # Provides classes that aid in the ability of exchange one currency with # another. module Bank - # The lowest Money::Bank error class. # All Money::Bank errors should inherit from it. class Error < StandardError @@ -13,7 +12,6 @@ class Error < StandardError class UnknownRate < Error end - # Money::Bank::Base is the basic interface for creating a money exchange # object, also called Bank. # @@ -38,7 +36,6 @@ class UnknownRate < Error # +Money::Bank+ class. You can also override +#setup+ instead of # +#initialize+ to setup initial variables, etc. class Base - # Returns the singleton instance of the Base bank. # # @return [Money::Bank::Base] diff --git a/lib/money/bank/single_currency.rb b/lib/money/bank/single_currency.rb index ac3ffc1e8c..715f1ec819 100644 --- a/lib/money/bank/single_currency.rb +++ b/lib/money/bank/single_currency.rb @@ -13,7 +13,6 @@ class DifferentCurrencyError < Error; end # where exchanges happen are erroneous. Using this as the default bank # means that that these mistakes don't silently do the wrong thing. class SingleCurrency < Base - # Raises a DifferentCurrencyError to remove possibility of accidentally # exchanging currencies def exchange_with(from, to_currency, &block) diff --git a/lib/money/bank/variable_exchange.rb b/lib/money/bank/variable_exchange.rb index 972a0b163f..9c91ed50b8 100644 --- a/lib/money/bank/variable_exchange.rb +++ b/lib/money/bank/variable_exchange.rb @@ -41,13 +41,12 @@ class UnknownRateFormat < StandardError; end # # Get rate from redis # bank.get_rate 'USD', 'CAD' class VariableExchange < Base - attr_reader :mutex, :store # Available formats for importing/exporting rates. RATE_FORMATS = [:json, :ruby, :yaml].freeze SERIALIZER_SEPARATOR = '_TO_'.freeze - FORMAT_SERIALIZERS = {json: JSON, ruby: Marshal, yaml: YAML}.freeze + FORMAT_SERIALIZERS = { json: JSON, ruby: Marshal, yaml: YAML }.freeze # Initializes a new +Money::Bank::VariableExchange+ object. # It defaults to using an in-memory, thread safe store instance for @@ -220,7 +219,7 @@ def export_rates(format, file = nil, opts = {}) s = FORMAT_SERIALIZERS[format].dump(rates) unless file.nil? - File.open(file, "w") {|f| f.write(s) } + File.open(file, "w") { |f| f.write(s) } end s @@ -229,7 +228,7 @@ def export_rates(format, file = nil, opts = {}) # This should be deprecated. def rates - store.each_rate.each_with_object({}) do |(from,to,rate),hash| + store.each_rate.each_with_object({}) do |(from, to, rate), hash| hash[[from, to].join(SERIALIZER_SEPARATOR)] = rate end end diff --git a/lib/money/currency.rb b/lib/money/currency.rb index 77f58df520..85e966fd4c 100644 --- a/lib/money/currency.rb +++ b/lib/money/currency.rb @@ -5,7 +5,6 @@ require "money/currency/heuristics" class Money - # Represents a specific currency unit. # # @see https://en.wikipedia.org/wiki/Currency @@ -80,6 +79,7 @@ def find(id) def find_by_iso_numeric(num) num = num.to_s.rjust(3, '0') return if num.empty? + id, _ = self.table.find { |key, currency| currency[:iso_numeric] == num } new(id) rescue UnknownCurrency @@ -136,6 +136,7 @@ def all if c.priority.nil? raise MissingAttributeError.new(:all, c.id, :priority) end + c end.sort_by(&:priority) end @@ -206,7 +207,6 @@ def each all.each { |c| yield(c) } end - private def stringify_keys @@ -252,8 +252,8 @@ def stringify_keys # this currency) attr_reader :id, :priority, :iso_code, :iso_numeric, :name, :symbol, - :disambiguate_symbol, :html_entity, :subunit, :subunit_to_unit, :decimal_mark, - :thousands_separator, :symbol_first, :smallest_denomination + :disambiguate_symbol, :html_entity, :subunit, :subunit_to_unit, :decimal_mark, + :thousands_separator, :symbol_first, :smallest_denomination alias_method :separator, :decimal_mark alias_method :delimiter, :thousands_separator @@ -427,14 +427,14 @@ def exponent def initialize_data! data = self.class.table[@id] - @alternate_symbols = data[:alternate_symbols] - @decimal_mark = data[:decimal_mark] - @disambiguate_symbol = data[:disambiguate_symbol] - @html_entity = data[:html_entity] - @iso_code = data[:iso_code] - @iso_numeric = data[:iso_numeric] - @name = data[:name] - @priority = data[:priority] + @alternate_symbols = data[:alternate_symbols] + @decimal_mark = data[:decimal_mark] + @disambiguate_symbol = data[:disambiguate_symbol] + @html_entity = data[:html_entity] + @iso_code = data[:iso_code] + @iso_numeric = data[:iso_numeric] + @name = data[:name] + @priority = data[:priority] @smallest_denomination = data[:smallest_denomination] @subunit = data[:subunit] @subunit_to_unit = data[:subunit_to_unit] diff --git a/lib/money/money.rb b/lib/money/money.rb index 6d8ed73af1..71b2e428c4 100644 --- a/lib/money/money.rb +++ b/lib/money/money.rb @@ -1,4 +1,5 @@ # encoding: utf-8 + require "money/bank/variable_exchange" require "money/bank/single_currency" require "money/money/arithmetic" @@ -89,7 +90,6 @@ def round_to_nearest_cash_value # Class Methods class << self - # @!attribute [rw] default_bank # @return [Money::Bank::Base] Each Money object is associated to a bank # object, which is responsible for currency exchange. This property @@ -121,8 +121,8 @@ class << self # @return [Integer] Use this to specify precision for converting Rational # to BigDecimal attr_accessor :default_bank, :default_formatting_rules, - :use_i18n, :infinite_precision, :conversion_precision, - :locale_backend + :use_i18n, :infinite_precision, :conversion_precision, + :locale_backend end # @!attribute default_currency diff --git a/lib/money/money/arithmetic.rb b/lib/money/money/arithmetic.rb index 50bba94300..fc51446c83 100644 --- a/lib/money/money/arithmetic.rb +++ b/lib/money/money/arithmetic.rb @@ -55,9 +55,11 @@ def eql?(other_money) def <=>(other) unless other.is_a?(Money) return unless other.respond_to?(:zero?) && other.zero? + return other.is_a?(CoercedNumeric) ? 0 <=> fractional : fractional <=> 0 end return 0 if zero? && other.zero? + other = other.exchange_to(currency) fractional <=> other.fractional rescue Money::Bank::UnknownRate @@ -69,6 +71,7 @@ def ==(other) if other.is_a?(Numeric) && !other.zero? raise ArgumentError, 'Money#== supports only zero numerics' end + super end @@ -135,9 +138,11 @@ def negative? self.class.new(new_fractional, currency, bank) when CoercedNumeric raise TypeError, non_zero_message.call(other.value) unless other.zero? + self.class.new(other.value.public_send(op, fractional), currency) when Numeric raise TypeError, non_zero_message.call(other) unless other.zero? + self else raise TypeError, "Unsupported argument type: #{other.class.name}" @@ -188,6 +193,7 @@ def /(value) fractional / as_d(value.exchange_to(currency).fractional).to_f else raise TypeError, 'Can not divide by Money' if value.is_a?(CoercedNumeric) + self.class.new(fractional / as_d(value), currency, bank) end end diff --git a/lib/money/money/constructors.rb b/lib/money/money/constructors.rb index a5cd17053b..1ab8d3c946 100644 --- a/lib/money/money/constructors.rb +++ b/lib/money/money/constructors.rb @@ -1,6 +1,5 @@ class Money module Constructors - # Create a new money object with value 0. # # @param [Currency, String, Symbol] currency The currency to use. @@ -14,7 +13,6 @@ def empty(currency = default_currency) end alias_method :zero, :empty - # Creates a new Money object of the given value, using the Canadian # dollar currency. # @@ -31,7 +29,6 @@ def ca_dollar(cents) end alias_method :cad, :ca_dollar - # Creates a new Money object of the given value, using the American dollar # currency. # @@ -48,7 +45,6 @@ def us_dollar(cents) end alias_method :usd, :us_dollar - # Creates a new Money object of the given value, using the Euro currency. # # @param [Integer] cents The cents value. @@ -64,7 +60,6 @@ def euro(cents) end alias_method :eur, :euro - # Creates a new Money object of the given value, in British pounds. # # @param [Integer] pence The pence value. @@ -79,6 +74,5 @@ def pound_sterling(pence) new(pence, "GBP") end alias_method :gbp, :pound_sterling - end end diff --git a/lib/money/money/formatter.rb b/lib/money/money/formatter.rb index 1b8a7b0194..b0071c56ab 100644 --- a/lib/money/money/formatter.rb +++ b/lib/money/money/formatter.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 + require 'money/money/formatting_rules' class Money @@ -229,6 +230,7 @@ def initialize(money, *rules) def to_s return free_text if show_free_text? + result = format_number formatted = append_sign(result) append_currency_symbol(formatted) diff --git a/lib/money/rates_store/memory.rb b/lib/money/rates_store/memory.rb index 9b028d4012..7dbdbef505 100644 --- a/lib/money/rates_store/memory.rb +++ b/lib/money/rates_store/memory.rb @@ -1,6 +1,5 @@ class Money module RatesStore - # Class for thread-safe storage of exchange rate pairs. # Used by instances of +Money::Bank::VariableExchange+. # @@ -91,7 +90,7 @@ def each_rate(&block) enum = Enumerator.new do |yielder| index.each do |key, rate| iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR) - yielder.yield iso_from, iso_to, rate + yielder.yield iso_from, iso_to, rate end end diff --git a/money.gemspec b/money.gemspec index bbc8b73d75..18eea40532 100644 --- a/money.gemspec +++ b/money.gemspec @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "money/version" diff --git a/spec/bank/base_spec.rb b/spec/bank/base_spec.rb index e5976eff7c..15e7507981 100644 --- a/spec/bank/base_spec.rb +++ b/spec/bank/base_spec.rb @@ -1,5 +1,4 @@ describe Money::Bank::Base do - describe ".instance" do it "is local to one class" do subclass = Class.new(described_class) diff --git a/spec/bank/variable_exchange_spec.rb b/spec/bank/variable_exchange_spec.rb index 52d1ab6acb..4b138b2fb7 100644 --- a/spec/bank/variable_exchange_spec.rb +++ b/spec/bank/variable_exchange_spec.rb @@ -2,7 +2,6 @@ require 'yaml' describe Money::Bank::VariableExchange do - describe "#initialize" do context "without &block" do let(:bank) { @@ -52,12 +51,12 @@ expect { bank.exchange_with(Money.new(100, 'USD'), 'JPY') }.to raise_exception(Money::Bank::UnknownRate) end - #it "rounds the exchanged result down" do + # it "rounds the exchanged result down" do # bank.add_rate("USD", "EUR", 0.788332676) # bank.add_rate("EUR", "YEN", 122.631477) # expect(bank.exchange_with(Money.new(10_00, "USD"), "EUR")).to eq Money.new(788, "EUR") # expect(bank.exchange_with(Money.new(500_00, "EUR"), "YEN")).to eq Money.new(6131573, "YEN") - #end + # end it "accepts a custom truncation method" do proc = Proc.new { |n| n.ceil } @@ -183,7 +182,7 @@ context "with unknown format" do it "raises Money::Bank::UnknownRateFormat" do - expect { subject.export_rates(:foo)}.to raise_error Money::Bank::UnknownRateFormat + expect { subject.export_rates(:foo) }.to raise_error Money::Bank::UnknownRateFormat end end @@ -201,7 +200,6 @@ expect(subject.store).to receive(:transaction) subject.export_rates(:yaml, nil, foo: 1) end - end describe "#import_rates" do @@ -216,7 +214,7 @@ context "with format == :ruby" do it "loads the rates provided" do - s = Marshal.dump({"USD_TO_EUR"=>1.25,"USD_TO_JPY"=>2.55}) + s = Marshal.dump({ "USD_TO_EUR" => 1.25, "USD_TO_JPY" => 2.55 }) subject.import_rates(:ruby, s) expect(subject.get_rate('USD', 'EUR')).to eq 1.25 expect(subject.get_rate('USD', 'JPY')).to eq 2.55 @@ -234,7 +232,7 @@ context "with unknown format" do it "raises Money::Bank::UnknownRateFormat" do - expect { subject.import_rates(:foo, "")}.to raise_error Money::Bank::UnknownRateFormat + expect { subject.import_rates(:foo, "") }.to raise_error Money::Bank::UnknownRateFormat end end @@ -243,12 +241,11 @@ s = "--- \nUSD_TO_EUR: 1.25\nUSD_TO_JPY: 2.55\n" subject.import_rates(:yaml, s, foo: 1) end - end describe "#marshal_dump" do it "does not raise an error" do - expect { Marshal.dump(subject) }.to_not raise_error + expect { Marshal.dump(subject) }.to_not raise_error end it "works with Marshal.load" do diff --git a/spec/currency/heuristics_spec.rb b/spec/currency/heuristics_spec.rb index 543b32a38e..b9af943512 100644 --- a/spec/currency/heuristics_spec.rb +++ b/spec/currency/heuristics_spec.rb @@ -5,7 +5,7 @@ let(:it) { Money::Currency } it "it raises deprecation error" do - expect{ it.analyze('123') }.to raise_error(StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile') + expect { it.analyze('123') }.to raise_error(StandardError, 'Heuristics deprecated, add `gem "money-heuristics"` to Gemfile') end end end diff --git a/spec/currency_spec.rb b/spec/currency_spec.rb index 1bfa757fea..934036802c 100644 --- a/spec/currency_spec.rb +++ b/spec/currency_spec.rb @@ -3,7 +3,7 @@ describe Money::Currency do FOO = '{ "priority": 1, "iso_code": "FOO", "iso_numeric": "840", "name": "United States Dollar", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 1000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }' - def register_foo(opts={}) + def register_foo(opts = {}) foo_attrs = JSON.parse(FOO, symbolize_names: true) # Pass an array of attribute names to 'skip' to remove them from the 'FOO' # json before registering foo as a currency. @@ -88,13 +88,12 @@ def to_s it "raises a MissingAttributeError if any currency has no priority" do register_foo(skip: :priority) - expect{described_class.all}.to \ + expect { described_class.all }.to \ raise_error(described_class::MissingAttributeError, /foo.*priority/) unregister_foo end end - describe ".register" do after { described_class.unregister(iso_code: "XXX") if described_class.find("XXX") } @@ -118,7 +117,6 @@ def to_s end end - describe ".inherit" do after do described_class.unregister(iso_code: "XXX") if described_class.find("XXX") @@ -133,9 +131,8 @@ def to_s subunit_to_unit: 100 ) described_class.inherit("XXX", - iso_code: "YYY", - symbol: "@" - ) + iso_code: "YYY", + symbol: "@") new_currency = described_class.find("YYY") expect(new_currency).not_to be_nil expect(new_currency.name).to eq "Golden Doubloon" @@ -144,7 +141,6 @@ def to_s end end - describe ".unregister" do it "unregisters a currency" do described_class.register(iso_code: "XXX") @@ -171,7 +167,6 @@ def to_s end end - describe ".each" do it "yields each currency to the block" do expect(described_class).to respond_to(:each) @@ -187,7 +182,6 @@ def to_s end end - it "implements Enumerable" do expect(described_class).to respond_to(:all?) expect(described_class).to respond_to(:each_with_index) @@ -196,7 +190,6 @@ def to_s expect(described_class).to respond_to(:reject) end - describe "#initialize" do before { described_class._instances.clear } @@ -239,7 +232,7 @@ def to_s it 'is thread safe' do ids = [] - 2.times.map{ Thread.new{ ids << described_class.new("USD").object_id }}.each(&:join) + 2.times.map { Thread.new { ids << described_class.new("USD").object_id } }.each(&:join) expect(ids.uniq.length).to eq(1) end end @@ -364,7 +357,7 @@ def to_s it "doesn't create new symbols indefinitely" do expect { described_class.new("bogus") }.to raise_exception(described_class::UnknownCurrency) - expect(Symbol.all_symbols.map{|s| s.to_s}).not_to include("bogus") + expect(Symbol.all_symbols.map { |s| s.to_s }).not_to include("bogus") end end diff --git a/spec/locale_backend/i18n_spec.rb b/spec/locale_backend/i18n_spec.rb index 5fe7b63607..9154d59270 100644 --- a/spec/locale_backend/i18n_spec.rb +++ b/spec/locale_backend/i18n_spec.rb @@ -21,8 +21,8 @@ before do I18n.locale = :de I18n.backend.store_translations(:de, number: { - currency: { format: { delimiter: '.', separator: ',', unit: '$' } } - }) + currency: { format: { delimiter: '.', separator: ',', unit: '$' } } + }) end it 'returns thousands_separator based on the current locale' do diff --git a/spec/money/allocation_spec.rb b/spec/money/allocation_spec.rb index f06f1b95b5..31dec6d4c3 100644 --- a/spec/money/allocation_spec.rb +++ b/spec/money/allocation_spec.rb @@ -49,11 +49,9 @@ # Rounding due to inconsistent BigDecimal size in ruby compared to jruby. In reality the # first 2 elements will look like the last one with a '5' at the end, compensating for a # missing fraction - expect(parts.map { |x| x.round(10) }).to eq([ - BigDecimal('33.3333333333'), - BigDecimal('33.3333333333'), - BigDecimal('33.3333333333') - ]) + expect(parts.map { |x| x.round(10) }).to eq([BigDecimal('33.3333333333'), + BigDecimal('33.3333333333'), + BigDecimal('33.3333333333')]) expect(parts.inject(0, :+)).to eq(amount) end end @@ -123,11 +121,9 @@ # Rounding due to inconsistent BigDecimal size in ruby compared to jruby. In reality the # first 2 elements will look like the last one with a '5' at the end, compensating for a # missing fraction - expect(parts.map { |x| x.round(10) }).to eq([ - BigDecimal('33.3333333333'), - BigDecimal('33.3333333333'), - BigDecimal('33.3333333333') - ]) + expect(parts.map { |x| x.round(10) }).to eq([BigDecimal('33.3333333333'), + BigDecimal('33.3333333333'), + BigDecimal('33.3333333333')]) expect(parts.inject(0, :+)).to eq(amount) end end diff --git a/spec/money/arithmetic_spec.rb b/spec/money/arithmetic_spec.rb index 95d1649a5c..a96ddeadf2 100644 --- a/spec/money/arithmetic_spec.rb +++ b/spec/money/arithmetic_spec.rb @@ -263,10 +263,10 @@ describe "#*" do it "multiplies Money by Integer and returns Money" do ts = [ - {a: Money.new( 10, :USD), b: 4, c: Money.new( 40, :USD)}, - {a: Money.new( 10, :USD), b: -4, c: Money.new(-40, :USD)}, - {a: Money.new(-10, :USD), b: 4, c: Money.new(-40, :USD)}, - {a: Money.new(-10, :USD), b: -4, c: Money.new( 40, :USD)}, + { a: Money.new(10, :USD), b: 4, c: Money.new(40, :USD) }, + { a: Money.new(10, :USD), b: -4, c: Money.new(-40, :USD) }, + { a: Money.new(-10, :USD), b: 4, c: Money.new(-40, :USD) }, + { a: Money.new(-10, :USD), b: -4, c: Money.new(40, :USD) }, ] ts.each do |t| expect(t[:a] * t[:b]).to eq t[:c] @@ -296,10 +296,10 @@ describe "#/" do it "divides Money by Integer and returns Money" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 3, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new( 3, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(3, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(3, :USD) }, ] ts.each do |t| expect(t[:a] / t[:b]).to eq t[:c] @@ -351,10 +351,10 @@ it "divides Money by Money (same currency) and returns Float" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :USD), c: 3.25}, - {a: Money.new( 13, :USD), b: Money.new(-4, :USD), c: -3.25}, - {a: Money.new(-13, :USD), b: Money.new( 4, :USD), c: -3.25}, - {a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25}, + { a: Money.new(13, :USD), b: Money.new(4, :USD), c: 3.25 }, + { a: Money.new(13, :USD), b: Money.new(-4, :USD), c: -3.25 }, + { a: Money.new(-13, :USD), b: Money.new(4, :USD), c: -3.25 }, + { a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25 }, ] ts.each do |t| expect(t[:a] / t[:b]).to eq t[:c] @@ -363,10 +363,10 @@ it "divides Money by Money (different currency) and returns Float" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :EUR), c: 1.625}, - {a: Money.new( 13, :USD), b: Money.new(-4, :EUR), c: -1.625}, - {a: Money.new(-13, :USD), b: Money.new( 4, :EUR), c: -1.625}, - {a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625}, + { a: Money.new(13, :USD), b: Money.new(4, :EUR), c: 1.625 }, + { a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: -1.625 }, + { a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: -1.625 }, + { a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625 }, ] ts.each do |t| expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD)) @@ -377,10 +377,10 @@ context "with infinite_precision", :infinite_precision do it "uses BigDecimal division" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 3.25, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3.25, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new(-3.25, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new( 3.25, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(3.25, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3.25, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(-3.25, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(3.25, :USD) }, ] ts.each do |t| expect(t[:a] / t[:b]).to eq t[:c] @@ -394,10 +394,10 @@ describe "#div" do it "divides Money by Integer and returns Money" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 3, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new( 3, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(3, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(3, :USD) }, ] ts.each do |t| expect(t[:a].div(t[:b])).to eq t[:c] @@ -406,10 +406,10 @@ it "divides Money by Money (same currency) and returns Float" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :USD), c: 3.25}, - {a: Money.new( 13, :USD), b: Money.new(-4, :USD), c: -3.25}, - {a: Money.new(-13, :USD), b: Money.new( 4, :USD), c: -3.25}, - {a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25}, + { a: Money.new(13, :USD), b: Money.new(4, :USD), c: 3.25 }, + { a: Money.new(13, :USD), b: Money.new(-4, :USD), c: -3.25 }, + { a: Money.new(-13, :USD), b: Money.new(4, :USD), c: -3.25 }, + { a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: 3.25 }, ] ts.each do |t| expect(t[:a].div(t[:b])).to eq t[:c] @@ -418,10 +418,10 @@ it "divides Money by Money (different currency) and returns Float" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :EUR), c: 1.625}, - {a: Money.new( 13, :USD), b: Money.new(-4, :EUR), c: -1.625}, - {a: Money.new(-13, :USD), b: Money.new( 4, :EUR), c: -1.625}, - {a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625}, + { a: Money.new(13, :USD), b: Money.new(4, :EUR), c: 1.625 }, + { a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: -1.625 }, + { a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: -1.625 }, + { a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: 1.625 }, ] ts.each do |t| expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD)) @@ -432,10 +432,10 @@ context "with infinite_precision", :infinite_precision do it "uses BigDecimal division" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 3.25, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3.25, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new(-3.25, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new( 3.25, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(3.25, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3.25, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(-3.25, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(3.25, :USD) }, ] ts.each do |t| expect(t[:a].div(t[:b])).to eq t[:c] @@ -447,10 +447,10 @@ describe "#divmod" do it "calculates division and modulo with Integer" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: [Money.new( 3, :USD), Money.new( 1, :USD)]}, - {a: Money.new( 13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)]}, - {a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new( 3, :USD)]}, - {a: Money.new(-13, :USD), b: -4, c: [Money.new( 3, :USD), Money.new(-1, :USD)]}, + { a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] }, + { a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] }, + { a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] }, + { a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] }, ] ts.each do |t| expect(t[:a].divmod(t[:b])).to eq t[:c] @@ -459,10 +459,10 @@ it "calculates division and modulo with Money (same currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :USD), c: [ 3, Money.new( 1, :USD)]}, - {a: Money.new( 13, :USD), b: Money.new(-4, :USD), c: [-4, Money.new(-3, :USD)]}, - {a: Money.new(-13, :USD), b: Money.new( 4, :USD), c: [-4, Money.new( 3, :USD)]}, - {a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: [ 3, Money.new(-1, :USD)]}, + { a: Money.new(13, :USD), b: Money.new(4, :USD), c: [3, Money.new(1, :USD)] }, + { a: Money.new(13, :USD), b: Money.new(-4, :USD), c: [-4, Money.new(-3, :USD)] }, + { a: Money.new(-13, :USD), b: Money.new(4, :USD), c: [-4, Money.new(3, :USD)] }, + { a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: [3, Money.new(-1, :USD)] }, ] ts.each do |t| expect(t[:a].divmod(t[:b])).to eq t[:c] @@ -471,10 +471,10 @@ it "calculates division and modulo with Money (different currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :EUR), c: [ 1, Money.new( 5, :USD)]}, - {a: Money.new( 13, :USD), b: Money.new(-4, :EUR), c: [-2, Money.new(-3, :USD)]}, - {a: Money.new(-13, :USD), b: Money.new( 4, :EUR), c: [-2, Money.new( 3, :USD)]}, - {a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: [ 1, Money.new(-5, :USD)]}, + { a: Money.new(13, :USD), b: Money.new(4, :EUR), c: [1, Money.new(5, :USD)] }, + { a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: [-2, Money.new(-3, :USD)] }, + { a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: [-2, Money.new(3, :USD)] }, + { a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: [1, Money.new(-5, :USD)] }, ] ts.each do |t| expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD)) @@ -485,10 +485,10 @@ context "with infinite_precision", :infinite_precision do it "uses BigDecimal division" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: [Money.new( 3, :USD), Money.new( 1, :USD)]}, - {a: Money.new( 13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)]}, - {a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new( 3, :USD)]}, - {a: Money.new(-13, :USD), b: -4, c: [Money.new( 3, :USD), Money.new(-1, :USD)]}, + { a: Money.new(13, :USD), b: 4, c: [Money.new(3, :USD), Money.new(1, :USD)] }, + { a: Money.new(13, :USD), b: -4, c: [Money.new(-4, :USD), Money.new(-3, :USD)] }, + { a: Money.new(-13, :USD), b: 4, c: [Money.new(-4, :USD), Money.new(3, :USD)] }, + { a: Money.new(-13, :USD), b: -4, c: [Money.new(3, :USD), Money.new(-1, :USD)] }, ] ts.each do |t| expect(t[:a].divmod(t[:b])).to eq t[:c] @@ -513,10 +513,10 @@ describe "#modulo" do it "calculates modulo with Integer" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 1, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) }, ] ts.each do |t| expect(t[:a].modulo(t[:b])).to eq t[:c] @@ -525,10 +525,10 @@ it "calculates modulo with Money (same currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :USD), c: Money.new( 1, :USD)}, - {a: Money.new( 13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new( 4, :USD), c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD)}, + { a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) }, + { a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) }, ] ts.each do |t| expect(t[:a].modulo(t[:b])).to eq t[:c] @@ -537,10 +537,10 @@ it "calculates modulo with Money (different currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :EUR), c: Money.new( 5, :USD)}, - {a: Money.new( 13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new( 4, :EUR), c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD)}, + { a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) }, + { a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) }, ] ts.each do |t| expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD)) @@ -552,10 +552,10 @@ describe "#%" do it "calculates modulo with Integer" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 1, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) }, ] ts.each do |t| expect(t[:a] % t[:b]).to eq t[:c] @@ -564,10 +564,10 @@ it "calculates modulo with Money (same currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :USD), c: Money.new( 1, :USD)}, - {a: Money.new( 13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new( 4, :USD), c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD)}, + { a: Money.new(13, :USD), b: Money.new(4, :USD), c: Money.new(1, :USD) }, + { a: Money.new(13, :USD), b: Money.new(-4, :USD), c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(4, :USD), c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(-4, :USD), c: Money.new(-1, :USD) }, ] ts.each do |t| expect(t[:a] % t[:b]).to eq t[:c] @@ -576,10 +576,10 @@ it "calculates modulo with Money (different currency)" do ts = [ - {a: Money.new( 13, :USD), b: Money.new( 4, :EUR), c: Money.new( 5, :USD)}, - {a: Money.new( 13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new( 4, :EUR), c: Money.new( 3, :USD)}, - {a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD)}, + { a: Money.new(13, :USD), b: Money.new(4, :EUR), c: Money.new(5, :USD) }, + { a: Money.new(13, :USD), b: Money.new(-4, :EUR), c: Money.new(-3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(4, :EUR), c: Money.new(3, :USD) }, + { a: Money.new(-13, :USD), b: Money.new(-4, :EUR), c: Money.new(-5, :USD) }, ] ts.each do |t| expect(t[:b]).to receive(:exchange_to).once.with(t[:a].currency).and_return(Money.new(t[:b].cents * 2, :USD)) @@ -591,10 +591,10 @@ describe "#remainder" do it "calculates remainder with Integer" do ts = [ - {a: Money.new( 13, :USD), b: 4, c: Money.new( 1, :USD)}, - {a: Money.new( 13, :USD), b: -4, c: Money.new( 1, :USD)}, - {a: Money.new(-13, :USD), b: 4, c: Money.new(-1, :USD)}, - {a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD)}, + { a: Money.new(13, :USD), b: 4, c: Money.new(1, :USD) }, + { a: Money.new(13, :USD), b: -4, c: Money.new(1, :USD) }, + { a: Money.new(-13, :USD), b: 4, c: Money.new(-1, :USD) }, + { a: Money.new(-13, :USD), b: -4, c: Money.new(-1, :USD) }, ] ts.each do |t| expect(t[:a].remainder(t[:b])).to eq t[:c] @@ -607,7 +607,7 @@ describe "#abs" do it "returns the absolute value as a new Money object" do n = Money.new(-1, :USD) - expect(n.abs).to eq Money.new( 1, :USD) + expect(n.abs).to eq Money.new(1, :USD) expect(n).to eq Money.new(-1, :USD) end @@ -731,7 +731,7 @@ }.to raise_exception(TypeError) expect { - Rational(2,3) / Money.new(2, 'USD') + Rational(2, 3) / Money.new(2, 'USD') }.to raise_exception(TypeError) expect { diff --git a/spec/money/constructors_spec.rb b/spec/money/constructors_spec.rb index facead47db..be9ceeca33 100644 --- a/spec/money/constructors_spec.rb +++ b/spec/money/constructors_spec.rb @@ -1,7 +1,6 @@ # encoding: utf-8 describe Money::Constructors do - describe "::empty" do it "creates a new Money object of 0 cents" do expect(Money.empty).to eq Money.new(0) @@ -13,7 +12,6 @@ end end - describe "::zero" do subject { Money.zero } it { is_expected.to eq Money.empty } @@ -24,7 +22,6 @@ end end - describe "::ca_dollar" do it "creates a new Money object of the given value in CAD" do expect(Money.ca_dollar(50)).to eq Money.new(50, "CAD") @@ -40,7 +37,6 @@ end end - describe "::us_dollar" do it "creates a new Money object of the given value in USD" do expect(Money.us_dollar(50)).to eq Money.new(50, "USD") @@ -56,7 +52,6 @@ end end - describe "::euro" do it "creates a new Money object of the given value in EUR" do expect(Money.euro(50)).to eq Money.new(50, "EUR") @@ -72,7 +67,6 @@ end end - describe "::pound_sterling" do it "creates a new Money object of the given value in GBP" do expect(Money.pound_sterling(50)).to eq Money.new(50, "GBP") @@ -87,5 +81,4 @@ expect(special_money_class.pound_sterling(0)).to be_a special_money_class end end - end diff --git a/spec/money/formatting_spec.rb b/spec/money/formatting_spec.rb index 10843afd0d..419b2c8515 100644 --- a/spec/money/formatting_spec.rb +++ b/spec/money/formatting_spec.rb @@ -1,7 +1,6 @@ # encoding: utf-8 describe Money, "formatting" do - BAR = '{ "priority": 1, "iso_code": "BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "smallest_denomination": 1 }' INDIAN_BAR = '{ "priority": 1, "iso_code": "INDIAN_BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": ",", "south_asian_number_formatting": true, "smallest_denomination": 1}' EU4 = '{ "priority": 1, "iso_code": "EU4", "iso_numeric": "841", "name": "Euro with 4 decimal places", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "€", "decimal_mark": ",", "thousands_separator": ".", "smallest_denomination": 1 }' @@ -36,8 +35,8 @@ reset_i18n I18n.locale = :de I18n.backend.store_translations( - :de, - number: { currency: { format: { delimiter: ".", separator: "," } } } + :de, + number: { currency: { format: { delimiter: ".", separator: "," } } } ) Money.use_i18n = false end @@ -70,8 +69,8 @@ reset_i18n I18n.locale = :de I18n.backend.store_translations( - :de, - number: { format: { delimiter: ".", separator: "," } } + :de, + number: { format: { delimiter: ".", separator: "," } } ) end @@ -91,8 +90,8 @@ reset_i18n I18n.locale = :de I18n.backend.store_translations( - :de, - number: { currency: { format: { delimiter: ".", separator: "," } } } + :de, + number: { currency: { format: { delimiter: ".", separator: "," } } } ) end @@ -112,8 +111,8 @@ reset_i18n I18n.locale = :de I18n.backend.store_translations( - :de, - number: { currency: { symbol: { CAD: "CAD$" } } } + :de, + number: { currency: { symbol: { CAD: "CAD$" } } } ) end @@ -149,7 +148,7 @@ expect(money.format(symbol: false)).to eq "1,000" end - after { I18n.locale = @_locale } + after { I18n.locale = @_locale } end it "returns the monetary value as a string" do @@ -404,7 +403,7 @@ money = Money.new(100, "EUR") expect(money.format(symbol: false, - sign_positive: true)).to eq "+1,00" + sign_positive: true)).to eq "+1,00" end end @@ -420,7 +419,7 @@ describe ":separator option" do specify "(separator: a separator string) works as documented" do - expect(Money.us_dollar(100).format(separator: ",")).to eq "$1,00" + expect(Money.us_dollar(100).format(separator: ",")).to eq "$1,00" end end @@ -481,7 +480,7 @@ expect(Money.new(300_000, 'USD').format(thousands_separator: ".", decimal_mark: ',', drop_trailing_zeros: true)).to eq "$3.000" end - after { Money.use_i18n = true} + after { Money.use_i18n = true } end end @@ -538,7 +537,7 @@ end it "raises an ArgumentError when passed an invalid option" do - expect{Money.euro(0).format(symbol_position: :befor)}.to raise_error(ArgumentError) + expect { Money.euro(0).format(symbol_position: :befor) }.to raise_error(ArgumentError) end end @@ -583,27 +582,27 @@ describe ":sign_positive option" do specify "(sign_positive: true, sign_before_symbol: true) works as documented" do - expect(Money.us_dollar( 0).format(sign_positive: true, sign_before_symbol: true)).to eq "$0.00" - expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: true)).to eq "+$1,000.00" + expect(Money.us_dollar(0).format(sign_positive: true, sign_before_symbol: true)).to eq "$0.00" + expect(Money.us_dollar(100000).format(sign_positive: true, sign_before_symbol: true)).to eq "+$1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: true)).to eq "-$1,000.00" end specify "(sign_positive: true, sign_before_symbol: false) works as documented" do - expect(Money.us_dollar( 0).format(sign_positive: true, sign_before_symbol: false)).to eq "$0.00" - expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: false)).to eq "$+1,000.00" - expect(Money.us_dollar( 100000).format(sign_positive: true, sign_before_symbol: nil)).to eq "$+1,000.00" + expect(Money.us_dollar(0).format(sign_positive: true, sign_before_symbol: false)).to eq "$0.00" + expect(Money.us_dollar(100000).format(sign_positive: true, sign_before_symbol: false)).to eq "$+1,000.00" + expect(Money.us_dollar(100000).format(sign_positive: true, sign_before_symbol: nil)).to eq "$+1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: false)).to eq "$-1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: true, sign_before_symbol: nil)).to eq "$-1,000.00" end specify "(sign_positive: false, sign_before_symbol: true) works as documented" do - expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: true)).to eq "$1,000.00" + expect(Money.us_dollar(100000).format(sign_positive: false, sign_before_symbol: true)).to eq "$1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: true)).to eq "-$1,000.00" end specify "(sign_positive: false, sign_before_symbol: false) works as documented" do - expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: false)).to eq "$1,000.00" - expect(Money.us_dollar( 100000).format(sign_positive: false, sign_before_symbol: nil)).to eq "$1,000.00" + expect(Money.us_dollar(100000).format(sign_positive: false, sign_before_symbol: false)).to eq "$1,000.00" + expect(Money.us_dollar(100000).format(sign_positive: false, sign_before_symbol: nil)).to eq "$1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: false)).to eq "$-1,000.00" expect(Money.us_dollar(-100000).format(sign_positive: false, sign_before_symbol: nil)).to eq "$-1,000.00" end @@ -656,8 +655,8 @@ reset_i18n I18n.locale = :de I18n.backend.store_translations( - :de, - number: { currency: { format: { delimiter: ".", separator: "," } } } + :de, + number: { currency: { format: { delimiter: ".", separator: "," } } } ) end @@ -772,11 +771,9 @@ expect(Money.new(88833310034, "BAR").format).to eq "$8,883,331.0034" expect(Money.new(88833310034, "EU4").format).to eq "€8.883.331,0034" end - end context "currencies with ambiguous signs" do - it "returns ambiguous signs when disambiguate is not set" do expect(Money.new(1999_98, "USD").format).to eq("$1,999.98") expect(Money.new(1999_98, "CAD").format).to eq("$1,999.98") diff --git a/spec/money_spec.rb b/spec/money_spec.rb index f0291e3e22..73b6843120 100644 --- a/spec/money_spec.rb +++ b/spec/money_spec.rb @@ -248,27 +248,27 @@ def expectation.fractional end context "loading a serialized Money via YAML" do - - let(:serialized) { < 0.9, 'CADUSD' => 1.1}) + result = subject.each_rate.each_with_object({}) { |(from, to, rate), m| m[[from, to].join] = rate } + expect(result).to match({ 'USDCAD' => 0.9, 'CADUSD' => 1.1 }) end end @@ -45,11 +45,11 @@ context 'mutex' do it 'uses mutex' do expect(subject.instance_variable_get('@mutex')).to receive(:synchronize) - subject.transaction{ 1 + 1 } + subject.transaction { 1 + 1 } end it 'wraps block in mutex transaction only once' do - expect{ + expect { subject.transaction do subject.add_rate('USD', 'CAD', 1) end @@ -62,7 +62,7 @@ it 'does not use mutex' do expect(subject.instance_variable_get('@mutex')).not_to receive(:synchronize) - subject.transaction{ 1 + 1 } + subject.transaction { 1 + 1 } end end end