Installing Guard & Spork for Auto Running of Specs
Gemfile
Install the following gems with bundle install
Gemfile
1234567891011121314151617181920212223
.....group:test_envsdogem'rspec-rails',"~> 2.0"gem'factory_girl_rails'gem'faker'gem'capybara',"~> 2.0.2"gem'database_cleaner',"~> 0.9.1"gem'launchy'# file system event triggers for ruby. See note at end about RVM gem'rb-fsevent','0.9.3'# Notifications of test states, Requires Growl and growlnotify to be installedgem'growl','1.0.3'# Automated test running and speed imporvementsgem'guard-rspec'gem'guard-spork','1.2.0'gem'childprocess','0.3.6'# this was due to errors appearing in 0.3.7 and highergem'spork','0.9.2'gem'debugger'end.....
require'rubygems'require'spork'ENV["RAILS_ENV"]=(ENV["RAILS_ENV"]=='development'?'test':ENV["RAILS_ENV"]+'_test')requireFile.expand_path("../../config/environment",__FILE__)require'rspec/rails'require'rspec/autorun'require"capybara/rspec"#uncomment the following line to use spork with the debugger# require 'spork/ext/ruby-debug'Spork.preforkdorequire'database_cleaner'# if defined? Capybara::Webkit# Capybara.javascript_driver = :webkit# endCapybara.default_wait_time=10Capybara.app_host='http://'+Settings.host.split(':')[0]Capybara.always_include_port=true# if defined? Delayed# Delayed::Worker.delay_jobs = false# end# Requires supporting ruby files with custom matchers and macros, etc,# in spec/support/ and its subdirectories.Dir[Rails.root.join("spec/support/**/*.rb")].each{|f|requiref}RSpec.configuredo|config|config.includeFactoryGirl::Syntax::Methodsconfig.extendPaperclipMacrosconfig.includeFacebookMacrosconfig.includeFriendcareBootstrapMacros# ## Mock Framework## If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:## config.mock_with :mocha# config.mock_with :flexmock# config.mock_with :rr# Remove this line if you're not using ActiveRecord or ActiveRecord fixturesconfig.fixture_path="#{::Rails.root}/spec/fixtures"# If true, the base class of anonymous controllers will be inferred# automatically. This will be the default behavior in future versions of# rspec-rails.config.infer_base_class_for_anonymous_controllers=false# Run specs in random order to surface order dependencies. If you find an# order dependency and want to debug it, you can fix the order by providing# the seed, which is printed after each run.# --seed 1234config.order="random"# If you're not using ActiveRecord, or you'd prefer not to run each of your# examples within a transaction, remove the following line or assign false# instead of true.config.use_transactional_fixtures=false# to make sure that each time the test suite is run it is done so against a new # database i use the database_cleaner gem. so add that to your test group in the gem file# add set it up like soconfig.before(:suite)doDatabaseCleaner.strategy=:truncationendconfig.before(:each)doDatabaseCleaner.startendconfig.after(:each)doDatabaseCleaner.cleanendendendSpork.each_rundoifdefined?QCQC::Conn.connection=ActiveRecord::Base.connection.raw_connectionendend
.rspec
.rspec
1
--formatdocumentation--color--drb
Guardfile
Running run guard init rspec and guard init spork will produce a Guardfile similar to the one below. Not the additions of cucumber: false, test_unit: false, :wait => 45 to the spork call as leaving them out without test unit or cucumber configured can result in errors.
We also make an addition to the rspec guard call :cli => '--drb' so that it runs through spoke using distributed ruby
# A sample Guardfile# More info at https://github.com/guard/guard#readmerequire'active_support/core_ext'guard'spork',:rspec_env=>{'RAILS_ENV'=>'sexyjordan_test'},cucumber:false,test_unit:false,:wait=>45dowatch('config/application.rb')watch('config/environment.rb')watch(%r{^config/environments/.+\.rb$})watch(%r{^config/initializers/.+\.rb$})watch('Gemfile')watch('Gemfile.lock')watch('spec/spec_helper.rb')# watch('test/test_helper.rb')watch('spec/support/')endguard'rspec',:all_after_pass=>false,:cli=>'--drb'dowatch(%r{^spec/.+_spec\.rb$})watch(%r{^lib/(.+)\.rb$}){|m|"spec/lib/#{m[1]}_spec.rb"}watch('spec/spec_helper.rb'){"spec"}# Rails examplewatch(%r{^app/(.+)\.rb$}){|m|"spec/#{m[1]}_spec.rb"}watch(%r{^app/(.*)(\.erb|\.haml)$}){|m|"spec/#{m[1]}#{m[2]}_spec.rb"}watch(%r{^app/controllers/(.+)_(controller)\.rb$}){|m|["spec/routing/#{m[1]}_routing_spec.rb","spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb","spec/acceptance/#{m[1]}_spec.rb"]}watch(%r{^spec/support/(.+)\.rb$}){"spec"}watch('config/routes.rb'){"spec/routing"}watch('app/controllers/application_controller.rb'){"spec/controllers"}watch(%r{^app/models/(.+)\.rb$}){|m|"spec/models/#{m[1]}_spec.rb"}watch(%r{^app/services/(.+)\.rb$}){|m|"spec/services/#{m[1]}_spec.rb"}# Capybara features specswatch(%r{^app/views/(.+)/.*\.(erb|haml)$}){|m|"spec/features/#{m[1]}_spec.rb"}end
Testing with queue classic
Using queue classic, spork and rspec. If the QC setup shares the rails connection to the database we need to add this to the each run command in spork
Auto detection didnt work with rvm and 1.9.2 straight away. Ruby had to be recompiled with an additional flag to deal with file system events the way we want. The fix is taken from here
Using RVM
You can use RVM to build your Ruby with GNU readline support. First install the readline package with RVM:
$ rvm pkg install readline --verify-downloads 1
Then configure RVM to use the readline package by adding