Mock Testing with Perl
I’ll start by saying that I probably should have started with Test::MockObject and saved myself all of this trouble. But sometimes things don’t work out that way.
So, I’m building unit tests in Perl the hard way. By the hard way, I mean that I am constructing ever more elaborate, interdependent, complex, and brittle test data sets to test the functions that I am hacking on. The data model is moderately complex, so there really isn’t any way around it (since I’m doing it the hard way, after all).
At one point, one function (which I am not testing) returns a result that I need for the function I am testing. The problem is that it reaches pretty far away into a section of the data model that I’d rather not set up test data for at the moment just to get that one value. This is where I’m sitting there wishing I had mock objects more than usual, since this would be a perfect place to mock the method. Since I couldn’t be bothered to see if someone had written such a handy module, I looked for a hard way to do it. Turns out that there is one.
It’s not actually hard, but it could be considered complex if you are not familiar with typeglobs and the workings of the symbol table in Perl. A …
perl testing
Upgrading Spree with the help of Git
Lately, I’ve upgraded a few Spree projects with the recent Spree releases. Spree is a Ruby on Rails ecommerce platform that End Point previously sponsored and continues to support. In all cases, my Spree project was running from the Spree gem (version 0.10.2) and I was upgrading to Spree 0.11.0. I wanted to go through a brief explanation on how I went about upgrading my projects.
First, I made sure my application was running and committed all recent changes to have a clean branch. I follow the development principles outlined here that describe methodology for developing custom functionality on top of the Spree framework core. All of my custom functionality lives in the RAILS_ROOT/vendor/extensions/site/ directory, so that directory probably won’t be touched during the upgrade.
steph@The-Laptop:/var/www/ep/myproject$ git status
# On branch master
nothing to commit (working directory clean)
Then, I tried the rake spree:upgrade task with the following results. I haven’t upgraded Spree recently, and I vaguely remembered there being an upgrade task.
steph@The-Laptop:/var/www/ep/myproject$ rake spree:upgrade
(in /var/www/ep/myproject)
[find_by_param error] database not available?
This …
ecommerce rails spree git
Getting Started with Unit Testing
So, you’re not writing tests.
And it’s not like you don’t want to, or think they’re a bad idea. It just seems so hard to get started. The hurdles to clear feel like such an impediment. It Just Couldn’t Possibly Be Productive To Start Testing Right Now, Not When My Really Important Project Needs to Get Finished in a Timely Manner.
Maybe you’re working on a legacy project, on an application built on an old framework that isn’t particularly friendly towards unit testing. To get testing, you’ll need to wrestle with so many things, it just doesn’t make sense to even try, right?
After a few years of using test-driven development (TDD) pretty consistently, I’m convinced that unit testing can and should be a more widespread practice. More importantly, after learning a lot of lessons over those few years, I think it’s well within any dedicated individual’s grasp. Care to hear about it? (Don’t answer that.)
Digression the First: Why You Should Write Tests, In Case You Require Convincing (and if you’re not writing them, then you clearly require convincing)
The code you write is for something, and that something is for somebody. Somebody cares that the stuff you wrote does what it’s supposed …
testing
SouthEast LinuxFest 2010
This past weekend I took a day to visit lovely, uh, Spartanburg, SC for the 2nd Annual SouthEast LinuxFest…
I’ve yet to live in an area of the country that either embraces Open Source Software (OSS) to a significant degree (Portland for instance) or is significantly populated (New York, San Francisco) or has significant university representation (Ann Arbor, Cambridge) which would allow me to get well connected in person or have large events to attend about the platforms I use regularly. Such is life, but it makes it difficult to feel engaged in the community aspects of many of the projects whose products I use on a daily basis. It also makes it difficult to learn in a quick fashion even the most basic elements about a new technology or practice that might be making its rounds at any given moment. Much to my surprise even here in “The South” there is a group of volunteers putting on a very good conference, not exceptional, not huge, but good. And for the second year, growing, and from the conversations I had with past participants improving!
The nature of the conference, i.e. a LinuxFest, makes the topic range incredibly varied as how can you have a targeted conference about …
community conference open-source
NoSQL at RailsConf 2010: An Ecommerce Example
Even more so than Rails 3, NoSQL was a popular technical topic at RailsConf this year. I haven’t had much exposure to NoSQL except for reading a few articles written by Ethan (Quick Thoughts on NoSQL Live Boston Conference, NoSQL Live: The Dynamo Derivatives (Cassandra, Voldemort, Riak), and Cassandra, Thrift, and Fibers in EventMachine), so I attended a few sessions to learn more.
First, it was reinforced several times that if you can read JSON, you should have no problem comprehending NoSQL. So, it shouldn’t be too hard to jump into code examples! Next, I found it helpful when one of the speakers presented high-level categorization of NoSQL, whether or not the categories meant much to me at the time:
- Key-Value Stores: Advantages include that this is the simplest possible data model. Disadvantages include that range queries are not straightforward and modeling can get complicated. Examples include Redis, Riak, Voldemort, Tokyo Cabinet, MemcacheDB.
- Document stores: Advantages include that the value associated with a key is a document that exposes a structure that allows some database operations to be performed on it. Examples include CouchDB, MongoDB, Riak, FleetDB.
- Column-based …
database ecommerce nosql ruby rails spree mongodb
pgcrypto pg_cipher_exists errors on upgrade from PostgreSQL 8.1
While migrating a client from a 8.1 Postgres database to a 8.4 Postgres database, I came across a very annoying pgcrypto problem. (pgcrypto is a very powerful and useful contrib module that contains many functions for encryption and hashing.) Specifically, the following functions were removed from pgcrypto as of version 8.2 of Postgres:
- pg_cipher_exists- pg_digest_exists- pg_hmac_exists
While the functions listed above were deprecated, and marked as such for a while, their complete removal from 8.2 presents problems when upgrading via a simple pg_dump. Specifically, even though the client was not using those functions, they were still there as part of the dump. Here’s what the error message looked like:
$ pg_dump mydb --create | psql -X -p 5433 -f - >pg.stdout 2>pg.stderr
...
psql:<stdin>:2654: ERROR: could not find function "pg_cipher_exists"
in file "/var/lib/postgresql/8.4/lib/pgcrypto.so"
psql:<stdin>:2657: ERROR: function public.cipher_exists(text) does not exist
</stdin></stdin>
While it doesn’t stop the rest of the dump from importing, I like to remove any errors I can. In this case, it really was a SMOP. Inside the …
database postgres
Rails 3 at RailsConf 2010: Code Goodness
At RailsConf 2010, popular technical topics this year are Rails 3 and NoSQL technologies. My first two articles on RailsConf 2010 so far (here and here) have been less technical, so I wanted to cover some technical aspects of Rails 3 and some tasty code goodness in standard ecommerce examples.
Bundler
Bundler, a gem management tool, is a hot topic at the conference, which comes with Rails 3. I went to a talk on Bundler and it was mentioned in several talks, but a quick run through on its use is:
gem install bundler
gem update --system # update Rubygems to 1.3.6+
Specify your gem requirements in the application root Gemfile directory.
# excerpt from Spree Gemfile in the works
gem 'searchlogic', '2.3.5'
gem 'will_paginate', '2.3.11'
gem 'faker', '0.3.1'
gem 'paperclip', '>=2.3.1.1'
bundle install # installs all required gems
git add Gemfile # add Gemfile to repository
In Spree, the long-term plan is to break apart ecommerce functional components into gems and implement Bundler to aggregate the necessary ecommerce gems. The short-term plan is to use Bundler for …
conference ecommerce ruby rails spree
RailsConf 2010: Spree and The Ecommerce Smackdown, Or Not
Spree has made a good showing at RailsConf 2010 so far this year, new site and logo released this week:
It started off in yesterday’s Ecommerce Panel with Sean Schofield, a former End Point employee and technical lead on Spree; Cody Fauser, the CTO of Shopify and technical lead of ActiveMerchant; Nathaniel Talbott, co-founder of Spreedly; and Michael Bryzek, the CTO and founder of Gilt Groupe.
The panel gave a nice overview on a few standard ecommerce questions:
- My client needs a store—what technology should I use? Why shouldn’t I just reinvent the wheel? The SaaS reps evangelized their technologies well, explaining that a hosted solution is good as a relatively immediate solution that has minimum cost and risk to a business. A client [of SaaS] need not be concerned with infrastructure or transaction management initially, and a hosted solution comes with freebies like the use of a CDN that improve performance. A hosted solution is a good option to get the product out and make money upfront. Also, both SaaS options offer elegant APIs.
- How do you address client concerns with security? Again, the SaaS guys stressed that there are a few mistakes guaranteed to kill your business and …
conference ecommerce ruby rails spree