Skip to content

Commit 6115188

Browse files
committed
Merge pull request #273 from musicglue/master
strip out environment switches from rails runner ARGV [#272]
2 parents 1375228 + edb788b commit 6115188

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/spring/commands/rails.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def command_name
3434
end
3535

3636
class RailsRunner < Rails
37+
def call
38+
remove_environment_switches ARGV
39+
super
40+
end
41+
3742
def env(tail)
3843
previous_option = nil
3944
tail.reverse.each do |option|
@@ -49,6 +54,18 @@ def env(tail)
4954
def command_name
5055
"runner"
5156
end
57+
58+
def remove_environment_switches switches
59+
if i = switches.index('-e')
60+
if switches.length >= i + 1
61+
switches.slice! i..(i+1)
62+
end
63+
end
64+
65+
if i = switches.find_index { |arg| arg =~ /--environment=/ }
66+
switches.slice! i
67+
end
68+
end
5269
end
5370

5471
Spring.register_command "rails_console", RailsConsole.new

test/unit/commands_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ class CommandsTest < ActiveSupport::TestCase
2727
assert_nil command.env(['puts 1+1'])
2828
end
2929

30+
test 'RailsRunner#remove_environment_switches removes -e <env>' do
31+
command = Spring::Commands::RailsRunner.new
32+
switches = ['-b', '-a', '-e', 'test', '-r']
33+
command.remove_environment_switches switches
34+
assert_equal ['-b', '-a', '-r'], switches
35+
end
36+
37+
test 'RailsRunner#remove_environment_switches removes --environment=<env>' do
38+
command = Spring::Commands::RailsRunner.new
39+
switches = ['-b', '--environment=test', '-a', '-r']
40+
command.remove_environment_switches switches
41+
assert_equal ['-b', '-a', '-r'], switches
42+
end
43+
3044
test "rake command has configurable environments" do
3145
command = Spring::Commands::Rake.new
3246
assert_nil command.env(["foo"])

0 commit comments

Comments
 (0)