stevenbeales/mental-test

View on GitHub
spec/shared_context_specs.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

# Note: file cannot be renamed to shared_spec because of rspec bug that double loads 
# shared spec files ending in _spec.rb https://github.com/rspec/rspec-core/issues/828

# Enables testing of attributes and methods common to multiple classes 
RSpec.shared_context 'shared attributes', a: :b do
  def responds(attribute) 
    subject.respond_to?(attribute)
  end
end

RSpec.shared_context 'restore attributes' do
  after(:each) do
    subject.restore_attributes
  end
end

RSpec.shared_context 'destroy subject' do
  before :each do
    subject.destroy!
  end
end