Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

warn instead of raising when Ruby can't resolve '~'

- Fixes #377.
  • Loading branch information...
commit 2c00b21103495aef5e8ab9913a2f7890fc66bb08 1 parent 335729f
@dchelimsky dchelimsky authored
View
7 features/Changelog.md
@@ -1,3 +1,10 @@
+### 2.6.2 / 2011-05-20
+
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.1...v2.6.2)
+
+* Bug fixes
+ * Warn rather than raise when HOME env var is not defined
+
### 2.6.1 / 2011-05-19
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0...v2.6.1)
View
23 lib/rspec/core/configuration_options.rb
@@ -2,9 +2,6 @@ module RSpec
module Core
class ConfigurationOptions
- LOCAL_OPTIONS_FILE = ".rspec"
- GLOBAL_OPTIONS_FILE = File.join(File.expand_path("~"), ".rspec")
-
attr_reader :options
def initialize(args)
@@ -80,11 +77,11 @@ def custom_options
end
def local_options
- @local_options ||= options_from(LOCAL_OPTIONS_FILE)
+ @local_options ||= options_from(local_options_file)
end
def global_options
- @global_options ||= options_from(GLOBAL_OPTIONS_FILE)
+ @global_options ||= options_from(global_options_file)
end
def options_from(path)
@@ -92,7 +89,7 @@ def options_from(path)
end
def args_from_options_file(path)
- return [] unless File.exist?(path)
+ return [] unless path && File.exist?(path)
config_string = options_file_as_erb_string(path)
config_string.split(/\n+/).map {|l| l.split}.flatten
end
@@ -105,6 +102,20 @@ def options_file_as_erb_string(path)
def custom_options_file
command_line_options[:custom_options_file]
end
+
+ def local_options_file
+ ".rspec"
+ end
+
+ def global_options_file
+ begin
+ File.join(File.expand_path("~"), ".rspec")
+ rescue ArgumentError
+ warn "Unable to find ~/.rspec because the HOME environment variable is not set"
+ nil
+ end
+ end
+
end
end
end
View
30 spec/rspec/core/configuration_options_spec.rb
@@ -14,6 +14,17 @@ def parse_options(*args)
config_options_object(*args).options
end
+ it "warns when HOME env var is not set" do
+ begin
+ orig_home = ENV.delete("HOME")
+ coo = RSpec::Core::ConfigurationOptions.new([])
+ coo.should_receive(:warn)
+ coo.parse_options
+ ensure
+ ENV["HOME"] = orig_home
+ end
+ end
+
describe "#configure" do
it "sends libs before requires" do
opts = config_options_object(*%w[--require a/path -I a/lib])
@@ -286,23 +297,16 @@ def parse_options(*args)
before do
@orig_spec_opts = ENV["SPEC_OPTS"]
- @orig_global_options_file = RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE
- @orig_local_options_file = RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE
- RSpec::Core::ConfigurationOptions::__send__ :remove_const, :GLOBAL_OPTIONS_FILE
- RSpec::Core::ConfigurationOptions::__send__ :remove_const, :LOCAL_OPTIONS_FILE
- RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE = global_options_file
- RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE = local_options_file
- FileUtils.rm local_options_file if File.exist? local_options_file
- FileUtils.rm global_options_file if File.exist? global_options_file
- FileUtils.rm custom_options_file if File.exist? custom_options_file
+ RSpec::Core::ConfigurationOptions::send :public, :global_options_file
+ RSpec::Core::ConfigurationOptions::send :public, :local_options_file
+ RSpec::Core::ConfigurationOptions::any_instance.stub(:global_options_file) { global_options_file }
+ RSpec::Core::ConfigurationOptions::any_instance.stub(:local_options_file) { local_options_file }
end
after do
ENV["SPEC_OPTS"] = @orig_spec_opts
- RSpec::Core::ConfigurationOptions::__send__ :remove_const, :GLOBAL_OPTIONS_FILE
- RSpec::Core::ConfigurationOptions::__send__ :remove_const, :LOCAL_OPTIONS_FILE
- RSpec::Core::ConfigurationOptions::GLOBAL_OPTIONS_FILE = @orig_global_options_file
- RSpec::Core::ConfigurationOptions::LOCAL_OPTIONS_FILE = @orig_local_options_file
+ RSpec::Core::ConfigurationOptions::send :private, :global_options_file
+ RSpec::Core::ConfigurationOptions::send :private, :local_options_file
end
def write_options(scope, options)
Please sign in to comment.
Something went wrong with that request. Please try again.