Rspec Integration test guide for Ruby on Rails 4

Lets assume we must have admin and pages must be created by only admin. Admin must have authentication pages as well.
Pages for visitors -> home,about,contact
pages for admin -> login,register,page_management

1. rails new shop
2. add to Gemfile followings:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'rspec-rails', '~> 3.0'
  gem 'rspec'
  gem 'rspec-mocks'
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'faker'
  gem 'launchy'
  gem 'selenium-webdriver'
  gem 'database_cleaner'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
  gem 'spring-commands-rspec'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end


3.
rails generate rspec:install
This adds the following files which are used for configuration:
  • .rspec
  • spec/spec_helper.rb
  • spec/rails_helper.rb
Check the comments in each file for more information.
Use the rspec command to run your specs:
bundle exec rspec
 
4. Create folder spec/features/pages.
Create file spec/features/pages/index_page_spec.rb

 feature 'Index page' do
 scenario 'Visit the Index page' do
  visit '/'
  expect(page).to have_content 'Home'
 end
end
 

Comments