Inc1982
Inc1982

Reputation: 1975

How to get Capybara matchers to work?

I'm searching for a CSS class. My HAML is:

.friends
    = image_tag 'news-face.png'
    %p 15

My test is:

it "Should show friends count on popular feed" do
  visit '/'
  page.should have_css('.friends')
end

I'm getting an error:

Failure/Error: page.should have_css('.friends')
   expected css ".friends" to return something

I've tried should, should_not, & have_selector and can't figure out what's wrong.

Upvotes: 1

Views: 694

Answers (2)

Sławosz
Sławosz

Reputation: 11687

Maybe you would use has_css selector.

Upvotes: 0

Michał Czapko
Michał Czapko

Reputation: 1938

It seems that you don't have such element on your page. The best way to figure it out by yourself is to install:

# in your Gemfile
gem 'launchy'

and then just use:

# in Cucumber step
it "Should show friends count on popular feed" do
  visit '/'
  save_and_open_page
  page.should have_css('.friends')
end 

With this gem and command you will be able to render this page from your test.

Upvotes: 3

Related Questions