What is the best way to configure the rspec with selenium and how to setup test db.
I new in TDD and i am trying to configure rspec by adding the rspec gem in gemfile like
gem 'rspec'
gem 'selenium'
and trying to setup DB like
test:
db_name: xyz
but I am stuck as it didn't run successfully. Please guide either I am doing the stuff in right way or have some issues.
Lets try this solution manual add these gems in your GemFile
gem 'capybara'
gem 'rspec-rails'
gem 'wombat'
gem 'capybara-webkit'
gem 'selenium-webdriver', '2.35.0'
and after that run bundle and to create test envoirment do something like that in your database.yml
defaults: &defaults
adapter: mysql2
host: localhost
username: root
password: password
test:
<<: *defaults
database: test_db
and then run
rails generate rspec:install
this will generate these files.
.rspec
spec/spec_helper.rb
spec/rails_helper.rb
and to run the test cases use this command.
bundle exec rspec
include these in rspec_helper
require 'capybara'
require 'capybara/dsl'
require 'debugger'
and these in rails_helper
config.use_transactional_fixtures = true
config.include Capybara::DSL
then
RAILS_ENV=test rake db:create, db:migrate
or RAILS_ENV=test rake db:schema:load
Hopefully this solved your problem.