Last week, my development team and I ran across a problem with a library we had written several months before that parsed spreadsheets given to us by one of our clients and inserted the data provided into the database. At the time we weren’t sure what the problem was. We decided to run the tests and two frustratingly useless things occurred. First, all of the tests passed. Second, the test suite took 3 hours to run.
Here’s what we had done in our “unit tests.” We had placed several of these spreadsheets as examples into our fixtures folder. Then, we had created the importer object and told it to import. We then checked the results. These tests take a long time, specifically because an import can sometimes take 15 minutes depending on the amount of data we need to import. So, how do you fix something like that? Here are some ideas.
Read More
create, data, datasets, isolation, mock, mocking, object, test, testing, unit tests
Having used both Test::Unit and RSpec, I have to agree with Jim Weirich: the difference between the two is primarily semantics. It seems to me that functionally, they are both equally capable of verifying and specifying code. However, the way in which you write the tests—the semantics—is the primary difference between the two. That being the case, I prefer the semantics of RSpec.
Read More
cucumber, rspec, Ruby, Ruby on Rails, specification, test, test/unit, testing, unit tests
I’ve been working on NORM and after a few proof of concept things, I wrote a test to test the create method for the base class.
Here’s the create method:
1
2
3
4
5
6
| def create(attributes)
columns = attributes.keys.join(", ")
values = attributes.collect {|k, v| "'#{v}'"}.join(", ")
@@connection.execute("INSERT INTO base (#{columns}) VALUES (#{values});")
new(attributes)
end |
I’ve written dozens of unit tests in Ruby on Rails, but what I didn’t realize was that the same library you use to test in Rails is the standard test/unit library came with the Ruby installation on my Windows machine. So, I wrote my own test which I later revised. Read More
Database, DBI, MySQL, NORM, Rails, Ruby, test/unit, testing, unit tests