iammyr
iammyr

Reputation: 271

RSpec Failure: Page should have title

I'm trying to run very simple RSpec tests following the Rails Tutorial and they surprisingly fail when they're not supposed to.

Fiona somewhere else suggested to move the file application.html.erb in app/views/layouts but mine is already there.

Zetetic suggested to add "render views" but I did and nothing changed.

The versions of the sw i'm using are as follows:

I get the following failure message:

$>rspec spec/requests/pages_spec.rb
F

Failures:

1) Pages Home page should have the h1 'Sample App'
 Failure/Error: page.should have_selector('h1', :text => 'Sample App')
   expected #has_selector?("h1", {:text=>"Sample App"}) to return true, got false
 # ./spec/requests/pages_spec.rb:9:in `block (3 levels) in <top (required)>'

Deprecation Warnings:

Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /home/iammyr/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'.

Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/iammyr/railsgirls-app/projects/galway_june2014/spec/requests/pages_spec.rb:9:in `block (3 levels) in <top (required)>'.


Failed examples:

rspec ./spec/requests/pages_spec.rb:7 # Pages Home page should have the h1 'Sample App'

One difference from the tutorial is that rather than generating those static pages with "rails generate static_pages" I did run "rails generate controller pages home help" but that shouldn't have to do with the rspec result, imho.

The files look as follow.
pages_spec.rb

require 'spec_helper'

describe "Pages" do
  render_views
  describe "Home page" do
    it "should have the h1 'Sample App'" do
      visit '/pages/home'
      page.should have_selector('h1', :text => 'Sample App')
    end
  end
end

home.html.erb

<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
   This is the home page.
</p>

Thanks a million to whomever would like to help me! thank you! ;)

Upvotes: 0

Views: 555

Answers (2)

dre-hh
dre-hh

Reputation: 8044

You should first move the spec from requests to features folder see changes in capybara

I guess it will fix it (remember having a similar one) If not debug it with pry and in Firefox with selenium driver

 #Gemfile
  gem 'pry-rails'

  #spec
  it "should have the h1 'Sample App'", :js => true do
  visit '/pages/home'
  binding.pry
  page.should have_selector('h1', :text => 'Sample App')
end

Firefox should start and render the page Then in debug mode check the capybara selector

   page.all(:css, 'h1')

Upvotes: 1

Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Perhaps you didn't define capybara or another driver. Then you try content instead of text:

page.should have_selector('h1', :content => 'Sample App')

Upvotes: 0

Related Questions