2012-01-25

RubyInline version 3.11.1 has been released!

0 comments

Inline allows you to write foreign code within your ruby code. It automatically determines if the code in question has changed and builds it only when necessary. The extensions are then automatically loaded into the class/module that defines it.

You can even write extra builders that will allow you to write inlined code in any language. Use Inline::C as a template and look at Module#inline for the required API.

Changes:

3.11.1 / 2012-01-25

minitest version 2.11.0 has been released!

0 comments

minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.

"I had a class with Jim Weirich on testing last week and we were
 allowed to choose our testing frameworks. Kirk Haines and I were
 paired up and we cracked open the code for a few test
 frameworks...

 I MUST say that mintiest is *very* readable / understandable
 compared to the 'other two' options we looked at. Nicely done and
 thank you for helping us keep our mental sanity."

-- Wayne E. Seguin

minitest/unit is a small and incredibly fast unit testing framework. It provides a rich set of assertions to make your tests clean and readable.

minitest/spec is a functionally complete spec engine. It hooks onto minitest/unit and seamlessly bridges test assertions over to spec expectations.

minitest/benchmark is an awesome way to assert the performance of your algorithms in a repeatable manner. Now you can assert that your newb co-worker doesn't replace your linear algorithm with an exponential one!

minitest/mock by Steven Baker, is a beautifully tiny mock object framework.

minitest/pride shows pride in testing and adds coloring to your test output. I guess it is an example of how to write IO pipes too. :P

minitest/unit is meant to have a clean implementation for language implementors that need a minimal set of methods to bootstrap a working test suite. For example, there is no magic involved for test-case discovery.

"Again, I can't praise enough the idea of a testing/specing
 framework that I can actually read in full in one sitting!"

-- Piotr Szotkowski

Changes:

2.11.0 / 2012-01-25

2012-01-23

hoe version 2.13.0 has been released!

0 comments

Hoe is a rake/rubygems helper for project Rakefiles. It helps you manage and maintain, and release your project and includes a dynamic plug-in system allowing for easy extensibility. Hoe ships with plug-ins for all your usual project tasks including rdoc generation, testing, packaging, and deployment.

See class rdoc for help. Hint: ri Hoe or any of the plugins listed below.

For extra goodness, see: http://seattlerb.rubyforge.org/hoe/Hoe.pdf

Changes:

2.13.0 / 2012-01-23

  • 3 minor enhancements:

    • Added :dcov task so you can easily check documentation coverage.
    • Added Rake monkeypatch so that Task#clear will clear comments. (github)
    • Added coverage sorting and added tmp/isolate to rcov flags
  • 2 bug fixes:

    • Quelled 1.9.3 warning. (erikh)
    • rcov plugin should invoke isolate task if isolate plugin is being used.
  • https://github.com/seattlerb/hoe

2012-01-18

Enumerable#uniq_by

1 comments

Random code sitting around waiting to be blogged...

module Enumerable
  def uniq_by
    r, s = [], {}
    each do |e|
      v = yield(e)
      next if s[v]
      r << e
      s[v] = true
    end
    r
  end
end

2012-01-17

minitest version 2.10.1 has been released!

0 comments

minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.

"I had a class with Jim Weirich on testing last week and we were
 allowed to choose our testing frameworks. Kirk Haines and I were
 paired up and we cracked open the code for a few test
 frameworks...

 I MUST say that mintiest is *very* readable / understandable
 compared to the 'other two' options we looked at. Nicely done and
 thank you for helping us keep our mental sanity."

-- Wayne E. Seguin

minitest/unit is a small and incredibly fast unit testing framework. It provides a rich set of assertions to make your tests clean and readable.

minitest/spec is a functionally complete spec engine. It hooks onto minitest/unit and seamlessly bridges test assertions over to spec expectations.

minitest/benchmark is an awesome way to assert the performance of your algorithms in a repeatable manner. Now you can assert that your newb co-worker doesn't replace your linear algorithm with an exponential one!

minitest/mock by Steven Baker, is a beautifully tiny mock object framework.

minitest/pride shows pride in testing and adds coloring to your test output. I guess it is an example of how to write IO pipes too. :P

minitest/unit is meant to have a clean implementation for language implementors that need a minimal set of methods to bootstrap a working test suite. For example, there is no magic involved for test-case discovery.

"Again, I can't praise enough the idea of a testing/specing
 framework that I can actually read in full in one sitting!"

-- Piotr Szotkowski

Changes:

2.10.1 / 2012-01-17

2012-01-16

graph version 2.4.0 has been released!

0 comments

Graph is a type of hash that outputs in graphviz's dot format. It comes with a command-line interface that is easily pluggable.

It ships with plugins to graph dependencies and status of installed rubygems, rake tasks, homebrew ports, mac ports, and freebsd ports, coloring leaf nodes blue, outdated nodes red, and outdated leaf nodes purple (red+blue).

OSX quick tip:

% sudo gem install graph
% sudo brew install graphviz
% gem unpack graph
% cd graph*
% rake gallery
% open gallery/*.png

Changes:

2.4.0 / 2012-01-16

  • 4 minor enhancements:

    • Renamed arrownone to nonearrow.
    • Renamed box to box_arrow (because the box shape was already defined).
    • Renamed diamond to diamond_arrow (because the diamond shape was already defined).
    • Allow rake analyzer to read from stdin, making it more usable for isolated systems.
  • 1 bug fix:

    • Fixed 1.9.3 warnings.
  • https://github.com/seattlerb/graph

2012-01-11

rdoc_osx_dictionary version 2.0.1 has been released!

0 comments

rdoc via Apple's Dictionary.app. Automatically builds and installs an Apple Dictionary with all rdoc nicely formatted.

Inspired by: http://priithaamer.com/blog/ruby-on-rails-dictionary-for-macosx

Changes:

2.0.1 / 2012-01-11

assert_nothing_tested

1 comments

Check this rails test out:

def test_remove_column_with_multi_column_index
  ActiveRecord::Base.connection.create_table(:hats) do |table|
    table.column :hat_name, :string, :limit => 100
    table.column :hat_size, :integer
    table.column :hat_style, :string, :limit => 100
  end
  ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true

  assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") }
ensure
  ActiveRecord::Base.connection.drop_table(:hats)
end

The file this test came from is chock full of tests written just like this one. What exactly is it testing? The test name implies that it is testing removecolumn when there is a multi-column index. Does the test ensure that removecolumn

Better yet, here's how to make it pass:

def remove_column(*)
end

Tada! No exceptions raised!

This is exactly why minitest doesn't have assert_nothing_raised. You wind up with file after file of useless junk tests.

tenderlove recently converted the rails tests from test/unit to minitest and had to get these tests working since they were all calling assert_nothing_raised. Here is his implementation:

def assert_nothing_raised(*)
  yield
end

Certainly easier to do this than to go through all the tests and remove the call (never mind adding real assertions to make sure something is actually being tested).

Seattle.rb 10 Year Anniversary!

0 comments

Seattle.rb Logo

I'm incredibly proud to announce Seattle.rb's 10 Year anniversary party!

Seattle's world-famous Ruby Brigade is 10 years old in February! Come celebrate with us at Substantial with drink, food, music and more goodies TBA. Plus, you'll get a snazzy t-shirt from PeepCode.

Space is limited, so register now!

2012-01-09

Simulating .PHONY in Rake

0 comments

Makefiles have a construct called .PHONY. You declare your task a non-filesystem based task like so:

.PHONY: mytask

and then make knows that it shouldn't force your task to run just because "mytask" doesn't exist in the filesystem.

Rake doesn't bother with such nonsense. It doesn't assume that all tasks map to the filesystem. That's great. What's not great is that it does assume that if your file task has non-file-task dependencies, that they should probably rebuild even if those tasks have run. The problem code looks like:

def out_of_date?(stamp) # on FileTask
  @prerequisites.any? { |n| application[n, @scope].timestamp > stamp}
end

In my case, I was trying to intelligently hook up some generated files to isolate so they could access their compiler:

file "lib/ruby18_parser.rb" => :isolate
file "lib/ruby19_parser.rb" => :isolate

The problem is that :isolate is a regular task, and they calculate their dependencies like so:

def timestamp # on Task
  prerequisite_tasks.collect { |pre| pre.timestamp }.max || Time.now
end

:isolate doesn't have any prerequisites, so it falls back to Time.now. This is wrong in my case, as it forces my parser files to regenerate every time.

What I need is a prerequisite that fixes this with a timestamp earlier than my files:

def (task(:phony)).timestamp # omg I love/hate this grammar construct
  Time.at 0
end

task :isolate => :phony

and everything is happy.

I'm going to officially ask that :phony gets added to rake so others can be spared this pain.