Sha256: 52da5fd97d498a9eb0bbd62677be50f0b2ff7f247cbdd14ee67b9874ae12ca1b

Contents?: true

Size: 1.3 KB

Versions: 13

Compression:

Stored size: 1.3 KB

Contents

namespace :landable do
  namespace :pgtap do
    def has_pgprove?
      @@has_prove ||= Kernel.system('which pg_prove > /dev/null')
    end

    def has_pgconfig?
      @@has_pgconfig ||= Kernel.system('which pg_config > /dev/null')
    end

    def has_pgtap?
      has_pgtap = false

      if has_pgconfig?
        sharedir = "#{`pg_config | grep SHAREDIR | awk {' print $3 '}`.strip}/extension/pgtap.control"
        if File.file?("#{sharedir}")
          has_pgtap = true
        end
      end

      has_pgtap
    end

    desc "Run PGTap unit tests"
    task :run, [:test_file] => [ :environment ] do |t, args|
      dbdir = "#{Rails.root}/../../db"

      tests = args[:test_file] ? args[:test_file] : "*.sql"

      if has_pgprove? and has_pgtap?
        # Load pgtap functions into database.  Will not complain if already loaded.
        ActiveRecord::Base.connection.execute("CREATE EXTENSION IF NOT EXISTS pgtap;")

        # Runs the tests.  Wrapped pg_prove call in shell script due to issues with return values
        sh "cd #{Rails.root}/../../script && ./pgtap"
      else
        puts "\nPGTap and/or pg_prove not installed.  Skipping DB unit tests"
        puts "Reference 'http://pgtap.org/documentation.html#installation' for installation instructions."
      end
    end
  end

  task :pgtap => 'pgtap:run'
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
landable-1.13.1 lib/tasks/landable/pgtap.rake
landable-1.12.3 lib/tasks/landable/pgtap.rake
landable-1.12.2 lib/tasks/landable/pgtap.rake
landable-1.12.1 lib/tasks/landable/pgtap.rake
landable-1.11.1 lib/tasks/landable/pgtap.rake
landable-1.11.0 lib/tasks/landable/pgtap.rake
landable-1.10.0.rc2 lib/tasks/landable/pgtap.rake
landable-1.10.0.rc1 lib/tasks/landable/pgtap.rake
landable-1.9.2 lib/tasks/landable/pgtap.rake
landable-1.9.1 lib/tasks/landable/pgtap.rake
landable-1.9.0 lib/tasks/landable/pgtap.rake
landable-1.9.0.rc2 lib/tasks/landable/pgtap.rake
landable-1.9.0.rc1 lib/tasks/landable/pgtap.rake