Skip to content

manageyp/rspec_tutorials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The purpose of this project is to teach you how to use RSpec, a popular testing tool.

Introduction

RSpec is testing tool for the Ruby programming language. Born under the banner of Behaviour-Driven Development, it is designed to make Test-Driven Development a productive and enjoyable experience.

This is a Rails project, by default it use Test::Unit and Fixture. However we use FactoryGirl to set up Ruby objects as test data. It support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.

If we want to use factory_girl with Rails, we need to include factory_girl_rails.

Usage

  1. prepare database

You may change the database.yml setting first.

rake db:create
rake db:migrate
  1. add the following lines to your Gemfile

group :test, :development do
  gem "rspec-rails"
  gem "factory_girl"
  gem "factory_girl_rails"
end

Then run the following rake tasks:
bunlde install
rails generate rspec:install
  1. run all tests

rake spec
  1. run all modles tests

rake spec:models
  1. run single test file

rspec spec/models/user_spec.rb
  1. run single test method within a test file

rspec file_path:line_no

The line_no is the method location in your test file. Such as:

rspec spec/models/user_spec.rb:10

About

Rspec Turorials

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published