Skip to content

Commit

Permalink
Better error if RSpec's option parser is accidentally loaded. [#347 s…
Browse files Browse the repository at this point in the history
…tate:invalid]
  • Loading branch information
aslakhellesoy committed May 24, 2009
1 parent b81a83d commit 282d493
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.txt
@@ -1,6 +1,7 @@
== 0.3.8 (Git)

=== New Features
* Better error if RSpec's option parser is "accidentally" loaded. (Aslak Hellesøy)
* Most formatters now report how long a run took (#228 Aslak Hellesøy)
* Scenario and ExampleRow objects (passed to Before and After hooks) have #name and #line methods (#316 Aslak Hellesøy)
* Rails generator creates a cucumber environment file to avoid potential cache_classes conflicts in test.rb (#165, Ben Mabey)
Expand Down
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -326,6 +326,7 @@ lib/cucumber/platform.rb
lib/cucumber/rails/rspec.rb
lib/cucumber/rails/world.rb
lib/cucumber/rake/task.rb
lib/cucumber/rspec_option_parser_detector.rb
lib/cucumber/step_definition.rb
lib/cucumber/step_match.rb
lib/cucumber/step_mother.rb
Expand Down
1 change: 1 addition & 0 deletions bin/cucumber
Expand Up @@ -3,6 +3,7 @@
$:.unshift(File.dirname(__FILE__ + '.rb') + '/../lib') unless $:.include?(File.dirname(__FILE__ + '.rb') + '/../lib')

require 'cucumber/cli/main'
require 'cucumber/rspec_option_parser_detector'
begin
# The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
failure = Cucumber::Cli::Main.execute(ARGV.dup)
Expand Down
6 changes: 3 additions & 3 deletions cucumber.gemspec

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions lib/cucumber/rspec_option_parser_detector.rb
@@ -0,0 +1,40 @@
require 'optparse'

module Spec
module Runner
# Detects if RSpec's option parser is loaded and raises an error
# if it is. (RSpec's option parser tries to parse ARGV, which
# will fail when running cucumber)
class OptionParser < ::OptionParser
def self.bail
raise <<-EOM
RSpec's 'spec/runner/option_parser' should *not* be loaded when you're running
Cucumber, but it seems it was loaded anyway. This is *not* a Cucumber bug.
Some other code is loading more RSpec code than it should. There can be several
reasons for this. The most common ones are:
1) Some of your own code does require 'spec'.
Use require 'spec/expectations' instead.
2) Some of your own code does require 'spec/rails'.
Use require 'spec/rails/expectations' instead.
3) Your Rails app's gem configuration is bad. Use
config.gem 'rspec', :lib => false
config.gem 'rspec-rails', :lib => false
4) Some other library you're using (indirectly)
does require 'spec/runner/option_parser'.
Analyze the stack trace below and get rid of it.
EOM
end

if method_defined?(:options)
bail
end

def self.method_added(*args)
bail
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cucumber/version.rb
Expand Up @@ -3,7 +3,7 @@ class VERSION #:nodoc:
MAJOR = 0
MINOR = 3
TINY = 7
PATCH = 1 # Set to nil for official release
PATCH = 2 # Set to nil for official release

STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
end
Expand Down

0 comments on commit 282d493

Please sign in to comment.