Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save epintozzi/668ee19db4c41331475c238292ebac5e to your computer and use it in GitHub Desktop.
Save epintozzi/668ee19db4c41331475c238292ebac5e to your computer and use it in GitHub Desktop.
Setting up rails and testing

Generate a new project without the included testing and with a postgres database:

rails new MyApp --skip-turbolinks --skip-spring -T --database=postgresql

Add VCR

group :test do
  gem 'vcr'
  gem 'webmock'
end

Add to spec_helper.rb

require 'vcr'

VCR.configure do |config|
  config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
  config.hook_into :webmock
end

Include as first line in test setup (after describe, context, and it

VCR.use_cassette("#repos") do 

OR Add to spec_helper.rb

VCR.configure do |config|
  config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
  config.hook_into :webmock
  config.configure_rspec_metadata!
end

Include :vcr in it line of test

it "returns repos for a user", :vcr do

Add Simplecov

gem 'simplecov'

Add this to spec_helper

if ENV['COVERAGE'] == 'true'
  require 'simplecov'

  SimpleCov.start
end

Add this to rails_helper

require 'simplecov'

require 'simplecov'
SimpleCov.start do
	add_filter "/spec/"
end

Add rspec, capybara, factory_girl, launchy and database cleaner to gemfile:

group :development, :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'launchy'
  gem 'database_cleaner'
end

Install gems and generate rspec files:

bundle
rails g rspec:install

Create directory and folder for factory girl:

mkdir spec/support
touch spec/support/factory_girl.rb

Add Rspec configuration to 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

Uncomment this line from rails_helper.rb

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

Heroku Tutorial: https://github.com/turingschool/lesson_plans/blob/master/ruby_02-web_applications_with_ruby/mix_master/1_getting_started.markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment