Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

By Peter Cooper / July 9, 2006

You can test your controllers, your models, and, well, most of your application, but till now there hasn’t been a way to explicitly test your Rails application’s helpers. Now there’s a solution.. the helper_test plugin (with source and instructions). Read More

By Peter Cooper / July 9, 2006

Assert Select

assert_select is a plugin by Assaf Arkin that allows you to use CSS selectors in your functional tests to check that certain HTML elements match your assertions. On the surface, this isn’t too far removed from using why’s Hpricot to do assertions on HTML, but in reality having the full power of CSS selectors available changes everything (Update! Hpricot has XPath and CSS addressing too!). Some examples:

# Form includes four input fields
assert_select “form input”, 4

# Page does not have any forms in it.
assert_select “form”, false, “Page must contain no forms”

def test_login_form_has_all_fields
get :login
assert_select “form[action=http://myapp/login] input” do |inputs|
assert_equal 3, inputs.size
assert_select inputs[0], “input[type=name][name=username]”
assert_select inputs[1], “input[type=password][name=password]”
assert_select inputs[2], “input[type=submit][value=Login]”
end
end

More examples here. Read More

By Peter Cooper / July 8, 2006

Spotlightruby

Arcadian Visions have released a plugin for Mac OS X’s Spotlight that lets you quickly search your Ruby source code. Once indexed, you can search by module, class, method, general contents, or code comments. (Found via Have GNU, Will Travel)

(Added: Tread with caution! It seems one user is having problems installing this on their Intel x86 powered Mac. See comments.) Read More

By Peter Cooper / July 8, 2006

New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast.

A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. The screencast series includes 12 lessons over more than 15 hours! Get the best “over the shoulder” experience of following what a top Rails 3 developer does when building an app today. Click here to learn more.

Please note that this post is over four years old – it’s from 2006! As such, these tips were relevant to Rails 1.2 and this content is woefully out of date. Read More

By Peter Cooper / July 7, 2006

Textmatecheatsheet

Mike Clark has produced a single page PDF cheat sheet of about fifty TextMate keyboard shortcuts to speed up your Ruby development. As a long time TextMate user who never uses the shortcuts, this is very useful. Great work, Mike! Read More

By Peter Cooper / July 7, 2006

Comatose

RadiantCMS has been getting a lot of press in the Rails world lately as the first, interesting Rails powered CMS (it’s open source too), but now comes Comatose, a ‘micro CMS’ that works as a Rails plugin, allowing you to easy integrate it with your own application. As Matt McCray, the developer, says:

Lately, I’ve had a recurring issue arise on my projects: They generally require a few content pages. Nothing fancy. Just a privacy policy, terms & conditions, an FAQ, that kind of thing.

I don’t really want to make these static HTML pages. They are likely to change at some point, especially the FAQ. Read More

By Peter Cooper / July 7, 2006

Shattered

It’s still pretty new, but Shattered Ruby looks interesting. It’s a Ruby game development framework that runs on Mac OS X, Linux, and Windows, and uses the Ogre3D libraries (which support OpenGL and DirectX) for graphics. There’s even a blog. It has some pretty neat event handling:

key :pressed => [:a, :b], :action => :do_something
def do_something
puts "will be called when a or b is pressed"
end

I want to find some time to play with this.. Read More

By Peter Cooper / July 6, 2006

MeantimeFilter is an interesting new plugin for Rails by Roman Le Negrate. It’s a little like around_filter, but rather than using a class with ‘before’ and ‘after’ methods, it uses a single method (like the other types of filter) and passes in the method to wrap ‘around’ as a code block. You can then yield to this or pass it into anything you like. An example: Read More

class PostsController < ApplicationController
before_filter :authenticate
meantime_filter :scope_posts_to_user

# Displays the posts of the logged in user.
def show
@posts = Post.find(:all)
end

def create
# …
@post = Post.create(params[:post]) # Automatically associated to @user
# …

By Peter Cooper / July 6, 2006

Paul Battley has developed a Ruby to JavaScript converter. I’m trying to think what this is useful for, but this is an amazing results for just a few hours’ work.

Found via _why Read More

By Peter Cooper / July 5, 2006

Hpricot

Ruby legend whytheluckystuff has developed a new HTML parser called Hpricot. It’s easy to install and use and parses HTML in a liberal fashion. It does, however, require a compiler to install (as it’s written in C), so should be okay on Linux and Mac OS X, though not necessarily on Windows (yet).

Here’s some demo code:

require ‘hpricot’
doc = Hpricot.parse("index.html")
(doc/:p/:a).each do |link|
p link.attributes
end

This is a good alternative to RubyfulSoup, if you’re finding RubyfulSoup too slow (though RubyfulSoup is certainly worth a try!) Read More

By Peter Cooper / July 3, 2006

DevX.com has published a great article by Mark Watson entitled “Ruby Programming Language Enables Concise Network Programming“. Mark gives quick rationales and examples for:

  • a simple (not an exaggeration) Web server from scratch in 12 lines of code
  • a basic WEBrick server
  • a simple REST server with pure sockety madness
  • a quick and simple XML-RPC Web service
  • a slightly more complex SOAP Web server

A great introduction to some of the networking power at your fingertips with Ruby. Read More

By Peter Cooper / July 3, 2006

Flickr.rb is an ‘insanely easy’ Ruby library to interface with the world’s most popular photo-sharing service, Flickr.

Here’s some example code: Read More

require ‘flickr’

# basics
flickr = Flickr.new # create a flickr client
flickr.login(email, password) # log in for actions that require it
flickr.users # get all users currently online
flickr.photos # get the 100 most recent public photos
flickr.tag(‘red’) # search for photos tagged with ‘red’
flickr.groups # get all active public groups

# working with users
user = flickr.users(‘sco’) # lookup a user by username
user = flickr.users(‘sco@scottraymond.net’) # or email
user.name # get the user’s real name
user.location # and location
user.photos # grab their collection of Photo objects…

By Peter Cooper / July 2, 2006

TeensyMud is a simple MUD (multi-user dungeon – a bit like a text adventure) server written in Ruby. It’s not particularly complex, but it has a great structure and there’s a lot to learn from looking at the code (patterns are well used). It’s also ripe for extending and for building, perhaps, a proper game or full multi-user environment on. Read More

By Peter Cooper / July 1, 2006

Mauricio Fernandez’s ever-mindblowing Eigenclass presents a great article about how to easily implement a plugin system for any Ruby application. Ruby’s reflection and OO features make it a cinch. Read More

By Peter Cooper / July 1, 2006

Paul Cantrell has created a cool guide, with demonstrations, of the powers, quirks, and surprises of closures, blocks, and procs in Ruby. He writes:

A closure is a block of code which meets three criteria:

* It can be passed around as a value and

* executed on demand by anyone who has that value, at which time

* it can refer to variables from the context in which it was created (i.e. it is closed with respect to variable access).

Closures are a mainstay of functional languages, but are present in many other languages as well (e.g. Java’s anonymous inner classes). Read More

Recently Popular Posts