spec/fear/some_spec.rb in fear-1.0.0 vs spec/fear/some_spec.rb in fear-1.1.0

- old
+ new

@@ -1,81 +1,83 @@ +# frozen_string_literal: true + RSpec.describe Fear::Some do it_behaves_like Fear::RightBiased::Right do - let(:right) { Fear.some('value') } + let(:right) { Fear.some("value") } end subject(:some) { Fear.some(42) } - describe '#select' do + describe "#select" do subject { some.select(&predicate) } - context 'predicate evaluates to true' do + context "predicate evaluates to true" do let(:predicate) { ->(v) { v > 40 } } it { is_expected.to eq(some) } end - context 'predicate evaluates to false' do + context "predicate evaluates to false" do let(:predicate) { ->(v) { v < 40 } } it { is_expected.to eq(Fear.none) } end end - describe '#reject' do + describe "#reject" do subject { some.reject(&predicate) } - context 'predicate evaluates to true' do + context "predicate evaluates to true" do let(:predicate) { ->(v) { v > 40 } } it { is_expected.to eq(Fear.none) } end - context 'predicate evaluates to false' do + context "predicate evaluates to false" do let(:predicate) { ->(v) { v < 40 } } it { is_expected.to eq(some) } end end - describe '#get' do + describe "#get" do subject { some.get } it { is_expected.to eq(42) } end - describe '#or_nil' do + describe "#or_nil" do subject { some.or_nil } it { is_expected.to eq(42) } end - describe '#empty?' do + describe "#empty?" do subject { some.empty? } it { is_expected.to eq(false) } end - describe '#match' do - context 'matched' do + describe "#match" do + context "matched" do subject do some.match do |m| m.some(->(x) { x > 2 }) { |x| x * 2 } - m.none { 'noop' } + m.none { "noop" } end end it { is_expected.to eq(84) } end - context 'nothing matched and no else given' do + context "nothing matched and no else given" do subject do proc do some.match do |m| m.some(->(x) { x < 2 }) { |x| x * 2 } - m.none { 'noop' } + m.none { "noop" } end end end it { is_expected.to raise_error(Fear::MatchError) } end - context 'nothing matched and else given' do + context "nothing matched and else given" do subject do some.match do |m| m.none { |x| x * 2 } m.else { :default } end @@ -83,33 +85,33 @@ it { is_expected.to eq(:default) } end end - describe '#to_s' do + describe "#to_s" do subject { some.to_s } - it { is_expected.to eq('#<Fear::Some get=42>') } + 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' } } + describe "pattern matching" do + subject { Fear.xcase("Some(v : Integer)") { |v:| "matched #{v}" }.call_or_else(var) { "nothing" } } - context 'some of int' do + context "some of int" do let(:var) { Fear.some(42) } - it { is_expected.to eq('matched 42') } + it { is_expected.to eq("matched 42") } end - context 'some of string' do - let(:var) { Fear.some('42') } + context "some of string" do + let(:var) { Fear.some("42") } - it { is_expected.to eq('nothing') } + it { is_expected.to eq("nothing") } end - context 'not some' do - let(:var) { '42' } + context "not some" do + let(:var) { "42" } - it { is_expected.to eq('nothing') } + it { is_expected.to eq("nothing") } end end end