Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while running bundle exec rspec spec/requests/static_pages_spec.rb in Rails

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'
like image 215
arun thakur Avatar asked Feb 22 '12 06:02

arun thakur


1 Answers

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.

like image 61
Verse Versari Avatar answered Oct 05 '22 22:10

Verse Versari