Sha256: ff4d9dd1c22dacdc923cce813afafb141a6bf4424ee157a02902cd91f651e076

Contents?: true

Size: 1.63 KB

Versions: 25

Compression:

Stored size: 1.63 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'thor/rake_compat'
require 'rake/tasklib'

$main = self

class RakeTask < Rake::TaskLib
  def initialize
    define
  end

  def define
    $main.instance_eval do
      desc "Say it's cool"
      task :cool do
        puts "COOL"
      end

      namespace :hiper_mega do
        task :super do
          puts "HIPER MEGA SUPER"
        end
      end
    end
  end
end

class ThorTask < Thor
  include Thor::RakeCompat
  RakeTask.new
end

describe Thor::RakeCompat do
  it "sets the rakefile application" do
    expect(["rake_compat_spec.rb", "Thorfile"]).to include(Rake.application.rakefile)
  end

  it "adds rake tasks to thor classes too" do
    task = ThorTask.tasks["cool"]
    expect(task).to be
  end

  it "uses rake tasks descriptions on thor" do
    expect(ThorTask.tasks["cool"].description).to eq("Say it's cool")
  end

  it "gets usage from rake tasks name" do
    expect(ThorTask.tasks["cool"].usage).to eq("cool")
  end

  it "uses non namespaced name as description if non is available" do
    expect(ThorTask::HiperMega.tasks["super"].description).to eq("super")
  end

  it "converts namespaces to classes" do
    expect(ThorTask.const_get(:HiperMega)).to eq(ThorTask::HiperMega)
  end

  it "does not add tasks from higher namespaces in lowers namespaces" do
    expect(ThorTask.tasks["super"]).not_to be
  end

  it "invoking the thor task invokes the rake task" do
    expect(capture(:stdout) {
      ThorTask.start ["cool"]
    }).to eq("COOL\n")

    expect(capture(:stdout) {
      ThorTask::HiperMega.start ["super"]
    }).to eq("HIPER MEGA SUPER\n")
  end
end

Version data entries

25 entries across 21 versions & 8 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/thor-0.17.0/spec/rake_compat_spec.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/thor-0.17.0/spec/rake_compat_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/thor-0.17.0/spec/rake_compat_spec.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/rake_compat_spec.rb