[LRUG] Rspec sees different output from Rails application

John Winters john at sinodun.org.uk
Sat Jul 16 05:31:26 PDT 2011


I'm trying out Rspec with Rails 3.1pre to see whether I can use it for
testing, using a book called "Ruby on Rails 3 Tutorial" for guidance.

I seem to have got it installed and running but I'm getting odd results.

The first suggested test is simply to ensure a page can be retrieved, and
that works fine.

The second suggest test is to check its title is correct.  The spec for
this reads:

  describe "GET 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success
    end

    it "should have the right title" do
      get 'about'
      response.should have_selector("title",
        :content => "Ruby on Rails Tutorial Sample App | About")
    end
  end

and this second test fails.  The trouble is, the complaint message from
rspec shows only part of the output it's checking (and not the relevant
bit), but the part it shows doesn't match what you get when you access the
page with a normal web browser.

With a normal web browser, the source of the retrieved page starts like
this:

<!DOCTYPE html>
<html>
  <head>
    <title>Ruby on Rails Tutorial Sample App | About</title>
  </head>
  ...

and yet the complaint from Rspec looks like this:

  3) PagesController GET 'about' should have the right title
     Failure/Error: response.should have_selector("title",
       expected following output to contain a <title>Ruby on Rails
Tutorial Sample App | About</title> tag:
       <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
     # ./spec/controllers/pages_controller_spec.rb:39:in `block (3 levels)
in <top (required)>'

Note the completely different start to the page.  I've searched the whole
application source and nowhere can I find anything which would generate
this output.

Anyone any idea where Rspec is getting this from?

TIA,
John



More information about the Chat mailing list