Rails: How to test code in the lib/ directory?

前端 未结 7 1491

I have a model which gets its data from a parser object. I\'m thinking that the parser class should live in the lib/ directory (although I could be persuaded that it should live

7条回答
  •  清酒与你
    2021-01-30 07:26

    I was looking to do the same thing but with rspec & autospec and it took a little digging to figure out just where they were getting the list of directories / file patterns that dictated which test files to run. Ultimately I found this in lib/tasks/rspec.rake:86

      [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
        desc "Run the code examples in spec/#{sub}"
        Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
          t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
          t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
        end
      end
    

    I had placed my tests in a new spec/libs directory when the rpsec.rake file was configured to look in spec/lib. Simply renaming libs -> lib did the trick!

提交回复
热议问题