$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 do |block| "expected block to call exit(#{status_code}) but exit" + (actual.nil? ? " not called" : "(#{actual}) was called") end failure_message_when_negated 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 module STDCapture def self.included(target) target.before do $stdin = @in = StringIO.new $stdout = @out = StringIO.new $stderr = @err = StringIO.new @terminal = $terminal $terminal = HighLine.new($stdin, $stdout) end target.after do $stdin = STDIN $stdout = STDOUT $stderr = STDERR $terminal = @terminal end end def set_stdin_string(string) @in << string @in.rewind end def stdout @out.string end def stderr @err.string end end