Running RSpec Files From ruby code

Posted by Brian D. on Stack Overflow See other posts from Stack Overflow or by Brian D.
Published on 2010-05-13T13:38:43Z Indexed on 2010/05/13 13:44 UTC
Read the original article Hit count: 254

Filed under:
|

I'm trying to run RSpec tests straight from ruby code. More specifically, I'm running some mysql scripts, loading the rails test environment and then I want to run my rspec tests (which is what I'm having trouble with)... I'm trying to do this with a rake task. Here is my code so far:

require"spec" 
require "spec/rake/spectask" 
RAILS_ENV = 'test'

namespace :run_all_tests do 
  desc "Run all of your tests" 

  puts "Reseting test database..." 
  system "mysql --user=root --password=dev < C:\\Brian\\Work\\Personal\\BrianSite\\database\\BrianSite_test_CreateScript.sql" 
  puts "Filling database tables with test data..." 
  system "mysql --user=root --password=dev < C:\\Brian\\Work\\Personal\\BrianSite\\database\\Fill_Test_Tables.sql" 

  puts "Starting rails test environment..." 
  task :run => :environment do 
    puts "RAILS_ENV is #{RAILS_ENV}"
    # Run rspec test files here...
    require "spec/models/blog_spec.rb" 
  end 
end

I thought the require "spec/models/blog_spec.rb" would do it, but the tests aren't running. Anyone know where I'm going wrong?

Thanks for any help.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rspec