Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #128 from integrum/master

Set environment variables
  • Loading branch information...
commit 49fef65d8acfb10a957fe43d8ea8b0eebd2983a4 2 parents df2ea83 + ff88053
Thibaud Guillaume-Gentil authored
View
7 README.md
@@ -96,6 +96,13 @@ guard 'rspec', :spec_paths => "test" do
# ...
end
```
+If you want to set an environment variable, you can configure `:env` option with a hash:
+
+``` ruby
+guard 'rspec', :env => {'RAILS_ENV' => 'guard'} do
+ # ...
+end
+```
[Turnip](https://github.com/jnicklas/turnip) is supported (Ruby 1.9.X only), but you must enable it:
``` ruby
guard 'rspec', :turnip => true do
View
8 lib/guard/rspec/runner.rb
@@ -14,6 +14,7 @@ def initialize(options = {})
:binstubs => false,
:rvm => nil,
:cli => nil,
+ :env => nil,
:notification => true,
:turnip => false
}.merge(options)
@@ -80,6 +81,11 @@ def parsed_or_default_formatter
private
+ def environment_variables
+ return if @options[:env].nil?
+ "export " + @options[:env].map {|key, value| "#{key}=#{value}"}.join(' ') + ';'
+ end
+
def rspec_arguments(paths, options)
arg_parts = []
arg_parts << options[:cli]
@@ -97,6 +103,7 @@ def rspec_arguments(paths, options)
def rspec_command(paths, options)
cmd_parts = []
+ cmd_parts << environment_variables
cmd_parts << "rvm #{@options[:rvm].join(',')} exec" if @options[:rvm].respond_to?(:join)
cmd_parts << "bundle exec" if bundle_exec?
cmd_parts << rspec_executable
@@ -230,7 +237,6 @@ def deprecations_warnings
def formatter_regex
@formatter_regex ||= /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
end
-
end
end
end
View
15 spec/guard/rspec/runner_spec.rb
@@ -370,6 +370,21 @@
end
end
end
+
+ describe ':env' do
+ context ":env => {'RAILS_ENV' => 'blue'}" do
+ subject { described_class.new(:env => {'RAILS_ENV' => 'blue'}) }
+
+ it 'sets the Rails environment' do
+ subject.should_receive(:system).with(
+ "export RAILS_ENV=blue; bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} " <<
+ '-f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec'
+ ).and_return(true)
+
+ subject.run(['spec'])
+ end
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.