Sha256: 080b9fa25512595dacfbff51097a7036fa0b9ef5b0acdda749b29d119df83928

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

describe IEX::Resources::Resource do
  context 'float number to percent (Positive)' do
    subject do
      IEX::Resources::Resource.float_to_percentage(0.09123)
    end
    it 'converts to percentage' do
      expect(subject).to eq '+9.12%'
    end
  end

  context 'float number to percent (Negative)' do
    subject do
      IEX::Resources::Resource.float_to_percentage(-0.09123)
    end
    it 'converts to percentage' do
      expect(subject).to eq '-9.12%'
    end
  end

  context 'float number to percent (nil)' do
    subject do
      IEX::Resources::Resource.float_to_percentage(nil)
    end
    it 'nil argument does not convert' do
      expect(subject).to eq nil
    end
  end

  context 'float number to percent (0)' do
    subject do
      IEX::Resources::Resource.float_to_percentage(0)
    end
    it 'Zero converts to +0.00%' do
      expect(subject).to eq '+0.00%'
    end
  end

  context 'percent to string (Positive)' do
    subject do
      IEX::Resources::Resource.percentage_to_string(3.3793)
    end
    it 'converts to percentage' do
      expect(subject).to eq '+3.38%'
    end
  end

  context 'percent to string (Negative)' do
    subject do
      IEX::Resources::Resource.percentage_to_string(-3.3793)
    end
    it 'converts to percentage' do
      expect(subject).to eq '-3.38%'
    end
  end

  context 'percent to string (nil)' do
    subject do
      IEX::Resources::Resource.percentage_to_string(nil)
    end
    it 'nil argument does not convert' do
      expect(subject).to eq nil
    end
  end

  context 'float number to percent (0)' do
    subject do
      IEX::Resources::Resource.percentage_to_string(0)
    end
    it 'Zero converts to +0.00%' do
      expect(subject).to eq '+0.00%'
    end
  end

  context 'Unformatted money amount to dollar' do
    subject do
      IEX::Resources::Resource.to_dollar(amount: 123_391)
    end
    it 'converts to dollar' do
      expect(subject).to eq '$123,391'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
iex-ruby-client-2.1.0 spec/iex/resources/resource_spec.rb
iex-ruby-client-2.0.0 spec/iex/resources/resource_spec.rb
iex-ruby-client-1.6.0 spec/iex/resources/resource_spec.rb
iex-ruby-client-1.5.0 spec/iex/resources/resource_spec.rb
iex-ruby-client-1.4.1 spec/iex/resources/resource_spec.rb
iex-ruby-client-1.4.0 spec/iex/resources/resource_spec.rb