Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

require not working inside a spec

I've got an rspec test which looks something like this:

require 'require_all'
require_rel '../spec_helper'

describe "HtmlEntities" do
  ...some tests
end

And I'm invoking it from a rake task that looks like

require 'rspec/core/rake_task'
Rspec::Core::RakeTask.new(:spec) do |spec|
#  spec.libs << 'lib' << 'spec'
#  spec.spec_files = FileList['spec/**/*_spec.rb']
end

But I'm getting the exception:

./spec/fixers/entities_spec.rb:1:in `require': no such file to load -- require_all (LoadError)
    from ./spec/fixers/entities_spec.rb:1

I definitely have the require_all gem installed (I can see it in gem list and require it in irb). Does anyone know why I can't require it here?

like image 370
Ceilingfish Avatar asked May 07 '26 03:05

Ceilingfish


1 Answers

add require 'rubygems' to the top of your file that contains the rake task:

require 'rubygems'
require 'rspec/core/rake_task'
Rspec::Core::RakeTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

this will tell ruby to include your gems so you can run them

like image 78
Derick Bailey Avatar answered May 08 '26 18:05

Derick Bailey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!