Many developers are convinced that their language, tool or library is the best. They think that C is better than Pascal, Python is better Ruby, and Git is much better than SVN. Among the editors, some prefer VIM over Emacs, while others only like Textmate or JEdit. The preference for certain languages, tools and frameworks can be very subjective, some like this tool, some like that, while others prefer something completely different. Often you like the tool you are used to, because you know how to use it well. Luckily we have the choice between various tools and frameworks, which are often equally powerful. Python is very similar to Ruby, and VIM is just as uncomfortable (or powerful) as Emacs. RSpec and the classic Test::Unit are another good example, both are equally powerful and more or less isomorphic, i.e. similar in form, function and relations.
Test::Unit | RSpec | |
Existence | assert assigns(:object) | assigns(:object).should be assigns(:object).should_not == nil |
Matching | assert_match object | object.should match(expected) |
Equality | assert_equal object.text,text | object.text.should eq(text) |
Validity | assert object.valid? assert !object.valid? |
object.should be_valid object.should_not be_valid |
Collections | assert collection.include?(object) assert !collection.include?(object) assert_equal collection.count, count |
collection.should include(object) collection.should_not include(object) collection.should have(count).items |
HTTP Response | assert_response :success assert_response :redirect |
response.should be_success response.should be_redirect |
Redirect | assert_redirected_to posts_url | response.should redirect_to(posts_url) |
Templates | assert_template “posts/index” | response.should render_template(“posts/index”) |
Selectors | assert_select “h1”, :text => /Headline/ assert_select “div[id=main]” |
response.should have_selector(“h1”, /Headline/) response.should have_tag(‘div#main’) |
(The have_tag or have_selector methods are not part of RSpec and are defined in Webrat and/or Capybara.)