forked from refinery/refinerycms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
94 lines (81 loc) · 2.96 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'rbconfig'
require 'factory_girl'
require File.expand_path('../support/refinery/controller_macros', __FILE__)
def setup_environment
# This file is copied to ~/spec when you run 'rails generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f}
engines = [
'authentication',
'images',
]
engines.each do |engine|
require "#{Rails.root}/#{engine}/features/support/factories.rb"
end
RSpec.configure do |config|
# == 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
config.mock_with :rspec
config.fixture_path = ::Rails.root.join('spec', 'fixtures').to_s
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.include ::Devise::TestHelpers, :type => :controller
config.extend ::Refinery::ControllerMacros, :type => :controller
end
end
def each_run
end
require 'rubygems'
# If spork is available in the Gemfile it'll be used but we don't force it.
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
setup_environment
end
Spork.each_run do
# This code will be run each time you run your specs.
each_run
end
# --- Instructions ---
# - Sort through your spec_helper file. Place as much environment loading
# code that you don't normally modify during development in the
# Spork.prefork block.
# - Place the rest under Spork.each_run block
# - Any code that is left outside of the blocks will be ran during preforking
# and during each_run!
# - These instructions should self-destruct in 10 seconds. If they don't,
# feel free to delete them.
#
else
setup_environment
each_run
end
def capture_stdout(stdin_str = '')
begin
require 'stringio'
$o_stdin, $o_stdout, $o_stderr = $stdin, $stdout, $stderr
$stdin, $stdout, $stderr = StringIO.new(stdin_str), StringIO.new, StringIO.new
yield
{:stdout => $stdout.string, :stderr => $stderr.string}
ensure
$stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr
end
end