Permalink
Browse files

Implement pending spec and improve error message when rspec-1 is loaded.

  • Loading branch information...
dchelimsky committed Nov 10, 2010
1 parent 7016d06 commit 62402739a3e2f0e29ca025e60c600c1100f21424
Showing with 32 additions and 14 deletions.
  1. +18 −8 lib/rspec/core/configuration.rb
  2. +14 −6 spec/rspec/core/configuration_spec.rb
@@ -217,7 +217,7 @@ def formatter_class
end
def formatter=(formatter_to_use)
- self.formatter_class =
+ self.formatter_class =
built_in_formatter(formatter_to_use) ||
custom_formatter(formatter_to_use) ||
(raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
@@ -332,14 +332,24 @@ def configure_expectation_framework
def load_spec_files
files_to_run.map {|f| load File.expand_path(f) }
- ensure_version_one_is_not_loaded
+ raise_if_rspec_1_is_loaded
end
-
+
private
-
- def ensure_version_one_is_not_loaded
- if Object.constants.include?('Spec') && defined?(Spec::VERSION) && Spec::VERSION::MAJOR.eql?(1)
- raise 'This is RSpec 2, please do not load RSpec 1'
+
+ def raise_if_rspec_1_is_loaded
+ if defined?(Spec::VERSION::MAJOR) && Spec::VERSION::MAJOR == 1
+ raise <<-MESSAGE
+
+#{'*'*80}
+ You are running rspec-2, but it seems as though rspec-1 has been loaded as
+ well. This is likely due to a statement like this somewhere in the specs:
+
+ require 'spec'
+
+ Please locate that statement, remove it, and try again.
+#{'*'*80}
+MESSAGE
end
end
@@ -392,7 +402,7 @@ def path_for(const_ref)
end
def underscore_with_fix_for_non_standard_rspec_naming(string)
- underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
+ underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
end
# activesupport/lib/active_support/inflector/methods.rb, line 48
@@ -7,17 +7,25 @@ module RSpec::Core
let(:config) { subject }
describe "#load_spec_files" do
-
+
it "loads files using load" do
config.files_to_run = ["foo.bar", "blah_spec.rb"]
config.should_receive(:load).twice
config.load_spec_files
end
-
- pending "raises if RSpec 1 is loaded" do
- expect {
- config.load_spec_files
- }.to raise_error('This is RSpec 2, please do not load RSpec 1')
+
+ context "with rspec-1 loaded" do
+ before do
+ Object.const_set(:Spec, Module.new)
+ ::Spec::const_set(:VERSION, Module.new)
+ ::Spec::VERSION::const_set(:MAJOR, 1)
+ end
+ after { Object.__send__(:remove_const, :Spec) }
+ it "raises with a helpful message" do
+ expect {
+ config.load_spec_files
+ }.to raise_error(/rspec-1 has been loaded/)
+ end
end
end

0 comments on commit 6240273

Please sign in to comment.