Skip to content

Commit

Permalink
Implement pending spec and improve error message when rspec-1 is loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Nov 10, 2010
1 parent 7016d06 commit 6240273
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
26 changes: 18 additions & 8 deletions lib/rspec/core/configuration.rb
Expand Up @@ -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'?.")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions spec/rspec/core/configuration_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 6240273

Please sign in to comment.