Sha256: 31694409a3c620dc1f171695f0bb5f0d0b04744649ae338adbacb5a9a4bec8fd

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

require "helpers/acceptance/git_helper"

module AcceptanceHelper
  include FileUtils

  def export_directory
    File.dirname(__FILE__) + "/../../exports"
  end

  def enable_auth!
    Integrity.config[:use_basic_auth]      = true
    Integrity.config[:admin_username]      = "admin"
    Integrity.config[:admin_password]      = "test"
    Integrity.config[:hash_admin_password] = false
  end

  def login_as(user, password)
    def AcceptanceHelper.logged_in; true; end
    basic_auth user, password
    visit "/login"
    Integrity::App.before { login_required if AcceptanceHelper.logged_in }
  end

  def log_out
    def AcceptanceHelper.logged_in; false; end
    @_webrat_session = Webrat::SinatraSession.new(self)
  end

  def disable_auth!
    Integrity.config[:use_basic_auth] = false
  end

  def set_and_create_export_directory!
    FileUtils.rm_r(export_directory) if File.directory?(export_directory)
    FileUtils.mkdir(export_directory)
    Integrity.config[:export_directory] = export_directory
  end

  def setup_log!
    log_file = Pathname(File.dirname(__FILE__) + "/../../integrity.log")
    log_file.delete if log_file.exist?
    Integrity.config[:log] = log_file
  end
end

class Test::Unit::AcceptanceTestCase < Test::Unit::TestCase
  include AcceptanceHelper
  include Test::Storyteller
  include GitHelper
  include Webrat::Methods
  include Webrat::Matchers
  include Webrat::HaveTagMatcher

  # TODO: does this belongs in Webrat::SinatraSession?
  Webrat::Methods.delegate_to_session :response_code

  def app
    Integrity::App.tap { |app|
      app.set     :environment, :test
      app.disable :raise_errors, :run, :reload
    }
  end

  before(:each) do
    # ensure each scenario is run in a clean sandbox
    Integrity.config[:base_uri] = "http://www.example.com"
    enable_auth!
    setup_log!
    set_and_create_export_directory!
    log_out
  end

  after(:each) do
    destroy_all_git_repos
    rm_r export_directory if File.directory?(export_directory)
  end

end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
foca-integrity-0.1.9.1 test/helpers/acceptance.rb
oliyoung-integrity-0.1.9.0 test/helpers/acceptance.rb
integrity-0.1.9.1 test/helpers/acceptance.rb