Rails 3.2.1, Ruby 1.9.3p125, rspec 2.8.0, rake 0.9.2.2
Rake::Task['namespace:task_name'].invoke refused to find namespace:task_name (namespace.rake is in Rails.root/lib/tasks). .execute - same.
So, I'm doing
system 'RAILS_ENV=test bundle exec rake namespace:taskname'
which appears to work but -- does not use test database.
I have a module and have been told to write tests for it within Rails framework. I'm using rspec. I have the cookbook task that creates fixtures from my "sandbox" environment ("development" is somewhere else and inaccessible to me). The fixtures are created correctly.
Next, I try to run
system 'RAILS_ENV=test bundle exec rake db.fixtures.load FIXTURES=<fixture_list>'
No data in my test db; I'm just assuming that it's being loaded back into my sandbox db, which is the same place from which it was derived.
The purpose of my module is to examine other tables in the database, and for each day, to create or not create a "feedstatus" record for each of 34 feeds. Whether the record gets created depends on predetermined schedules, whether the "feed" observes a holiday, what day of the week it is - many criteria that vary wildly but are algorithmically determined (many algorithms here).
I could write several hundred tests to test each possible outcome for each "feed" but (a) I think that's a lot of work; (b) it would be unmaintainable (more "feeds" will be added in the future); (c) I'm still working on heuristics about the algorithms - something new or something I didn't anticipate is always appearing and (d) I'm concerned that I will revert to using the same algorithms that the module uses, which tests nothing but my typing.
So, the plan was to create a spreadsheet matrix of all the days of the year x all the "feeds' (34x366) and manually put a 0 or a 1 to indicate the "feed" shouldn't or should be there that day. Yes, it's a bit of work, but the people who follow me will be more comfortable with changing spreadsheets than ruby code, and any discrepancies will show up.
So, the steps are: 1. prepare the empty test database 2. create the fixtures (every time to catch changes to the real data) 3. load the fixtures 4. run the module for a year's worth of days. 5. For each spreadsheet entry, match it to presence or absence of the record that the module will or will not create.
But - I'm stuck at "load the fixtures". No data gets loaded into the test db.
Incidentally, invoking the module with
system 'RAILS_ENV=test bundle exec rake namespace:task_that_calls_module'
causes the module to use the sandbox (current environment) rather than the test db.
The task_that_calls_module also has RAILS_ENV=test name_of_module_method_to_perform and still writes the sandbox, not the test db. "sandbox" is my actual development environment.
The rspec file in Rails.root/spec/modules:
describe "MakeExpected" do
require 'rake'
before(:all) do
system "bundle exec rake testdb:extract_fixtures"
puts "extracted fixtures"
system "bundle exec rake db:test:load"
puts "db:test:load"
system 'RAILS_ENV=test bundle exec rake db:fixtures:load'
puts "loaded fixtures"
system("RAILS_ENV=test bundle exec rake testdb:run_make_expected --trace")
end # before
it "should be true" do
end # should be true
end # describe
The testdb:run_make_expected task in Rails.root/lib/tasks/testdb.rake:
task :run_make_expected => :environment do
include MakeExpected
RAILS_ENV=test test_scheduler
end # task do
After the before block, there will be some convoluted tests comparing db with expectations from the spreadsheet.
Please tell me it's something dumb and simple?
Oh - the bundle exec db rake stuff is because I don't have root to install rake into the regular bin directory. Same with rspec. I invoke this whole thing as:
bundle exec rspec spec/modules
where this make_expected_spec.rb is the only file in that directory. Should I be saying
RAILS_ENV=test bundle exec rspec spec/modules
???