Sha256: e7c84da9cd300162cb85038d46b071ac9b43cfa38102b39253a2588a51e78a14

Contents?: true

Size: 1.46 KB

Versions: 12

Compression:

Stored size: 1.46 KB

Contents

require 'assert'
require 'pathname'
require 'active_record'
require 'ardb/runner'

class Ardb::Runner

  class BaseTests < Assert::Context
    desc "Ardb::Runner"
    setup do
      @runner = Ardb::Runner.new(['null', 1, 2], 'some' => 'opts')
    end
    subject{ @runner }

    should have_readers :cmd_name, :cmd_args, :opts

    should "know its cmd, cmd_args, and opts" do
      assert_equal 'null', subject.cmd_name
      assert_equal [1,2],  subject.cmd_args
      assert_equal 'opts', subject.opts['some']
    end

  end

  class RunTests < BaseTests
    desc "when running a command"
    setup do
      Ardb::Adapter.reset
      @runner = Ardb::Runner.new(['null', 1, 2], {})
    end
    teardown do
      Ardb::Adapter.reset
    end

    should "validate the configs" do
      orig_adapter = Ardb.config.db.adapter
      Ardb.config.db.adapter = nil
      assert_raises(Ardb::NotConfiguredError) { subject.run }
      Ardb.config.db.adapter = orig_adapter
    end

    should "init the adapter" do
      assert_nil Ardb.adapter
      subject.run
      assert_not_nil Ardb.adapter
    end

    should "set the AR logger" do
      default_ar_logger = ActiveRecord::Base.logger
      subject.run
      assert_equal Ardb.config.logger, ActiveRecord::Base.logger
      ActiveRecord::Base.logger = default_ar_logger
    end

    should "complain about unknown cmds" do
      runner = Ardb::Runner.new(['unknown'], {})
      assert_raises(UnknownCmdError) { runner.run }
    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ardb-0.17.0 test/unit/runner_tests.rb
ardb-0.16.0 test/unit/runner_tests.rb
ardb-0.15.0 test/unit/runner_tests.rb
ardb-0.14.0 test/unit/runner_tests.rb
ardb-0.13.0 test/unit/runner_tests.rb
ardb-0.12.0 test/unit/runner_tests.rb
ardb-0.11.0 test/unit/runner_tests.rb
ardb-0.10.0 test/unit/runner_tests.rb
ardb-0.9.0 test/unit/runner_tests.rb
ardb-0.8.0 test/unit/runner_tests.rb
ardb-0.7.0 test/unit/runner_tests.rb
ardb-0.6.0 test/unit/runner_tests.rb