This post originated from an RSS feed registered with Ruby Buzz
by Vincent Woo.
Original Post: TIL: RSpec Request Specs
Feed Title: Undefined Range
Feed URL: http://www.undefinedrange.com/categories/ruby-on-rails.rss
Feed Description: Interesting things I experience with Ruby on Rails.
The rspec-rails gem gives us Request Specs, the ability to create default Test::Unit Rails integration style tests. Just add files into #{Rails.root}/spec/requests.
require 'spec_helper'
describe "Redirect Middleware" do
it "should redirect based on certain conditions"
get '/x'
get '/y'
follow_redirect!
end
end
Rails Guide has more information on what you can do with request specs like follow_redirect! or host!
Request specs was perfect for testing a simple middleware I wrote. It was high level specs that require multiple page requests to trigger and applicable to many different controllers. Plus, it didn't need the browser compatibility testing of the popular Cucumber + Webrat + Selenium type combos. Really happy with less dependencies = smaller API and complexity = less setup, faster test runs, reduced brittleness.
I'm probably in the minority in that thinking though. For instance, the recently minted RSpec book has a large section dedicated to Cucumber but AFAIK doesn't reference request specs at all (other than mentioning the "rake spec:requests" task in passing). But request specs are a part of the RSpec gems and I hope it is here to stay.