Search code examples
ruby-on-railsrspecruby-on-rails-3.2rakerspec2

`uninitialized constant Rake` in rake spec


According to this tutorial http://carlosplusplus.github.io/blog/2014/02/01/testing-rake-tasks-with-rspec/

to test rake tasks with rspec, one has to set

Rake.application = rake

in a before block. However, I get the error

Failure/Error: Rake.application = rake
NameError:
uninitialized constant Rake

How can I fix this?


Solution

  • You need to require "rake" before the offending code. The tutorial you are using is based on a blog post by Thoughtbot, which includes the appropriate require and can be used as an example.