spec/lib/danica/formatted_spec.rb in danica-2.7.4 vs spec/lib/danica/formatted_spec.rb in danica-2.7.5
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'spec_helper'
shared_examples 'a formatted result' do |output|
it do
expect(result).to be_a(described_class)
@@ -12,32 +14,35 @@
shared_examples('a formatted object that responds to basic operations') do |operations_map|
operations_map.each do |operation, (output, reverse_output)|
describe(operation.to_s) do
let(:result) { subject.public_send(operation, 2) }
+
it_behaves_like 'a formatted result', output
context 'when doing it backwards' do
let(:result) { Danica::Wrapper::Number.new(2).public_send(operation, subject) }
+
it_behaves_like 'a formatted result', reverse_output
end
end
end
end
describe Danica::Formatted do
- let(:content) { Danica::Wrapper::Variable.new(latex: :V, gnuplot: :v) }
- let(:format) { :tex }
- let(:options) { {} }
subject do
described_class.new(content, format: format, **options)
end
+ let(:content) { Danica::Wrapper::Variable.new(latex: :V, gnuplot: :v) }
+ let(:format) { :tex }
+ let(:options) { {} }
+
describe '#repack' do
let(:expression) { Danica::Wrapper::Number.new(1.0 / 3) }
it do
- expect(subject.repack(expression)).to be_a(Danica::Formatted)
+ expect(subject.repack(expression)).to be_a(described_class)
end
context 'when there are options' do
let(:options) { { decimals: 3 } }
@@ -61,11 +66,11 @@
expect(subject.to_s).to eq('v')
end
end
context 'when variable has numeric value' do
- let(:content) { Danica::Wrapper::Number.new(1/3.0) }
+ let(:content) { Danica::Wrapper::Number.new(1 / 3.0) }
it 'returns the formatted number' do
expect(subject.to_s).to eq('0.3333333333333333')
end
@@ -78,17 +83,16 @@
end
end
end
describe 'operators' do
- it_behaves_like 'a formatted object that responds to basic operations', {
- :+ => ['V + 2', '2 + V'],
- :- => ['V -2', '2 -V'],
- :* => ['V \cdot 2', '2 \cdot V'],
- :/ => ['\frac{V}{2}', '\frac{2}{V}'],
- :** => ['V^{2}', '2^{V}']
- }
+ it_behaves_like 'a formatted object that responds to basic operations',
+ :+ => ['V + 2', '2 + V'],
+ :- => ['V -2', '2 -V'],
+ :* => ['V \cdot 2', '2 \cdot V'],
+ :/ => ['\frac{V}{2}', '\frac{2}{V}'],
+ :** => ['V^{2}', '2^{V}']
describe '-@' do
it do
expect(-subject).to be_a(described_class)
end
@@ -121,11 +125,11 @@
end
end
describe '#tex' do
it do
- expect(subject.tex).to be_a(Danica::Formatted)
+ expect(subject.tex).to be_a(described_class)
end
context 'when original format is tex' do
it 'returns the tex string' do
expect(subject.tex.to_s).to eq('V')
@@ -136,10 +140,11 @@
end
end
context 'when original format is gnu' do
let(:format) { :gnu }
+
it 'returns the tex string' do
expect(subject.tex.to_s).to eq('V')
end
it 'returns a new format object' do
@@ -148,20 +153,21 @@
end
end
describe '#gnu' do
it do
- expect(subject.gnu).to be_a(Danica::Formatted)
+ expect(subject.gnu).to be_a(described_class)
end
context 'when original format is tex' do
it 'returns the gnu string' do
expect(subject.gnu.to_s).to eq('v')
end
end
context 'when original format is gnu' do
let(:format) { :gnu }
+
it 'returns the gnu string' do
expect(subject.gnu.to_s).to eq('v')
end
end
end