spec/spec/runner/option_parser_spec.rb in rspec-1.2.8 vs spec/spec/runner/option_parser_spec.rb in rspec-1.2.9

- old
+ new

@@ -1,9 +1,11 @@ -require File.dirname(__FILE__) + '/../../spec_helper.rb' -require File.dirname(__FILE__) + '/resources/custom_example_group_runner' +require 'spec_helper' +require 'spec/runner/resources/custom_example_group_runner' +require 'fakefs/safe' +require 'fakefs/spec_helpers' -describe "OptionParser" do +describe "OptionParser" do before(:each) do @out = StringIO.new @err = StringIO.new @parser = Spec::Runner::OptionParser.new(@err, @out) end @@ -11,10 +13,26 @@ def parse(args) @parser.parse(args) @parser.options end + # FIXME - this entire file should run w/ fakefs + describe "with fakefs" do + extend FakeFS::SpecHelpers + use_fakefs + + it "should not use colour by default" do + options = parse([]) + options.colour.should == false + end + + it "should use progress bar formatter by default" do + options = parse([]) + options.formatters[0].class.should equal(Spec::Runner::Formatter::ProgressBarFormatter) + end + end + it "should leave the submitted argv alone" do args = ["--pattern", "foo"] @parser.order!(args) args.should == ["--pattern", "foo"] end @@ -72,15 +90,10 @@ it "should not be verbose by default" do options = parse([]) options.verbose.should be_nil end - it "should not use colour by default" do - options = parse([]) - options.colour.should == false - end - it "should print help to stdout if no args and spec_comand?" do Spec::Runner::OptionParser.stub!(:spec_command?).and_return(true) options = parse([]) @out.rewind @out.read.should match(/Usage: spec \(FILE\(:LINE\)\?\|DIRECTORY\|GLOB\)\+ \[options\]/m) @@ -183,11 +196,11 @@ it "should use html formatter with explicit output when format is html:test.html" do FileUtils.rm 'test.html' if File.exist?('test.html') options = parse(["--format", "html:test.html"]) options.formatters # creates the file - File.should be_exist('test.html') + File.should exist('test.html') options.formatters[0].class.should equal(Spec::Runner::Formatter::HtmlFormatter) options.formatters[0].close FileUtils.rm 'test.html' end @@ -204,15 +217,10 @@ it "should use quiet backtrace tweaker by default" do options = parse([]) options.backtrace_tweaker.should be_instance_of(Spec::Runner::QuietBacktraceTweaker) end - it "should use progress bar formatter by default" do - options = parse([]) - options.formatters[0].class.should equal(Spec::Runner::Formatter::ProgressBarFormatter) - end - it "should use specdoc formatter when format is s" do options = parse(["--format", "s"]) options.formatters[0].class.should equal(Spec::Runner::Formatter::SpecdocFormatter) end @@ -506,6 +514,32 @@ it "sets options.autospec to true with --autospec" do options = parse(["--autospec"]) options.autospec.should be(true) end + + describe "implicitly loading spec/spec.opts" do + extend FakeFS::SpecHelpers + use_fakefs + it "uses spec/spec.opts if present" do + File.open('spec/spec.opts', 'w') { |f| f.write "--colour" } + options = parse(['ignore.rb']) + options.colour.should be(true) + end + + it "does not try to load spec/spec.opts if not present" do + FileUtils.rm 'spec/spec.opts' + options = parse(['ignore.rb']) + options.colour.should be(false) + end + + it "uses specified opts if supplied" do + options = nil + File.open("spec/spec.opts",'w') { |f| f.write "" } + File.open("spec/alternate.opts",'w') { |f| f.write "--colour" } + options = parse(['-O','spec/alternate.opts']) + options.colour.should be(true) + end + end + + end