Requiring a thor task in my rspec results in undefined method

rspec, ruby, ruby-on-rails, thor

Solution

The answer that I've found is to use `load` rather than `require` (I thought I had tested this, but perhaps I was mistaken)

so:

` require 'thor' load File.join(Rails.root.join('lib/tasks/test_task.thor')) `

Problem

I'm trying to write a very basic rspec to for my Thor task, however when trying to require (or load) the task it fails, giving NoMethodError ('undefined method ...') for the various Thor class-level methods (desc, method_option, class_option etc) ``` require "spec_helper" require Rails.root.join('lib/tasks/test_task.thor') describe 'TestTask' do it "is instantiated ok" do TestTask.new end end ``` As you can see I'm testing in the environment of a rails app. The thor task itself executes fine from the command line. I've looked through the Thor specs, as suggested elsewhere (Where can I find good examples of testing a Thor script with RSpec?) Any ideas?

Original source

Related problems