Gem problems when upgrading to Ruby 1.9.2 with MacPorts

If you for any reason have a recompile-the-world moment in MacPorts, you may notice that the ruby19 port has been upgraded to Ruby 1.9.2. Ruby 1.9.2 includes Rubygems by default, and any existing Rubygems versions will cause problems. There's a related discussion at http://redmine.ruby-lang.org/issues/show/3607, but it's not really going to help if you just want it to work.

So if, after updating to Ruby 1.9.2, you see this:

ben-2:logs ben$ gem1.9
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/source_index.rb:68:in `installed_spec_directories': undefined method `path' for Gem:Module (NoMethodError)
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/source_index.rb:58:in `from_installed_gems'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:881:in `source_index'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:81:in `init_gemspecs'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/gem_path_searcher.rb:13:in `initialize'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:839:in `new'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:839:in `block in searcher'
    from <internal:prelude>:10:in `synchronize'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:838:in `searcher'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:478:in `find_files'
    from /opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems.rb:1103:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /opt/local/bin/gem1.9:8:in `<main>'

The problem is that Ruby is loading Rubygems from the site_ruby folder--older versions of Rubygems associated with MacPorts will go in there, and you don't want them. Nuke anything related to Rubygems in /opt/local/lib/ruby1.9/site_ruby/1.9.1 and you'll be good to go. Your gems are actually located elsewhere, and they'll still be around, so no need to waste an afternoon reinstalling them all.

This probably affects systems other than MacPorts, and if you have the same problem but elsewhere, the solution is probably the same with slightly different paths.

Spira 0.0.1 Released

I've released Spira 0.0.1, my go at an RDF ORM, built on RDF.rb. A blog post detailing the what and why is at the relevant datagraph blog entry. I think it's cool. Check it out.

Running RSpec on Heroku

Recently, while working on my rdf-do gem, a simple SQL backend for RDF.rb, I wanted to make sure it worked on Heroku. Easier said than done--Heroku demands a webapp, and RSpec hates that. But I fought it and fixed it.

First, in the root of your gem repository, add a Gemfile and a config.ru (examples are at the end). Then commit them, heroku create, and push. You'll need to push from master initially; heroku won't let you push to master from another branch until it already exists:

$ git commit -m "heroku stuff" Gemfile config.ru
$ heroku create mygemname
$ git push heroku master

Now, we don't want this Heroku stuff cluttering up our repository in general. So make a heroku branch and clean up your master. You'll never need to push the Heroku branch to github or anything.

$ git branch heroku
$ git reset --hard HEAD^1

You can update your heroku branch, and your app, whenever it is you want to test, by merging master and pushing your heroku branch to Heroku's master branch:

$ git checkout heroku
$ git merge master
$ git push heroku heroku:master

Poof! Now you're running your config.ru application. In my case, I wanted to run RSpec and get the html output. The config.ru I am using for my RDF::DataObjects gem is:

# sample heroku rackup

$:.unshift(Dir.glob("./.bundle/gems/bundler/gems/rdf-spec*gemspec*/lib").first)

require 'spec'

app = proc do |env|

    io = StringIO.new

    basename = File.basename(env['REQUEST_PATH'])
    if basename.empty?
      files = Dir.glob(File.dirname(__FILE__) + '/spec/*.spec')
    else
      files = ['spec/' + basename + ".spec"] unless basename =~ /spec$/
    end

    options = ['--format','html',files].flatten
    puts "I couldn't find #{options.last}" unless File.exists?(options.last)

    parser = ::Spec::Runner::OptionParser.new(io, io)
    parser.order!(options)
    opts = parser.options
    ::Spec::Runner.use opts
    opts.run_examples

  [ 200, {'Content-Type' => 'text/html'}, io.string ]
end


run app

There's nothing special about the gemfile:

# Gemfile
source 'http://rubygems.org'
gem 'rdf-spec'
gem 'pg'
gem 'sqlite3'
gem 'data_objects'
gem 'do_sqlite3'
gem 'do_postgres'
gem 'rdf'
gem 'rspec'

This will run any test at appname.heroku.com/spec-file-name. For example, my rdf-do gem has a spec/sqlite3.spec file. You can see the output at http://rdfdo.heroku.com/sqlite3, or below, where a screenshot is perhaps embedded; I'm not a specialist here.

RSpec results
Uploaded with plasq's Skitch!
Syndicate content