Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Last active December 20, 2015 04:49
Show Gist options
  • Save bartolsthoorn/6074108 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/6074108 to your computer and use it in GitHub Desktop.

Install Cucumber with Rspec, Guard 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

Done!

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