Sha256: 475e3aecd3a0392cb94ebcd5b73acc01dc3725746bf9e0a6a1eca4a34ad9ce8d

Contents?: true

Size: 1.82 KB

Versions: 35

Compression:

Stored size: 1.82 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rspec'
require 'active_record'  # for Flydata::Heroku
require 'protected_attributes'

# Change FLYDATA_HOME to tempdir
temp_dir_path = Dir.mktmpdir
ENV['FLYDATA_HOME'] = temp_dir_path
# Set dummy flydata_api_host file
File.open(File.join(temp_dir_path, 'flydata_api_host'), 'w') do |f|
  f.write('http://0.0.0.0:3000')
end

require 'logger'
$log = Logger.new(STDOUT)

require 'flydata'


# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|

  if defined? ActiveRecord
    # The ActiveRecord::Rollback exception will be caught by the transaction
    # block and roll back all the database changes after each spec.
    config.around do |example|
      if ActiveRecord::Base.connected?
        ActiveRecord::Base.transaction do
          example.run
          raise ActiveRecord::Rollback
        end
      else
        example.run
      end
    end
  end
end

# https://gist.github.com/stevenharman/2355172
RSpec::Matchers.define :terminate do |code|
  actual = nil

  def supports_block_expectations?
    true
  end

  match do |block|
    begin
      block.call
    rescue SystemExit => e
      actual = e.status
    end
    actual and actual == status_code
  end

  chain :with_code do |status_code|
    @status_code = status_code
  end

  failure_message_for_should do |block|
    "expected block to call exit(#{status_code}) but exit" +
      (actual.nil? ? " not called" : "(#{actual}) was called")
  end

  failure_message_for_should_not do |block|
    "expected block not to call exit(#{status_code})"
  end

  description do
    "expect block to call exit(#{status_code})"
  end

  def status_code
    @status_code ||= 0
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
flydata-0.3.24 spec/spec_helper.rb
flydata-0.3.23 spec/spec_helper.rb
flydata-0.3.22 spec/spec_helper.rb
flydata-0.3.21 spec/spec_helper.rb
flydata-0.3.20 spec/spec_helper.rb
flydata-0.3.19 spec/spec_helper.rb
flydata-0.3.18 spec/spec_helper.rb
flydata-0.3.17 spec/spec_helper.rb
flydata-0.3.16 spec/spec_helper.rb
flydata-0.3.15 spec/spec_helper.rb
flydata-0.3.14 spec/spec_helper.rb
flydata-0.3.13 spec/spec_helper.rb
flydata-0.3.12 spec/spec_helper.rb
flydata-0.3.11 spec/spec_helper.rb
flydata-0.3.10 spec/spec_helper.rb
flydata-0.3.9 spec/spec_helper.rb
flydata-0.3.8 spec/spec_helper.rb
flydata-0.3.7 spec/spec_helper.rb
flydata-0.3.6 spec/spec_helper.rb
flydata-0.3.5 spec/spec_helper.rb