Sha256: 6bfe4c6a097533828ba8d17c26b99fd9eee700c3ca17b26cdeb8cd5a38b76ab2

Contents?: true

Size: 1.58 KB

Versions: 77

Compression:

Stored size: 1.58 KB

Contents

require '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

77 entries across 69 versions & 15 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/thor-0.18.1/spec/rake_compat_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/rake_compat_spec.rb