Skip to content

Instantly share code, notes, and snippets.

@johan--
Forked from JanDintel/install.md
Created July 20, 2016 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan--/58bad21f7a79648d478601f11ec2440e to your computer and use it in GitHub Desktop.
Save johan--/58bad21f7a79648d478601f11ec2440e to your computer and use it in GitHub Desktop.
Install guide for Rspec, Guard, Spork, Cucumber and Mongoid

Install Cucumber with Rspec, Guard, Factory Girl(?) and Spork

Using during Hartl rails 4.0 guide (http://ruby.railstutorial.org/chapters)

Gems

group :development, :test
  gem 'guard-rspec'
  gem 'guard-livereload'
  gem 'spork-rails', github: 'sporkrb/spork-rails' # rubygems version not rails 4 compatible
  gem 'guard-spork'
  gem 'childprocess'
end

group :test do
  gem 'selenium-webdriver', '2.0.0'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails'
  gem 'cucumber', '1.2.5' # Spork not supported as of Cucumber 1.3.0, need to use 1.2.5
  gem 'cucumber-rails', :require => false
  gem 'database_cleaner'
end

Install instruction

$ bundle update
$ bundle install
$ rails generate rspec:install
$ guard init rspec

Modify ./Guardfile

guard 'rspec', after_all_pass: false, cli: '--drb' do
...

Set up spork

$ bundle spork --bootstrap

Set up Spork in /spec/spec_helper.rb

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
end

Setup guard with spork

$ guard init spork

Install Cucumber

$ rails generate cucumber:install --spork

Mongoid

For usage with mongoid, modify /spec/spec_helper.rb. Remove these lines:

ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
..
config.fixture_path = "#{::Rails.root}/spec/fixtures"
..
config.use_transactional_fixtures = true

And add to /spec/spec_helper.rb, below Rspec.configure

config.before(:suite) do
  DatabaseCleaner[:mongoid].strategy = :truncation
end

config.before(:each) do
  DatabaseCleaner[:mongoid].start
end

config.after(:each) do
  DatabaseCleaner[:mongoid].clean
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment