user1657173
user1657173

Reputation: 231

Ruby on Rails - run unit tests in subfolder

Is it possible to run tests only from one subfolder?

Something like this:

ruby -I"lib:test" test/functional/api/*

Thanks

Upvotes: 1

Views: 608

Answers (2)

yoppuyoppu
yoppuyoppu

Reputation: 490

I assume you're trying to find a way to run multiple unit tests in a specific directory and you're not using RSpec...

In that case, you can create a task in a Rakefile and run it from command line. This page Rake::TestTask will tell you how to create such a file. You're file is going to look something like this:

Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['test/functional/api/*.rb']
  t.verbose = true
end

And then run:

rake test

Upvotes: 3

Andreas Lyngstad
Andreas Lyngstad

Reputation: 4927

If you use rspec you can do this

rspec ./spec/models/

for a folder

and this

rspec ./spec/models/car_spec.rb

for one file

and this

rspec ./spec/models/car_spec.rb:34

for the test on line 34

Upvotes: 0

Related Questions