forked from solnic/virtus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated String .to_integer, .to_float and .to_decimal specs to test m…
…ore cases
- Loading branch information
Showing
8 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
spec/unit/virtus/typecast/string/class_methods/to_boolean_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe Virtus::Typecast::String, '.to_boolean' do | ||
subject { described_class.to_boolean(string) } | ||
subject { object.to_boolean(string) } | ||
|
||
described_class::TRUE_VALUES.each do |value| | ||
let(:object) { described_class } | ||
|
||
%w[ 1 t true T TRUE ].each do |value| | ||
context "with #{value.inspect}" do | ||
let(:string) { value } | ||
|
||
it { should be(true) } | ||
end | ||
end | ||
|
||
described_class::FALSE_VALUES.each do |value| | ||
%w[ 0 f false F FALSE ].each do |value| | ||
context "with #{value.inspect}" do | ||
let(:string) { value } | ||
|
||
it { should be(false) } | ||
end | ||
end | ||
|
||
context 'with an unknown string' do | ||
let(:string) { 'something' } | ||
it { should == string } | ||
context 'with an invalid boolean string' do | ||
let(:string) { 'non-boolean' } | ||
|
||
it { should equal(string) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 17 additions & 4 deletions
21
spec/unit/virtus/typecast/string/class_methods/to_decimal_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
describe Virtus::Typecast::String, '.to_decimal' do | ||
subject { described_class.to_decimal(string) } | ||
subject { object.to_decimal(string) } | ||
|
||
let(:string) { '1.0' } | ||
let(:decimal) { BigDecimal('1.0') } | ||
let(:object) { described_class } | ||
|
||
it { should == decimal } | ||
{ '1' => BigDecimal('1.0'), '1.0' => BigDecimal('1.0'), '.1' => BigDecimal('0.1') }.each do |value, expected| | ||
context "with #{value.inspect}" do | ||
let(:string) { value } | ||
|
||
it { should be_instance_of(BigDecimal) } | ||
|
||
it { should eql(expected) } | ||
end | ||
end | ||
|
||
context 'with an invalid decimal string' do | ||
let(:string) { 'non-decimal' } | ||
|
||
it { should equal(string) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters