5

I am following this article where I can written this code in this ruby file below and home page does have sample app, but it still says static pages home page should have content 'Sample App' when I run bundle exec rspec spec/requests/static_pages_spec.rb

spec/requests/static_pages_spec file code:

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      page.should have_content('Sample App')
    end
  end
end

home.html.erb

<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application.
</p>

Below is my gem file for this app. please advise. thanks for your help.

source 'https://rubygems.org'

gem 'rails', '3.2.1'
gem 'sqlite3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'rspec-rails', '2.6.0'

end

group :test do
gem 'webrat', '0.7.1'
gem 'capybara', '1.0.0.beta1'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.3'
  gem 'coffee-rails', '3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '1.0.3'
end

gem 'jquery-rails', '2.0.0'


group :production do
gem 'pg', '0.12.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
7
  • Can you post the output from the rspec run? Commented Feb 22, 2012 at 6:29
  • Try changing page.should have_content('Sample App') to page.should have_content("Sample App") Commented Feb 22, 2012 at 6:33
  • 1
    You can puts page.content in the spec to check what you're getting instead of the page you're expecting. That should give you an idea what's wrong. If that doesn't help show us your routes file, the problem may be there. Commented Feb 22, 2012 at 7:35
  • Posting Output in 2 comments:C:\rails\Sample_app>bundle exec rspec spec/requests/static_pages_spec.rb You must use ANSICON 1.31 or later (adoxa.110mb.com/ansicon) to use colo ur on Windows DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directlyin #<Class:0x3599a18> instead. (called from <top (required)> at C:/rails/Sample_app/spec/requests/static_pages_spec.rb:3) F Failures: Commented Feb 23, 2012 at 2:59
  • Adding Remaining output: 1) Static pages Home page should have the content 'Sample App' Failure/Error: page.should have_content('Sample App') Capybara::ElementNotFound: Unable to find xpath "/html" # (eval):2:in text' # ./spec/requests/static_pages_spec.rb:9:in block (3 levels) in <top (requ ired)>' Finished in 4.49 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should hav e the content 'Sample App' Commented Feb 23, 2012 at 3:02

3 Answers 3

6

In the output from your failed rspec test do you have the line FATAL: database "sample_app_test" does not exist many lines above the error Failed examples: rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content 'Ruby on Rails'? If so the following steps worked for me:

Open the sample_app/config.database.yml file in a text editor, and under test, change the database to the actual name of the postgres db you using, save the .yml file, and re-run the rspec test.

Sign up to request clarification or add additional context in comments.

Comments

0

I think that you need to require capybara manualy in the spec_helper.rb. That's what I normally do :)

Comments

0

I think this is a conflict with webrat. Remove it from you gem file.

#gem 'webrat', '0.7.1'
gem 'capybara', '1.0.0.beta1'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.