Skip to content

Commit 93ddd60

Browse files
committed
Merge pull request #403 from eileencodes/fix-environment-settings-on-spring
Ensure `bin/rails test command defaults to `test` env
2 parents f18afb8 + 497c1ee commit 93ddd60

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/spring/commands/rails.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ def extract_environment(args)
8484
end
8585

8686
class RailsTest < Rails
87+
def env(args)
88+
environment = "test"
89+
90+
args.each.with_index do |arg, i|
91+
if arg =~ /--environment=(\w+)/
92+
environment = $1
93+
elsif i > 0 && args[i - 1] == "-e"
94+
environment = arg
95+
end
96+
end
97+
98+
environment
99+
end
100+
87101
def command_name
88102
"test"
89103
end

test/unit/commands_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,19 @@ class CommandsTest < ActiveSupport::TestCase
5656
assert_equal "test", command.env(["test:models"])
5757
assert_nil command.env(["test_foo"])
5858
end
59+
60+
test 'RailsTest#command defaults to test rails environment' do
61+
command = Spring::Commands::RailsTest.new
62+
assert_equal 'test', command.env([])
63+
end
64+
65+
test 'RailsTest#command sets rails environment from --environment option' do
66+
command = Spring::Commands::RailsTest.new
67+
assert_equal 'foo', command.env(['--environment=foo'])
68+
end
69+
70+
test 'RailsTest#command sets rails environment from -e option' do
71+
command = Spring::Commands::RailsTest.new
72+
assert_equal 'foo', command.env(['-e', 'foo'])
73+
end
5974
end

0 commit comments

Comments
 (0)