I am trying to load rails in a test environment using ruby ββscript. I tried a little work and found this recommendation:
require "../../config/environment"
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'test'
This is similar to loading my environment, but my database is still in use. Am I doing something wrong?
Here is my database.yml file ... however I don't think this is a problem
development:
adapter: mysql
encoding: utf8
reconnect: false
database: BrianSite_development
pool: 5
username: root
password: dev
host: localhost
test:
adapter: mysql
encoding: utf8
reconnect: false
database: BrianSite_test
pool: 5
username: root
password: dev
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: BrianSite_production
pool: 5
username: root
password: dev
host: localhost
I can not use
ruby script/server -e test
because I'm trying to run ruby ββcode after loading rails. More specifically, what I'm trying to do: run the .sql script database, load the rails and then run the automated tests. Everything seems to be working fine, but for some reason, the rails seem to be loading into the development environment instead of the test environment.
Here is a shortened version of the code I'm trying to run:
system "execute mysql script here"
require "../../config/environment"
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'test'
describe Blog do
it "should be initialized successfully" do
blog = Blog.new
end
end
, (, ..), .
.
UPDATE:
. . :
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}"
require "spec/models/blog_spec.rb"
end
end
, spec/models/blog_spec.rb, , , ...
.