spec/utils_spec.rb in litexbrl-0.0.3 vs spec/utils_spec.rb in litexbrl-0.1.0
- old
+ new
@@ -1,73 +1,109 @@
require 'spec_helper'
module LiteXBRL
describe Utils do
- extend Utils
+ include Utils
- describe '.to_mill' do
+ describe '#to_securities_code' do
+ let(:code) { to_securities_code elm_code }
+
+ context '5桁の数字' do
+ let(:elm_code) { double("elm_code", content: "11110") }
+
+ it { expect(code).to eq "1111" }
+ end
+
+ context '全角' do
+ let(:elm_code) { double("elm_code", content: "1111") }
+
+ it { expect(code).to eq "1111" }
+ end
+
+ context '特殊文字' do
+ let(:elm_code) { double("elm_code", content: " 1111") }
+
+ it { expect(code).to eq "1111" }
+ end
+ end
+
+ describe '#to_mill' do
context 'val == "1000000"' do
let(:val) { "1000000" }
- it { expect(self.class.to_mill val).to eq(1) }
+ it { expect(to_mill val).to eq(1) }
end
end
- describe '.to_i' do
+ describe '#to_i' do
context 'val == "54,074"' do
let(:val) { "54,074" }
- it { expect(self.class.to_i val).to eq(54074) }
+ it { expect(to_i val).to eq(54074) }
end
end
- describe '.to_f' do
+ describe '#to_f' do
context 'val == "0.02"' do
let(:val) { "0.02" }
- it { expect(self.class.to_f val).to eq(0.02) }
+ it { expect(to_f val).to eq(0.02) }
end
context 'val == "1,000.1"' do
let(:val) { "1,000.1" }
- it { expect(self.class.to_f val).to eq 1000.1 }
+ it { expect(to_f val).to eq 1000.1 }
end
end
- describe '.perc_to_f' do
+ describe '#perc_to_f' do
context 'val == "2.2"' do
let(:val) { "2.2" }
- it { expect(self.class.percent_to_f val).to eq(0.022) }
+ it { expect(percent_to_f val).to eq(0.022) }
end
context 'val == "1,982.4"' do
let(:val) { "1,982.4" }
- it { expect(self.class.percent_to_f val).to eq 19.824 }
+ it { expect(percent_to_f val).to eq 19.824 }
end
end
describe '#present?' do
context 'val == nil' do
let(:val) { nil }
- it { expect(self.class.present? val).to be_false }
+ it { expect(present? val).to eq false }
end
context 'val == 空文字' do
let(:val) { "" }
- it { expect(self.class.present? val).to be_false }
+ it { expect(present? val).to eq false }
end
context 'val == 2.2' do
let(:val) { "2.2" }
- it { expect(self.class.present? val).to be_true }
+ it { expect(present? val).to eq true }
end
end
describe '#to_securities_code' do
context '全角数字' do
let(:code) { "96850" }
it "半角数字に直す" do
- code.stub(:content) { code }
- expect(self.class.to_securities_code code).to eq "9685"
+ allow(code).to receive(:content) { code }
+ expect(to_securities_code code).to eq "9685"
end
+ end
+ end
+
+ describe '#to_consolidation' do
+ context '連結' do
+ let(:consolidation) { Utils::CONSOLIDATED }
+
+ it { expect(to_consolidation consolidation).to eq 1 }
+ end
+
+ context '非連結' do
+ let(:consolidation) { Utils::NON_CONSOLIDATED }
+
+ it { expect(to_consolidation consolidation).to eq 0 }
end
end
end
end
\ No newline at end of file