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”
assert_select “form[action=http://myapp/login] input” do |inputs|
assert_equal 3, inputs.size
assert_select inputs, “input[type=name][name=username]”
assert_select inputs, “input[type=password][name=password]”
assert_select inputs, “input[type=submit][value=Login]”
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
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
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
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:
I don’t really want to make these static HTML pages. They are likely to change at some point, especially the FAQ. Read More
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
puts "will be called when a or b is pressed"
I want to find some time to play with this.. Read More
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
# Displays the posts of the logged in user.
@posts = Post.find(:all)
@post = Post.create(params[:post]) # Automatically associated to @user
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:
doc = Hpricot.parse("index.html")
(doc/:p/:a).each do |link|
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
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
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(‘firstname.lastname@example.org’) # or email
user.name # get the user’s real name
user.location # and location
user.photos # grab their collection of Photo objects…
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
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
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