-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inheritance (sub class from Unit) no longer works (#340)
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -24,3 +24,5 @@ Style/FormatString: | |
Enabled: false | ||
Style/DateTime: | ||
Enabled: false | ||
Metrics/ClassLength: | ||
Enabled: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
RSpec.describe 'Subclass' do | ||
subject(:subclass) { Class.new(RubyUnits::Unit) } | ||
|
||
it 'can be subclassed' do | ||
expect(subclass).to be < RubyUnits::Unit | ||
end | ||
|
||
it 'can be instantiated' do | ||
expect(subclass.new('1 m')).to be_a(RubyUnits::Unit) | ||
end | ||
|
||
it 'compares to the parent class' do | ||
expect(subclass.new('1 m')).to eq(RubyUnits::Unit.new('1 m')) | ||
end | ||
|
||
it 'can be added to another subclass instance' do | ||
expect(subclass.new('1 m') + subclass.new('1 m')).to eq(RubyUnits::Unit.new('2 m')) | ||
end | ||
|
||
it 'returns a subclass object when added to another instance of a subclass' do | ||
expect(subclass.new('1 m') + subclass.new('1 m')).to be_an_instance_of(subclass) | ||
end | ||
|
||
it 'returns an instance of the parent class when added to another instance of a subclass' do | ||
expect(RubyUnits::Unit.new('1 m') + subclass.new('1 m')).to be_an_instance_of(RubyUnits::Unit) | ||
end | ||
|
||
it 'returns an instance of the subclass when added to an instance of the parent class' do | ||
expect(subclass.new('1 m') + RubyUnits::Unit.new('1 m')).to be_an_instance_of(subclass) | ||
end | ||
end |