Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No tasks shown in thor list with thor/rake_compat for RSpec #619

Open
FilBot3 opened this issue Sep 10, 2018 · 2 comments
Open

No tasks shown in thor list with thor/rake_compat for RSpec #619

FilBot3 opened this issue Sep 10, 2018 · 2 comments

Comments

@FilBot3
Copy link

FilBot3 commented Sep 10, 2018

Using the example found here:
https://www.rubydoc.info/github/wycats/thor/Thor/RakeCompat

I am unable to run the RSpec task, or have it show when running thor list.

user01@M1711732 [17:26:32] ~/Documents/development/
$ thor list --debug
user01@M1711732 [17:26:42] ~/Documents/development/
$ thor list --debug --all
user01@M1711732 [17:26:46] ~/Documents/development/
$ cat Thorfile
require 'thor/rake_compat'
require 'rspec/core/rake_task'

class Default < Thor
  include Thor::RakeCompat

  RSpec::Core::RakeTask.new(:spec) do |t|
    t.spec_opts = ['--options', './.rspec']
    t.spec_files = FileList['spec/**/*_spec.rb']
  end
end

user01@M1711732 [17:26:54] ~/Documents/development/
$ thor version
Thor 0.20.0
@FilBot3
Copy link
Author

FilBot3 commented Sep 10, 2018

From playing around with this a bit and looking at the spec's and the Thorfile included with the repository, you need to create a Thor task to invoke the Rake task.

require 'thor/rake_compat'
require 'rspec/core/rake_task'

class Default < Thor
  include Thor::RakeCompat

  RSpec::Core::RakeTask.new(:spec) do |t|
    t.spec_opts = ['--options', './.rspec']
    t.spec_files = FileList['spec/**/*_spec.rb']
  end

  desc 'spec', 'Run RSpec tests'
  def spec
    Rake::Task['spec'].invoke
  end
end

Even taking from the rake_compat_spec.rb

require 'thor/rake_compat'
require "rake/tasklib"

class RakeTask < Rake::TaskLib
  def initialize
    define
  end

  def define
    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
  
  desc 'cool', 'say cool'
  def cool
    Rake::Task['cool'].invoke
    puts ThorTask.tasks['cool'].description
  end
end

The result is:

thor thor_task:cool
COOL
say cool

@FilBot3
Copy link
Author

FilBot3 commented Sep 10, 2018

Would it be helpful to make this into a Wiki page as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant