Skip to content

Instantly share code, notes, and snippets.

@francois-blanchard
Last active April 13, 2016 20:22
Show Gist options
  • Save francois-blanchard/74c5ff27cea06bba7e000a4f0a845970 to your computer and use it in GitHub Desktop.
Save francois-blanchard/74c5ff27cea06bba7e000a4f0a845970 to your computer and use it in GitHub Desktop.
RSpec usage

RSpec usage

Init for rails

  1. Remove /test directory, it’s minitest
  2. Install RSpec gem
# Gemfile

group :development , :test do
  gem 'rspec-rails' , '~> 3.4.2'
  gem 'factory_girl_rails', '~> 4.7.0'
  gem 'capybara', '~> 2.0.7'
end

group :test do
  gem 'database_cleaner'
end
$ bundle install
$ rails generate rspec:install
  1. Config factory girl
#spec/support/factory_girl.rb

RSpec.configure do |config| 
  config.include FactoryGirl::Syntax::Methods 
  config.before(:suite) do 
    begin 
      DatabaseCleaner.start 
      FactoryGirl.lint 
    ensure
      DatabaseCleaner.clean 
    end 
  end 
end
  1. Load factory to rspec
# Uncommentme! in rails_helper
Dir [Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  1. Load Capybara to rspec
# rails_helper
require 'capybara/rails'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment