spec/fear/some_spec.rb in fear-0.11.0 vs spec/fear/some_spec.rb in fear-1.0.0
- old
+ new
@@ -1,13 +1,11 @@
RSpec.describe Fear::Some do
- include Fear::Option::Mixin
-
it_behaves_like Fear::RightBiased::Right do
- let(:right) { Some('value') }
+ let(:right) { Fear.some('value') }
end
- subject(:some) { Some(42) }
+ subject(:some) { Fear.some(42) }
describe '#select' do
subject { some.select(&predicate) }
context 'predicate evaluates to true' do
@@ -15,20 +13,20 @@
it { is_expected.to eq(some) }
end
context 'predicate evaluates to false' do
let(:predicate) { ->(v) { v < 40 } }
- it { is_expected.to eq(None()) }
+ it { is_expected.to eq(Fear.none) }
end
end
describe '#reject' do
subject { some.reject(&predicate) }
context 'predicate evaluates to true' do
let(:predicate) { ->(v) { v > 40 } }
- it { is_expected.to eq(None()) }
+ it { is_expected.to eq(Fear.none) }
end
context 'predicate evaluates to false' do
let(:predicate) { ->(v) { v < 40 } }
it { is_expected.to eq(some) }
@@ -82,8 +80,36 @@
m.else { :default }
end
end
it { is_expected.to eq(:default) }
+ end
+ end
+
+ describe '#to_s' do
+ subject { some.to_s }
+
+ it { is_expected.to eq('#<Fear::Some get=42>') }
+ end
+
+ describe 'pattern matching' do
+ subject { Fear.xcase('Some(v : Integer)') { |v:| "matched #{v}" }.call_or_else(var) { 'nothing' } }
+
+ context 'some of int' do
+ let(:var) { Fear.some(42) }
+
+ it { is_expected.to eq('matched 42') }
+ end
+
+ context 'some of string' do
+ let(:var) { Fear.some('42') }
+
+ it { is_expected.to eq('nothing') }
+ end
+
+ context 'not some' do
+ let(:var) { '42' }
+
+ it { is_expected.to eq('nothing') }
end
end
end