RSpec 2 on Rails 3

What is BDD (Behaviour driven development)

We can say BDD is TDD (Test driven development)  Done Right. It extends TDD by writing test cases in a natural language that non-programmers can read. Behavior-driven developers use their native language in combination with the ubiquitous language of  domain driven design  to describe the purpose and benefit of their code. This allows the developers to focus on why the code should be created, rather than the technical details, and minimizes translation between the technical language in which the code is written and the domain language spoken by the business, users, stakeholders, project management, etc.

Installation

Firstly, install the gems:

$ sudo gem install rspec –prerelease
$ sudo gem install webrat
$ sudo gem install rspec-rails –prerelease

2) create rails project using

rails new myapp -T -d mysql

-T for avoiding unit test files
-d to use mysql database

2a) import into netbeans IDE

—————————————————————————
Here faced a problem

rake aborted! uninitialized constant Rake::DSL

solution

In Rakefile above require ‘rake’ put  require ‘rake/dsl_definition’

————————————————————————————

3) add these to gem file and bundle install

group :development, :test do
gem ‘rspec-rails’
end

—————————————————————————
here faced a problem

In Gemfile replaced  gem ‘mysql2’, ‘~> 0.2.6’  with

gem ‘mysql2’, ‘< 0.3’

———————————————————–
4)run the following in the project directory (used console window)

rails generate rspec:install

it will create

1) .rspec
2) spec
3) spec/spec_helper.rb

5) do usual scaffold, models etc

example
rails generate scaffold Person name:string age:integer zipcode:string

corresponding spec files  will created automatically.

6)

1) change database.yml for database access
2) rake db:create
3) rake db:migrate

7) run rake  (without arguments)

References

1) http://spanx.wordpress.com/2010/02/12/rspec-2-on-rails-3/
2) http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html

————————————————————————————————————————————————————

RSpec – installation- Normal way (Test Files included)

1) create new project

2)And add the following to the gme file

group :development, :test do
gem ‘rspec-rails’
end

3) bundle install

4) script/rails generate rspec:install

5) In config/applicaton.rb Add the following

config.generators do |g|
g.test_framework :rspec
end

Reference  http://blog.notahat.com/posts/43

Source:  http://klairvoyant.in

About http://www.infosolutions.klairvoyant.com/

software development firm
This entry was posted in rails, ROR, ruby on rails and tagged , . Bookmark the permalink.

Leave a comment