Sha256: c458b4b6e2720481042f5a5da1314ebe3e857de6288cf0243e3e519ad098ad2c

Contents?: true

Size: 1014 Bytes

Versions: 4

Compression:

Stored size: 1014 Bytes

Contents

require 'spec_helper'
require 'dump/rails_root'

def temp_remove_const(where, which)
  around do |example|
    if where.const_defined?(which)
      old = where.send(:const_get, which)
      where.send(:remove_const, which)
      example.run
      where.send(:remove_const, which) if where.const_defined?(which)
      where.const_set(which, old)
    else
      example.run
    end
  end
end

describe Dump::RailsRoot do
  include described_class

  before do
    @root = double('root')
    allow(@root).to receive(:to_s).and_return(@root)
  end

  temp_remove_const Object, :Rails
  temp_remove_const Object, :RAILS_ROOT

  it 'uses Rails if it is present' do
    Object.const_set('Rails', double('rails'))
    expect(Rails).to receive(:root).and_return(@root)
    expect(rails_root).to equal(@root)
  end

  it 'uses RAILS_ROOT if it is present' do
    Object.const_set('RAILS_ROOT', @root)
    expect(rails_root).to equal(@root)
  end

  it 'fails otherwaise' do
    expect{ rails_root }.to raise_error
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dump-1.1.0 spec/dump/rails_root_spec.rb
dump-1.0.8 spec/dump/rails_root_spec.rb
dump-1.0.7 spec/dump/rails_root_spec.rb
dump-1.0.6 spec/dump/rails_root_spec.rb