Skip to content

Commit 408ff09

Browse files
committed
Set up specs to use spork for faster test runs (locomotivecms#157)
1 parent b23f269 commit 408ff09

File tree

5 files changed

+56
-44
lines changed

5 files changed

+56
-44
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
--drb
12
--colour

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ group :test do
7272
gem 'capybara'
7373
gem 'database_cleaner'
7474

75-
gem 'spork'
75+
gem 'spork', '~> 0.9.0.rc'
7676
gem 'launchy'
7777
gem 'mocha', :git => 'git://github.com/floehopper/mocha.git'
7878
end

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ GEM
261261
ffi (>= 1.0.7)
262262
json_pure
263263
rubyzip
264-
spork (0.8.5)
264+
spork (0.9.0.rc9)
265265
term-ansicolor (1.0.6)
266266
thor (0.14.6)
267267
treetop (1.4.9)
@@ -330,7 +330,7 @@ DEPENDENCIES
330330
ruby-debug19
331331
rubyzip
332332
sass (= 3.1.2)
333-
spork
333+
spork (~> 0.9.0.rc)
334334
unicorn
335335
warden
336336
will_paginate

doc/changelogs/20110812.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- implement the reverse has_many feature based on the great work of Alex Sanford (#142)
2+
- fix a couple of bugs: #152
3+
- improve the installation procedure about setting carrierwave up (#144)

spec/spec_helper.rb

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Note: if segmentation fault with spork / imagemagick on mac os x, take a look at:
2+
# http://stackoverflow.com/questions/2838307/why-is-this-rmagick-call-generating-a-segmentation-fault
3+
4+
require 'rubygems'
5+
require 'spork'
6+
17
# figure out where we are being loaded from
28
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
39
begin
@@ -21,61 +27,63 @@
2127
end
2228
end
2329

24-
# This file is copied to spec/ when you run 'rails generate rspec:install'
25-
ENV["RAILS_ENV"] ||= 'test'
26-
require File.expand_path('../../config/environment', __FILE__)
2730

28-
require 'rspec/rails'
29-
require 'factory_girl'
31+
Spork.prefork do
32+
# Loading more in this block will cause your tests to run faster. However,
33+
# if you change any configuration or code from libraries loaded here, you'll
34+
# need to restart spork for it take effect.
3035

31-
FactoryGirl.find_definitions
36+
# This file is copied to spec/ when you run 'rails generate rspec:install'
37+
ENV["RAILS_ENV"] ||= 'test'
38+
require File.expand_path('../../config/environment', __FILE__)
3239

33-
# Requires supporting ruby files with custom matchers and macros, etc,
34-
# in spec/support/ and its subdirectories.
35-
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
40+
require 'rspec/rails'
41+
require 'factory_girl'
3642

37-
Locomotive.configure_for_test
43+
FactoryGirl.find_definitions
3844

39-
RSpec.configure do |config|
45+
# Requires supporting ruby files with custom matchers and macros, etc,
46+
# in spec/support/ and its subdirectories.
47+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
4048

41-
config.include(Locomotive::RSpec::Matchers)
49+
Locomotive.configure_for_test
4250

43-
# == Mock Framework
44-
#
45-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
46-
#
47-
config.mock_with :mocha
48-
# config.mock_with :flexmock
49-
# config.mock_with :rr
50-
# config.mock_with :rspec
51+
RSpec.configure do |config|
5152

52-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
53-
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
53+
config.include(Locomotive::RSpec::Matchers)
5454

55-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
56-
# examples within a transaction, remove the following line or assign false
57-
# instead of true.
58-
# config.use_transactional_fixtures = true
55+
config.mock_with :mocha
5956

60-
config.before(:each) do
61-
Locomotive.config.heroku = false
62-
end
57+
config.before(:each) do
58+
Locomotive.config.heroku = false
59+
end
6360

64-
require 'database_cleaner'
65-
config.before(:suite) do
66-
DatabaseCleaner.strategy = :truncation
67-
DatabaseCleaner.orm = 'mongoid'
68-
end
61+
require 'database_cleaner'
62+
config.before(:suite) do
63+
DatabaseCleaner.strategy = :truncation
64+
DatabaseCleaner.orm = 'mongoid'
65+
end
6966

70-
config.before(:each) do
71-
if self.described_class != Locomotive::Import::Job
72-
DatabaseCleaner.clean
67+
config.before(:each) do
68+
if self.described_class != Locomotive::Import::Job
69+
DatabaseCleaner.clean
70+
end
7371
end
74-
end
7572

76-
config.before(:all) do
77-
if self.described_class == Locomotive::Import::Job
78-
DatabaseCleaner.clean
73+
config.before(:all) do
74+
if self.described_class == Locomotive::Import::Job
75+
DatabaseCleaner.clean
76+
end
7977
end
8078
end
79+
8180
end
81+
82+
Spork.each_run do
83+
# This code will be run each time you run your specs.
84+
Locomotive.configure_for_test(true)
85+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
86+
87+
# loading ruby file directly breaks the tests
88+
# Dir[Rails.root.join('app/models/*.rb')].each { |f| load f }
89+
end

0 commit comments

Comments
 (0)