Browse files

Using guard and spork as local test servers

  • Loading branch information...
1 parent de6cf16 commit 532fdbbd130f1245cf88107168ff7faa41488026 @tvdeyen tvdeyen committed Mar 20, 2012
Showing with 71 additions and 42 deletions.
  1. +1 −2 Gemfile
  2. +13 −0 Guardfile
  3. +57 −40 spec/spec_helper.rb
View
3 Gemfile
@@ -4,9 +4,8 @@ source 'http://rubygems.org'
gemspec
group :development do
-
gem 'alchemy_cms', :git => 'git://github.com/magiclabs/alchemy_cms'
-
+ gem 'guard-spork'
if !ENV["CI"]
gem 'ruby-debug-base19', '~> 0.11.26', :platform => :ruby_19
gem 'linecache19', '~> 0.5.13', :platform => :ruby_19
View
13 Guardfile
@@ -0,0 +1,13 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+ watch(%r{lib/})
+ watch('spec/dummy/config/application.rb')
+ watch('spec/dummy/config/environment.rb')
+ watch(%r{^spec/dummy/config/environments/.+\.rb$})
+ watch(%r{^spec/dummy/config/initializers/.+\.rb$})
+ watch('Gemfile')
+ watch('Gemfile.lock')
+ watch('spec/spec_helper.rb') { :rspec }
+end
View
97 spec/spec_helper.rb
@@ -1,41 +1,58 @@
-# Configure Rails Envinronment
-ENV["RAILS_ENV"] = "test"
-
-require File.expand_path("../dummy/config/environment.rb", __FILE__)
-require "rails/test_help"
-require "rspec/rails"
-require "email_spec"
-
-ActionMailer::Base.delivery_method = :test
-ActionMailer::Base.perform_deliveries = true
-ActionMailer::Base.default_url_options[:host] = "test.com"
-
-Rails.backtrace_cleaner.remove_silencers!
-
-require 'database_cleaner'
-DatabaseCleaner.strategy = :truncation
-DatabaseCleaner.clean
-
-# Configure capybara for integration testing
-# require "capybara/rails"
-# Capybara.default_driver = :rack_test
-# Capybara.default_selector = :css
-
-Alchemy::Seeder.seed!
-AlchemyCrm::Seeder.seed!
-
-# Load support files
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
-
-RSpec.configure do |config|
- # Remove this line if you don't want RSpec's should and should_not
- # methods or matchers
- require 'rspec/expectations'
- config.include RSpec::Matchers
- # for testing mails
- config.include(EmailSpec::Helpers)
- config.include(EmailSpec::Matchers)
- config.use_transactional_fixtures = true
- # == Mock Framework
- config.mock_with :rspec
+begin
+ require 'spork'
+rescue LoadError => e
+end
+
+def configure
+ # Configure Rails Environment
+ ENV["RAILS_ENV"] = "test"
+
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
+
+ require 'database_cleaner'
+ DatabaseCleaner.strategy = :truncation
+
+ require "rails/test_help"
+ require "rspec/rails"
+ require "email_spec"
+
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.default_url_options[:host] = "test.com"
+
+ Rails.backtrace_cleaner.remove_silencers!
+
+ # Load support files
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+ RSpec.configure do |config|
+ # Remove this line if you don't want RSpec's should and should_not
+ # methods or matchers
+ require 'rspec/expectations'
+ config.include RSpec::Matchers
+ # for testing mails
+ config.include(EmailSpec::Helpers)
+ config.include(EmailSpec::Matchers)
+ config.use_transactional_fixtures = true
+ # == Mock Framework
+ config.mock_with :rspec
+ end
+
+end
+
+def seed
+ # This code will be run each time you run your specs.
+ DatabaseCleaner.clean
+
+ # Seed the database
+ Alchemy::Seeder.seed!
+ AlchemyCrm::Seeder.seed!
+end
+
+if defined?(Spork)
+ Spork.prefork { configure }
+ Spork.each_run { seed }
+else
+ configure
+ seed
end

0 comments on commit 532fdbb

Please sign in to comment.