6071 comments
2357 subscribers
6186 on Twitter
Subscribe! Feed reader E-mail

Rails: Preserving test data

I’m using Cucumber for testing my Rails project. The standard practice for automated testing in Rails is to make each test case completely self-contained and wipe out the test data after running the test. The test system accomplishes this by wrapping the operations in a transaction and rolling that transaction back at the end of the test. This is great, except when you’re developing code and you want to poke around the test environment to see what’s going on outside the handful of error messages you might get from a failed test.

I set up my test environment so that data stays in place after a test is run, and I modified my tests to delete data they need deleted. This is what I set in my features/support/env.rb:

Cucumber::Rails::World.use_transactional_fixtures = false

I also removed database_cleaner.

You can set this behaviour on a case-by-case basis with the tag @no-txn.

Running the tests individually with bundle exec cucumber ... now works. I still have to figure out why the database gets dropped when I do rake cucumber, though…

2011-04-24 Sun 16:21

Short URL: http://sachachua.com/blog/p/22216

On This Day...

  • 2013: Poll: How often would you like to receive e-mail updates? Also, quantifying my blog posting history — I’ve been posting practically every day for the past 3.5 years, and I write about a variety of topics. I’ve [...]
  • 2012: Responsive web, responsive life — A responsive site design is one that can adapt to different screen sizes and different devices. As you resize the [...]
  • 2010: Org-toodledo — I finally got around to asking my manager for permission to contribute org-toodledo as open source. Here it is. Enjoy! ;;; [...]
  • 2009: Virtual assistance: Process for managing my to-read books — I read a lot. Inspired by Mel Chua’s process for books: turning stocks into flows, here’s how I can ask [...]
  • 2008: The Incoming University Student’s Guide to Web 2.0 — Read extensively. The university library’s an amazing resource. Yours might come with access to online research libraries, too. Combine that [...]
  • 2007: Family first — A family matter requires me to fly home. It’s never too early to practice following my priorities. When we decide that we [...]
  • 2006: Mesh magic: Tara Hunt — I have big dreams. I have these thoughts I thought I was alone in. Then I found the blogosphere. I [...]
  • 2006: Mesh magic: Fifteen minutes of fame — Today’s fifteen minutes of fame focused on some totally awesome social Web 2.0 orgs and people. There was Favorville, an experiment [...]
  • 2006: Mesh magic: Tara Hunt fangirling — I am a fangirl of Tara Hunt. =) On Technorati: meshconference, mesh06, web2.0, mesh Random Japanese sentence: 猫の舌はざらざらしている。 The tongue of a cat [...]
  • 2006: Mesh magic: Venture capital and Web 2.0 — Mathew Ingram talks with venture capitalist and blogger Dr. Paul Kedrosky. Cute snippet from the intro: has an approach to blogging that [...]
  • 2006: Mesh magic: The Future of Marketing — Stuart MacDonald talks with Steve Rubel of Edelman and Micropersuasion.com. I slipped into the session just in time to hear a few [...]
  • 2006: Mesh magic: At the registration desk — I’m a paid registrant at Mesh today, but I’m volunteering at the registration desk because it’s fun greeting people and [...]
  • 2006: Mesh magic: Volunteering — Volunteering was absolutely the best thing I could’ve done. Here’s most of the story: I had ignored my Web 2.0 blog [...]
  • 2006: Connect — I’m also on LinkedIn and 43people. Let’s connect, share, inspire… =) Random Japanese sentence: うちの猫は台所にいます。 Our cat is in the kitchen.
  • 2006: Catching up; mesh post coming soon — Day 1 of the mesh conference, and day 3 of my conference sprint. (Barcamp was last weekend.) I’m running on a [...]
  • 2004: Passport details — -----BEGIN PGP MESSAGE----- Version: GnuPG v1.2.4 (GNU/Linux) hQEOAzQ6c9jHW5SMEAQAgom9v6UasEWvNjX1/OELXG3LdTkS//+6WMw+LEixJ8bp QSq9udX2zexBguw3Q8JkXqReXGITT1dg/uHB9YBzbHKC+120vIY+IHiUFntQJkxC /Cn/kEMQ2lggF8TDYu4TTKwgwz1b84zJKIRcutDLsenEoGo6S+15fpFNlGw2aI8D /RkXROkRh95z/lfNW7IynryO/kV8AelQbIkezMgyzFl7hHXJY5R+kqi7pFaAVDep kpAPeq2RJ7uYS+QdtQArYx7I6Y4ekcLcHZBjSwS8wNEvbvTfmCaayn1YNzrG8tLU 1tIhyRRMFOePp0MlEQPBMFydfUBPOpjh0n6mh3RuiC3c0pUBUKoMfdV8yNCQCiv0 2ahDBFokvGtyO1B2u+NaGGNGaf/GSr1EUj41MzjobdOZO/xn8q8b0nchjPS8MYZU NfRluTIiXrcq/KnwlIAzphGVA8Q94+Snd1CPvjvnLlTCgAhyV3wX20UBInny1Zsu /EaOGq7OKgTLT2G+OIJvygY0/OEPASiHN6AO7YcUZQlRJ7xAypavBQ== =fW0P -----END PGP MESSAGE-----
  • 2003: Ernest Baello — Thought I’d look up one of my oldest friends today. From http://slappy.cs.uiuc.edu/fall02/team4/contacts.html: Ernest Baello (Project Manager & Customer Contact): (217) 898-6821 (oooh, project [...]
  • 2003: debian emacs policy — Peter S Galbraith suggests (if (not (file-exists-p "/usr/share/emacs/site-lisp/emacs-goodies-el")) (message "Package emacs-goodies-el is removed but [...]
  • 2003: www.blogpulse.co
  • 2003: Woke up late today — Woke up past 7 today, am rushing off to school. Should’ve gotten out of bed when Cat was trying to wake [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging