Infinity Test: Flexible Continuous Testing with Multiple Ruby Implementations »

Created at: 29.09.2010 23:00, source: Ruby Inside, tagged: Miscellaneous Tools

Infinity Test is a new library by Tomas D'Stefano that pitches itself as a "flexible alternative to Autotest." If you want your project's tests (both RSpec or Test::Unit are supported) to be automatically run when changes are made, this is a great place to start.

The big benefit of Infinity Test is the support for testing across multiple Ruby implementations, powered by RVM (a candidate for Ruby project of the year, if ever there were one). For example, if you have some Test::Unit tests that you want to be run on Ruby 1.8.7, JRuby, Ruby Enterprise Edition, and Ruby 1.9.2, you could run:

infinity_test --test-unit --rubies=1.8.7,jruby,ree,1.9.2

There's also a configuration file system with its own DSL to build more complex automated testing systems with customized notification systems and callbacks.

[ad] Ruby Inside's newest sponsor is Recurly, a recurring billing service. They promise "subscription billing in 3 easy steps" and you can start a free trial right now. Their API is Ruby friendly and on GitHub!


more »

The 3 Step Guide to Slick Local Documentation for all your Ruby Gems »

Created at: 14.09.2010 05:58, source: Ruby Inside, tagged: Tools

A couple of weeks ago, I wrote about RubyDoc.info, a "good looking, up-to-date Ruby documentation" site powered by YARD. Well, as of YARD 0.6 you can get the same greatness that RubyDoc.info provides applied to your local machine's collection of gems in just a few steps. Try it out - you won't regret it.

Step 1: Install YARD. Install the yard gem with sudo gem install yard or similar.

Step 2: Run the YARD server. Run yard server --gems. Take note of the hostname and port given in the output.

Step 3: Get browsing. Visit http://0.0.0.0:8808/, where the IP address and port should be replaced with those provided by the YARD server. This URL should work for most of you though.

How does it look? Here's the overall view of all installed gems:

And here's a specific gem's documentation:

There's a lot more to YARD than merely serving up documentation - it's primarily a tool for generating it from both RDoc and YARD-enhanced RDoc formats. Learn more at Loren Segal's YARD 0.6.0 release post or from the GitHub project.


more »

Pusher: WebSocket-powered Realtime Browser Push Service for Rubyists »

Created at: 08.05.2010 02:05, source: Ruby Inside, tagged: Tools

Pusher is a new Web service from New Bamboo that makes it easy to push data to users of your web applications "live", outside of the request response cycle. They've embraced Web Sockets technology and built a REST API to which you can post events. Its flexible channels are based on a publish/subscribe model and you can send events as JSON which communicate with all connected browsers.

Websockets are part of the specification for HTML5, and are essentially long-running native TCP connections in the browser. These allow a client to establish a connection to a server, and have immediate feedback when there are events they need to be notified of. Websockets make your applications more dynamic, and break them out of the traditional stateless request-response cycle. Your applications can therefore rely on maintained state in the browser which will be kept fresh with messages from your server.

Pusher makes adding Websockets to your application a quick and easy process. Pusher provides a simple Ruby gem) for interacting with its REST API, which includes authentication. There's lots of documentation on the site, along with some more in-depth tutorials. Pusher also provides simple tools for debugging the socket connections to your application. Their event-based abstraction is handled in a Javascript library which also includes support for a flash fallback option.

Or.. try the DIY approach

The tools for creating a similar systems yourself are widely available, and it's pretty easy. Ilya Grigorik recently put together a walkthrough of creating a simple Web Sockets server in Ruby using EventMachine. There are plenty of other open source solutions for message pushing generally like Juggernaut and Cramp.

In many cases running your own standalone socket server gives you a lot of flexibility for more bespoke deployments. However, maintaining these socket servers, debugging the various issues that come up, and keeping up with the specs is not something everyone wants to be doing. Given the popularity of utility-based hosting providers such as Heroku, Pusher is an interesting option for a de-coupled socket service you can use to keep your infrastructure lean.

Disclaimer: New Bamboo is a sponsor of Ruby Inside for their Panda service. I only noticed this had happened after working on this post (!) but a disclaimer is required nonetheless ;-)


more »

3 New Date and Time Libraries for Rubyists »

Created at: 05.05.2010 17:30, source: Ruby Inside, tagged: Compilation Posts Cool Ruby Tricks Tools

In the UK there's a cliché that goes: "You wait hours for a bus, and then three come along at once!" So it went with these three Ruby date and time libraries. They all made an appearance on RubyFlow last week and are all useful in their own ways, depending on how you're working with dates and times.

ice_cube - Fast querying and expansion of event recurrence rules

ice_cube is a library by John Crepezzi that provides "fast querying and expansion of recurrence rules in Ruby." What this means is that you can create schedules powered by date recurrence rules that can be quite complex (e.g. every 4 years on a Tuesday in the first week of November). Rules like these are defined by chaining methods together, rather than using natural language.

To install:

gem install ice_cube

To use:

require 'ice_cube'
rule = IceCube::Rule.yearly(4).month_of_year(:november).day(:tuesday).day_of_month(2, 3, 4, 5, 6, 7, 8)
schedule = IceCube::Schedule.new(Time.now)
schedule.add_recurrence_rule rule
schedule.first(3)
# => [Tue Nov 02 05:04:38 +0000 2010, Tue Nov 04 05:04:38 +0000 2014, Tue Nov 06 05:04:38 +0000 2018]

ice_cube also supports exporting rules into iCal and YAML formats as well as a natural language equivalent.

John has put together a PDF presentation that shows off more usage, and there are some simple examples on the official site too.

tickle - A natural language parser for recurring events

tickle is a natural language parser for recurring events by Joshua Lippiner that stands in contrast to ice_cube's method driven approach. It depends on the popular chronic natural language date parser and appears (through my experience) to be for Ruby 1.9+ only.

tickle lets you throw it things like every 4 days starting next saturday, every other week, the tenth of the month and similar (there are a lot of examples on tickle's GitHub page). You pass these to the Tickle.parse method and you get the next occurrence of the rule.

To install:

gem install tickle

To use:

require 'tickle'
Tickle.parse('every 4 days starting next saturday')
# => 2010-05-01 12:00:00 +0000

tickle isn't particularly mature yet and it only makes it easy to get the next occurrence of your rule, but the developer suggests that once an event has occurred, you automatically run Tickle again to get the next date. In this way, it seems tickle is well suited for situations where only the next occurrence needs to be stored and the rule can be kept in a separate database column or similar.

business_time - Time and date offsets based on "business time/hours"

business_time is a new library that works with the concept of "business time" or "business hours." Rather than just letting you perform operations on dates by absolute numbers of days or hours, you can now work with business days and hours of your own definition. business_time depends heavily on Active Support.

To install:

gem install business_time

Note: business_time depends on Active Support (gem: activesupport)

To use:

require 'active_support'
require 'business_time'
# Examples "from now"
4.business_hours.from_now
5.business_days.from_now
# Using user supplied dates
my_birthday = Date.parse("August 4th, 2010")
10.business_days.before(my_birthday)
# Add a day to not count as a business day
BusinessTime::Config.holidays << my_birthday
# Overlapping days are OK
6.business_hours.after(Time.parse("August 3rd, 3:00pm"))


more »

Visually Inspect Ruby Object Models with DrX »

Created at: 29.04.2010 01:35, source: Ruby Inside, tagged: Linux Specific OS X Specific Tools

When you want to inspect your objects in Ruby, Object#inspect, p, or awesome_print are all valuable. You're stuck with plain-text, though, and primarily designed to look at object data rather than object models. If you want to drill down into parent classes, see object and class relationships, etc, then, check out DrX, a visual object inspector for Ruby!

DrX bills itself as a "small object inspector", but its key features are that it shows results visually (in a GUI interface) and that it focuses on showing the object model behind your objects, rather than the data contained within. A visual example of a DrX session should give you the idea:

Usage

Once DrX is installed (more on that in the next section), you just require 'drx' it into your app (or even within irb) and then use the Object#see method to get DrX into action:

require 'drx'
123.see

Even this rudimentary example will bring up an interesting graph. The DrX author does, however, provide a more interesting example to show off DrX's introspective features:

s = "wizard of oz"
def s.strong
"<strong>" + self + "!</strong>"
end
s.see

Installation and Prerequisites

Depending on your setup, DrX might take some serious work to get going. If you're running Linux and are heavy on your development experimentation, you might have everything ready to go. Just try gem install drx and see if the above examples work in irb.

Failing that, DrX uses Tk for its GUI work in order to be cross-platform and also requires GraphViz to be present. Install these with your package manager of choice and ensure that your Ruby installation has the Tk bindings installed (again, easier said than done).

On OS X 10.6 (Snow Leopard) I discovered that the stock Ruby installation does not include the Tk bindings, even though Tk is present otherwise. Rather than mess it up, I relied on the always-wonderful RVM and installed Ruby 1.9.2-preview1 (rvm install ruby-1.9.2-preview1). With this, Tk worked "out of the box" and gem install rbx was OK. For the Graphviz dependency, sudo port install graphviz did the trick and also "just worked." If you're one of the anti-Macports crowd, though, you might need to find a different approach.


more »