Monday, June 11, 2012

one-line update for all pom versions in multi-module project

We have a multi-module Maven project with many children, so it's a little annoying to bump the version number. Here's a one-liner to do it, just replace _OLD_ and _NEW_ with the old version and new version, respectively.
for f in `find . -name pom.xml`; do sed 's/_OLD_/_NEW_/' $f > $f.new; mv $f.new $f; done
for example:
for f in `find . -name pom.xml`; do sed 's/1.1.23-SNAPSHOT/1.1.24-SNAPSHOT/' $f > $f.new; mv $f.new $f; done

*DON'T FORGET TO CHECK THE DIFF (you ARE using Git, right?)*

** Update (thanks jamcole)**

Or even easier, use the Maven versions plugin (from the top-level project):
mvn versions:set

Saturday, June 9, 2012

Autotest w/ jeweler and 1.9.2-p320

I wanted to take another stab at TDD (and stick with it this time!) so I dusted off my copy of the awesome PragProg book 'Continuous Testing' and tried to get everything working again. Here's what I had to do (since I have trouble getting everything to work anytime I try - not detracting from the hard work the authors put into the writing, but it's never gone smoothly for me) There's just too many moving pieces that always seem to have minor version incompatibilities or quirks.

jeweler - wasn't too tough to set up, I'm using 1.8.3

So, run:

  • $ jeweler --rspec tower_d
  • $ cd tower_d
  • $ rake
Cool, get the expected:
F

Failures:

  1) TowerD fails
     Failure/Error: fail "hey buddy, you should probably rename this file and start specing for real"
     RuntimeError:
       hey buddy, you should probably rename this file and start specing for real
     # ./spec/tower_d_spec.rb:5:in `block (2 levels) in '

Finished in 0.00038 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/tower_d_spec.rb:4 # TowerD fails

Ok, now to get autotest working...

  • $ autotest
loading autotest/rspec2

Uhoh, it just hangs and doesn't run anything... this is where we run off the rails a bit. Time to read through page after page of conflicting advice based on which version of autotest/ZenTest/rspec/etc we're running.

$ bundle list
Gems included by the bundle:
  * bundler (1.1.4)
  * diff-lcs (1.1.3)
  * git (1.2.5)
  * jeweler (1.8.3)
  * json (1.7.3)
  * multi_json (1.3.6)
  * rake (0.9.2.2)
  * rdoc (3.12)
  * rspec (2.8.0)
  * rspec-core (2.8.0)
  * rspec-expectations (2.8.0)
  * rspec-mocks (2.8.0)
  * simplecov (0.6.4)
  * simplecov-html (0.5.3)

$ gem list autotest

*** LOCAL GEMS ***

autotest (4.4.6)
autotest-fsevent (0.2.8)
autotest-growl (0.2.16)
autotest-rails (4.1.2, 4.1.1)
Hmm... ok, well there's this (rspec wiki) that says for rspec > 2.3 (I'm using 2.8.0) to "make sure you have a .rspec file in the project root. That tells RSpec to tell Autotest to load RSpec’s autotest extension." Jeweler created one already, so that can't be it...

Turns out that you need something like this in a file called .autotest (at the root of your project). The way the wiki is formatted, it LOOKS like it applies to rspec-2.0 – 2.2 only, but it must be for all =/

Autotest.add_hook(:initialize) {|at|
  at.add_exception %r{^\.git}  # ignore Version Control System
  at.add_exception %r{^./tmp}  # ignore temp files, lest autotest will run again, and again...
  at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
    Dir['spec/**/*_spec.rb']
  }
  nil
}

tl;dr: Make sure you have a .autotest file that adds the mapping

Monday, May 7, 2012