Created
October 12, 2012 07:11
-
-
Save moh-alsheikh/3877739 to your computer and use it in GitHub Desktop.
Steps to setup rails enviroment to work with RSpec TDD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Steps to setup rails enviroment to work with RSpec TDD | |
1- include the follwing gems in your gem file :: | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
group :development, :test do | |
gem 'rspec-rails' | |
gem 'factory_girl_rails' | |
end | |
group :test do | |
gem 'faker' | |
gem 'capybara' | |
gem 'guard-rspec' | |
gem 'launchy' | |
end | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
So what did we just install? | |
# rspec-rails includes RSpec itself in a wrapper to make it play nicely with Rails 3. | |
# factory_girl_rails replaces Rails’ default fixtures for feeding test data to the test suite with much more preferable factories. | |
# faker generates names, email addresses, and other placeholders for factories. | |
#capybara makes it easy to programatically simulate your users’ interactions with your application. | |
#launchy does one thing, but does it well: It opens your default web browser upon failed integration specs to show you what your application is rendering. | |
#guard-rspec watches your application and tests and runs specs for you automatically when it detects changes. | |
2- check if there is a test database in your project if it's not exist you can create by put the follwing | |
to you database.yml in config folder :: | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
test: | |
adapter: sqlite3 | |
database: db/test.sqlite3 | |
pool: 5 | |
timeout: 5000 | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
and issue the follwing command to create it | |
rake db:create:all | |
3- now we need to install RSpec into our app by :: | |
rails g rspec:install | |
this command wil create | |
* .rspec | |
* spec folder | |
* spec_helper.rb | |
open the last one and include this line | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
require "capybara/rspec" | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
and open .rspec file and include this line | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
--format documentation | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
4- now open config/application.rb and include the following code inside the Application class: | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
config.generators do |g| | |
g.test_framework :rspec, | |
:fixtures => true, | |
:view_specs => false, | |
:helper_specs => false, | |
:routing_specs => false, | |
:controller_specs => true, | |
:request_specs => true | |
g.fixture_replacement :factory_girl, :dir => "spec/factories" | |
end | |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
:fixtures => true specifies to generate a fixture for each model (using a Factory Girl factory, instead of an actual fixture) | |
:view_specs => false says to skip generating view specs. I won’t cover them in this book; instead we’ll use request specs to test interface elements. | |
:helper_specs => false skips generating specs for the helper files Rails generates with each controller. As your comfort level with RSpec improves, consider changing this option to true and testing these files. | |
:routing_specs => false omits a spec file for your config/routes.rb file. If your application is simple, as the one in this book will be, you’re probably safe skipping these specs. As your application grows, however, and takes on more complex routing, it’s a good idea to incorporate routing specs. | |
And finally, g.fixture_replacement :factory_girl tells Rails to generate factories instead of fixtures, and to save them in the spec/factories directory. | |
now you are ready to start using RSpec wih rails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment