Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Skip HashWithIndifferentAccess specs if it isn't present
Browse files Browse the repository at this point in the history
  • Loading branch information
paulelliott committed Mar 10, 2021
1 parent 2e250d1 commit 37308bd
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions spec/fabrication/support_spec.rb
@@ -1,49 +1,44 @@
require 'spec_helper'

describe Fabrication::Support do

describe ".class_for" do

context "with a class that exists" do

it "returns the class for a class" do
describe '.class_for' do
context 'with a class that exists' do
it 'returns the class for a class' do
expect(Fabrication::Support.class_for(Object)).to eq(Object)
end

it "returns the class for a class name string" do
it 'returns the class for a class name string' do
expect(Fabrication::Support.class_for('object')).to eq(Object)
end

it "returns the class for a class name symbol" do
it 'returns the class for a class name symbol' do
expect(Fabrication::Support.class_for(:object)).to eq(Object)
end

end

context "with a class that doesn't exist" do

it "returns nil for a class name string" do
expect { Fabrication::Support.class_for('your_mom') }.
to raise_error(Fabrication::UnfabricatableError)
it 'returns nil for a class name string' do
expect { Fabrication::Support.class_for('your_mom') }
.to raise_error(Fabrication::UnfabricatableError)
end

it "returns nil for a class name symbol" do
expect { Fabrication::Support.class_for(:your_mom) }.
to raise_error(Fabrication::UnfabricatableError)
it 'returns nil for a class name symbol' do
expect { Fabrication::Support.class_for(:your_mom) }
.to raise_error(Fabrication::UnfabricatableError)
end

context "and custom const_missing is defined" do
context 'and custom const_missing is defined' do
before do
module Family
def self.const_missing(name)
raise NameError, "original message"
def self.const_missing(_name)
raise NameError, 'original message'
end
end
end

it "raises an exception with the message from the original exception" do
expect { Fabrication::Support.class_for("Family::Mom") }.
to raise_error(Fabrication::UnfabricatableError, /original message/)
it 'raises an exception with the message from the original exception' do
expect { Fabrication::Support.class_for('Family::Mom') }
.to raise_error(Fabrication::UnfabricatableError, /original message/)
end
end
end
Expand All @@ -52,6 +47,10 @@ def self.const_missing(name)
describe '.hash_class', depends_on: :active_support do
subject { Fabrication::Support.hash_class }

before do
pending unless defined?(HashWithIndifferentAccess)
end

context 'with HashWithIndifferentAccess defined' do
it { should == HashWithIndifferentAccess }
end
Expand All @@ -62,12 +61,13 @@ def self.const_missing(name)
Fabrication::Support.instance_variable_set('@hash_class', nil)
Object.send(:remove_const, :HashWithIndifferentAccess)
end

after do
Fabrication::Support.instance_variable_set('@hash_class', nil)
HashWithIndifferentAccess = TempHashWithIndifferentAccess
end

it { should == Hash }
end
end

end

0 comments on commit 37308bd

Please sign in to comment.