2014-10-26 20:51:42 -04:00
|
|
|
require File.expand_path('../support/unit/rails_application', __FILE__)
|
2013-10-23 16:18:52 -04:00
|
|
|
|
Add missing test dependences to Appraisals
Since as of commit 2748b750873faf587c78d7a71f6c725b0fd4252a, we no
longer install dependencies inside of the Rails app that is generated
and used to run all of the tests, we have to require all of the
dependencies that the app would install inside of the appropriate
Appraisals.
This was mostly straightforward except for some workarounds with the
turn gem:
* Rails 3.1 requires two versions of turn depending on which Ruby
version you're using. On 1.9.2, it uses turn 0.9.2; after 1.9.2, it
uses ~> 0.9.3. To accommodate this we have to have two versions of the
Rails 3.1 appraisal which declare the different turn versions.
* Rails 3.1 also loads the turn gem even if, in the Gemfile for the app,
turn is declared with `require: false`. This causes a problem while
running our tests because turn actually requires minitest/autorun,
which adds a hook so when Ruby exits, Minitest tests are run. Because
we're already using RSpec, Minitest will try to re-run the `rspec`
command we ran within a Minitest environment. This will fail since we
are using RSpec-specific command line options to run the tests.
Unfortunately there's no way to shut off minitest/autorun after it's
been required, so we have to monkey-patch Minitest's #run method so
it's a no-op.
2014-05-16 11:57:19 -04:00
|
|
|
def monkey_patch_minitest_to_do_nothing
|
|
|
|
# Rails 3.1's test_help file requires Turn, which loads Minitest in autorun
|
|
|
|
# mode. This means that Minitest tests will run after these RSpec tests are
|
|
|
|
# finished running. This will break on CI since we pass --color to the `rspec`
|
|
|
|
# command.
|
|
|
|
|
|
|
|
if defined?(MiniTest)
|
|
|
|
MiniTest::Unit.class_eval do
|
|
|
|
def run(*); end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-26 20:51:42 -04:00
|
|
|
$test_app = UnitTests::RailsApplication.new
|
2013-11-22 22:25:27 -05:00
|
|
|
$test_app.create
|
|
|
|
$test_app.load
|
2010-12-13 17:28:59 -05:00
|
|
|
|
Add missing test dependences to Appraisals
Since as of commit 2748b750873faf587c78d7a71f6c725b0fd4252a, we no
longer install dependencies inside of the Rails app that is generated
and used to run all of the tests, we have to require all of the
dependencies that the app would install inside of the appropriate
Appraisals.
This was mostly straightforward except for some workarounds with the
turn gem:
* Rails 3.1 requires two versions of turn depending on which Ruby
version you're using. On 1.9.2, it uses turn 0.9.2; after 1.9.2, it
uses ~> 0.9.3. To accommodate this we have to have two versions of the
Rails 3.1 appraisal which declare the different turn versions.
* Rails 3.1 also loads the turn gem even if, in the Gemfile for the app,
turn is declared with `require: false`. This causes a problem while
running our tests because turn actually requires minitest/autorun,
which adds a hook so when Ruby exits, Minitest tests are run. Because
we're already using RSpec, Minitest will try to re-run the `rspec`
command we ran within a Minitest environment. This will fail since we
are using RSpec-specific command line options to run the tests.
Unfortunately there's no way to shut off minitest/autorun after it's
been required, so we have to monkey-patch Minitest's #run method so
it's a no-op.
2014-05-16 11:57:19 -04:00
|
|
|
monkey_patch_minitest_to_do_nothing
|
|
|
|
|
2013-11-22 22:25:27 -05:00
|
|
|
ENV['BUNDLE_GEMFILE'] ||= app.gemfile_path
|
2013-10-23 16:18:52 -04:00
|
|
|
ENV['RAILS_ENV'] = 'test'
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2012-03-23 21:00:36 -04:00
|
|
|
require 'rspec/rails'
|
2014-12-24 16:28:35 -05:00
|
|
|
require 'shoulda-matchers'
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2013-11-22 22:25:27 -05:00
|
|
|
PROJECT_ROOT = File.expand_path('../..', __FILE__)
|
2010-12-13 17:28:59 -05:00
|
|
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
|
|
|
|
2014-10-26 20:52:55 -04:00
|
|
|
Dir[ File.join(File.expand_path('../support/unit/**/*.rb', __FILE__)) ].sort.each do |file|
|
2014-10-26 20:51:42 -04:00
|
|
|
require file
|
|
|
|
end
|
|
|
|
|
2010-12-13 17:28:59 -05:00
|
|
|
RSpec.configure do |config|
|
2014-11-06 16:16:30 -05:00
|
|
|
config.order = :random
|
|
|
|
|
2014-01-17 17:01:43 -05:00
|
|
|
config.expect_with :rspec do |c|
|
|
|
|
c.syntax = :expect
|
|
|
|
end
|
|
|
|
|
2014-11-07 17:22:20 -05:00
|
|
|
config.mock_with :rspec
|
|
|
|
|
2014-10-17 14:27:53 -04:00
|
|
|
if config.respond_to?(:infer_spec_type_from_file_location!)
|
|
|
|
config.infer_spec_type_from_file_location!
|
|
|
|
end
|
2014-10-26 20:51:42 -04:00
|
|
|
|
2014-12-24 16:44:38 -05:00
|
|
|
config.before(:all, type: :controller) do
|
|
|
|
self.class.controller(ApplicationController) { }
|
|
|
|
end
|
|
|
|
|
2014-10-26 20:51:42 -04:00
|
|
|
UnitTests::ActiveModelHelpers.configure_example_group(config)
|
|
|
|
UnitTests::ActiveModelVersions.configure_example_group(config)
|
|
|
|
UnitTests::ActiveResourceBuilder.configure_example_group(config)
|
|
|
|
UnitTests::ClassBuilder.configure_example_group(config)
|
|
|
|
UnitTests::ControllerBuilder.configure_example_group(config)
|
|
|
|
UnitTests::I18nFaker.configure_example_group(config)
|
|
|
|
UnitTests::MailerBuilder.configure_example_group(config)
|
|
|
|
UnitTests::ModelBuilder.configure_example_group(config)
|
|
|
|
UnitTests::RailsVersions.configure_example_group(config)
|
|
|
|
|
|
|
|
config.include UnitTests::Matchers
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
2014-06-27 18:39:39 -04:00
|
|
|
|
2014-12-24 16:46:10 -05:00
|
|
|
ActiveSupport::Deprecation.behavior = :stderr
|
2014-06-27 18:39:39 -04:00
|
|
|
$VERBOSE = true
|