O'Reilly logo

Instant RSpec Test-Driven Development How-to by Charles Feduke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making specs more concise (Intermediate)

So far, we've written specifications that work in the spirit of unit testing, but we're not yet taking advantage of any of the important features of RSpec to make writing tests more fluid. The specs illustrated so far closely resemble unit testing patterns and have multiple assertions in each spec.

How to do it...

  1. Refactor our specs in spec/lib/location_spec.rb to make them more concise:
    require "spec_helper"
    describe Location do
      describe "#initialize" do
        subject { Location.new(:latitude => 38.911268,
                               :longitude => -77.444243) }
        its (:latitude) { should == 38.911268 }
        its (:longitude) { should == -77.444243 }
      end
    end
  2. While running the spec, you see a clean output because we've separated multiple assertions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required