Skip to content

Commit

Permalink
Support rspec 3.0+ out of the box
Browse files Browse the repository at this point in the history
Rspec 3.0 introduces separate _helper files for full tests and tests that
don't require the full rails app to be loaded. Because of this and because
the point of zeus is to pre-load your app, default to loading the full
rails_helper for zeus. You can override this behavior with the env var
RAILS_TEST_HELPER.

Fixes #474
  • Loading branch information
latortuga committed Nov 10, 2014
1 parent e9b0086 commit d126abf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rubygem/lib/zeus/rails.rb
Expand Up @@ -191,7 +191,11 @@ def test_helper
if ENV['RAILS_TEST_HELPER']
require ENV['RAILS_TEST_HELPER']
else
if File.exists?(ROOT_PATH + "/spec/spec_helper.rb")
if File.exists?(ROOT_PATH + "/spec/rails_helper.rb")
# RSpec >= 3.0+
require 'rails_helper'
elsif File.exists?(ROOT_PATH + "/spec/spec_helper.rb")
# RSpec < 3.0
require 'spec_helper'
elsif File.exists?(ROOT_PATH + "/test/minitest_helper.rb")
require 'minitest_helper'
Expand Down
13 changes: 12 additions & 1 deletion rubygem/spec/rails_spec.rb
Expand Up @@ -17,7 +17,16 @@ module Zeus
ENV.clear
end

it "requires rails_helper when using rspec 3.0+" do
mock_file_existence(ROOT_PATH + "/spec/rails_helper.rb", true)

rails.should_receive(:require).with("rails_helper")

rails.test_helper
end

it "when spec_helper exists spec_helper is required" do
mock_file_existence(ROOT_PATH + "/spec/rails_helper.rb", false)
mock_file_existence(ROOT_PATH + "/spec/spec_helper.rb", true)

rails.should_receive(:require).with("spec_helper")
Expand All @@ -26,6 +35,7 @@ module Zeus
end

it "when minitest_helper exists minitest_helper is required" do
mock_file_existence(ROOT_PATH + "/spec/rails_helper.rb", false)
mock_file_existence(ROOT_PATH + "/spec/spec_helper.rb", false)
mock_file_existence(ROOT_PATH + "/test/minitest_helper.rb", true)

Expand All @@ -34,7 +44,8 @@ module Zeus
rails.test_helper
end

it "when there is no spec_helper or minitest_helper, test_helper is required" do
it "when there is no rspec helpers or minitest_helper, test_helper is required" do
mock_file_existence(ROOT_PATH + "/spec/rails_helper.rb", false)
mock_file_existence(ROOT_PATH + "/spec/spec_helper.rb", false)
mock_file_existence(ROOT_PATH + "/test/minitest_helper.rb", false)

Expand Down

0 comments on commit d126abf

Please sign in to comment.