Ruby on Rails Friday, June 29, 2012

Rails 3.2.1 Ruby 1.9.3p125 Rspec 2.8.0
I have a utility written in ruby that executes within a Rails
environment. It creates database records in one table based on the info
in other tables. A date and a name determine uniqueness of these created
records.

To test this, I have to run the utility giving it date parameters for a
year + 4 days and then, for each test, test to see if each of 34 records
has or has not been created according to a spreadsheet that contains the
expected result.

The utility creates records according to a number of different
algorithms so that, for example, on the 21st of the month it may create
a record for the 19th and another for the 31st, so it's not feasible to
run this on a day-by-day basis.

The thing is, I don't want to have to run the utility inside every test
- it takes several minutes for each run and there will be 34 x 366 tests
(plus a few extras).

So, I run the utility and then, when I execute the first test, I
discover that the records created by the utility are gone and the
database contains just the fixtures data.

Roughly, I have:

describe "comprehensive test" do
context "all year" do
<utility to extract infrastructure data from dev database>
<code to symlink a yaml file with one or another mutually exclusive
seed records>
fixtures :all
<execute utility for 2012-01-01 to 2013-01-05>
it "should have more than the seed records in the table examined" do
Table.all.count.should be > 2 # number of seed records
end
<each day, each identifier, try to retrieve record and check against
0 or 1 on the corresponding spreadsheet entry>
end
context "already existing records" do
<empty database>
<code to symlink the other yaml file into a fixture>
fixtures :all
<execute utility for 2012-05-31 only>
<test that a specific 6 records have not been created>
end
end

One test actually implemented and it fails.

The one test will be followed by complex looping code reading the
spreadsheet and requesting the corresponding record and either it should
be there or it shouldn't. That's over 12,000 tests because not creating
a record when it shouldn't be there is as important as creating it when
it should. And then there's the second context...

Running a single month is not sufficient because holidays, days of
the week, first and last days of the month figure in for different
record creation algorithms.

But I can't get past this one test. How do I stop rspec from clearing
the relevant table before the test? I watch the records I want being
created, but then the db is restored to just the fixtures.

Note that I could have done this in shell in about 1/2 day but I've been
ordered to do this in the rspec framework. I feel like I'm building a
blivet here (10 pounds of ... slop in a 5-lb bag).

Please someone help? Otherwise I will just have to write the shell
script and call it from rspec :(
TIA

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.

No comments:

Post a Comment