0

I've google and read stackoverflow about 4 hours, but cannot understand, why test similar to rails tutorial fail.

Test is very simple:


# encoding: utf-8

require 'spec_helper'

describe "StaticPages" do
  subject { page }

  describe "Contacts page" do
    before { visit contacts_path }

    it { should have_selector(:title, text: "|") }
  end
end

So, I add save_and_open_page to see, what's wrong with my Contacts page, but it's looks good. Title tag is present and contain "|".

I cannot understand, what's wrong. I've:

  • tryed get instead visit;
  • response instead page;
  • check something other permanently in body (body.should have_selector(:h1)).

Also I tryed to understand, how to improve rspec output to more infomative. At now I see:

Failure/Error: it { should have_selector(:title, text: "|") }
       expected id :title with text "|" to return something
Aleksey Bakin
  • 1,506
  • 13
  • 27
  • Asked and answered on http://stackoverflow.com/questions/5129423/capybara-how-to-test-the-title-of-a-page – David Chelimsky May 01 '12 at 14:34
  • 1
    I'm not asked how. I asked why have_selector not work. And I found, that if I use string "title" instead symbol :title - my sample works fine. – Aleksey Bakin May 01 '12 at 14:49

1 Answers1

1

As I know have_selector is a Capybara matcher and according to the tutorial as a first argument you can use an html element name in quotes or a xpath notation, but not a symbol.

Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72