Skip to content

Instantly share code, notes, and snippets.

@alex-zige
Last active December 17, 2015 06:29
Show Gist options
  • Save alex-zige/5566238 to your computer and use it in GitHub Desktop.
Save alex-zige/5566238 to your computer and use it in GitHub Desktop.
Rspec and Guard setup

enable test suit in Gemfile

group :test, :development do
  gem 'guard'
  gem 'guard-rspec'
  gem "rspec-rails"
  gem 'guard-zeus'
  gem "factory_girl_rails", "~> 4.0"
  gem 'mysql2'
end

group :test do
  gem 'database_cleaner'
  gem 'simplecov', :require => false
end

bundle update

bundle install

generate spec helper

rails generate rspec:install

custom and enable db cleaner [spech_helper.rb]

RSpec.configure do |config|
  #database cleaner
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
end

init the guard file

guard init

update the guardfile

guard 'rspec', :version => 2, all_on_start: false, all_after_pass: false, zeus: true, bundler: false do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }
  ....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment