Open File Fast reached 1.0


After almost a year of development and several beta versions Open File Fast finally became stable and mature enough to bump its version to 1.0. There’s not much new in this release except several bugfixes and improved look of search results list.

Now it looks like this:

Notice that entered characters are now displayed in bold indicating where they were found in each filename. File path is now right aligned and has lighter color. It doesn’t come into way anymore when looking at results and lets you localize the file you seek even faster.

Netbeans version of plugin was updated to work in Netbeans 6.8, JEdit’s one works now in final JEdit 4.3 version (with ProjecViewer 2.9.1+).

Netbeans NBM package: off-netbeans-1.0.nbm
JEdit jar file: off-jedit-1.0.jar

View Comments

Quick and dirty hack for RSpec's before(:all)


RSpec is generally nice testing framework. It supports before and after hooks which can be invoked before/after each test case or all test cases. before(:all) is a little confusing though. It runs your "before" block before all "describes" and "contexts", also nested ones. Here's example:

describe User do
  before(:all) { puts "preparing for war" }
  it "should foo" do
    ...
  end
  context "active" do
    it "should bar" do
      ...
    end
  end
  context "inactive" do
    it "should baz" do
      ...
    end
  end
end

I would expect "preparing for war" to show up once. But before(:all) was called thrice. First, for top level "describe", then two times for "contexts". There were some suggestions to change this behaviour or to add and option to skip call for nested groups but nothing has changed recently. People are even trying some crazy hacks like this.

What I needed was to wipe database for every model spec and every request spec because factory generated records made my build unstable (due to uniqueness validations). After trying few things I ended up with using before(:all) with some condition. First, I've added before_top_level_group method to Spec::Runner::Configuration and saved it in spec/before_top_level_group.rb:

$_groups = []

class Spec::Runner::Configuration
  def before_top_level_group
    before(:all) do
      top_level_group = self.class.to_s[/^.+ExampleGroup::([^:]+)/, 1]
      unless $_groups.any? { |g| top_level_group == g }
        $_groups << top_level_group
        yield
      end
    end
  end
end

Then in spec_helper I used it like this:

require 'before_top_level_group'

Spec::Runner.configure do |config|
  config.before_top_level_group do
    # re-migrate db for each top-level group (it usually equals one *_spec.rb file)
    DataMapper.auto_migrate!
  end
end

Voila! I know it's a dirty hack but it works for me and I'll be using it until RSpec is patched or I switch my testing framework to something else (Bacon looks nice).

View Comments

More Rack::Shell goodies for all Rack worshippers


Rack::Shell got a lot of attention lately and I received some feature requests/ideas from great ruby hackers. Daniel Neighman, currently working on Pancake, pointed me towards Bryan Helmkamp's rack-test. This awesome piece of code is now used by racksh to simulate HTTP requests to your Rack application. Yay!

% racksh
Rack::Shell v0.9.4 started in development environment.
>> $rack.get "/"
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...

Check out README for details. Here are just few examples what's possible:

$rack.get "/", {}, { 'REMOTE_ADDR' => '123.45.67.89' }
$rack.header "User-Agent", "Firefox"
$rack.post "/users", :user => { :name => "Jola", :email => "jola@misi.ak" }

Now you can build and test Sinatra apps in single racksh session like this.

Another nice thing in new version is support for session setup through config files. Rack::Shell supports configuration file .rackshrc which is loaded from two places during startup: user's home dir and application directory (in this order). You can put any ruby code in it, but it's purpose is to setup your session, ie. setting headers which will be used for all $rack.get/post/... requests.

For example to set user agent to Firefox and re-migrate db if loaded environment is test put following in .rackshrc:

# .rackshrc

$rack.header "User-Agent", "Firefox"
DataMapper.auto_migrate! if $rack.env == "test"

You can also make requests in config file:

# .rackshrc

$rack.put "/signin", :login => "jola", :password => "misiacz"

This will ensure you are always logged in when you start racksh :)

Full documentation and sources are on github, gems for all versions on gemcutter.org. Enjoy!

View Comments