1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/utils/options'
3 require 'mspec/version'
4 require 'mspec/runner/mspec'
5 require 'mspec/runner/formatters'
7 describe MSpecOptions, "#parser" do
8 it "returns an OptionParser instance" do
9 MSpecOptions.new({}, "spec").parser.should be_kind_of(OptionParser)
13 describe "The -B, --config FILE option" do
15 @options, @config = new_option
18 it "is enabled with #add_config { }" do
19 @options.should_receive(:on).with("-B", "--config FILE",
20 String, an_instance_of(String))
21 @options.add_config {}
24 it "calls the passed block" do
25 ["-B", "--config"].each do |opt|
28 @options.add_config { |x| ScratchPad.record x }
29 @options.parse [opt, "file"]
30 ScratchPad.recorded.should == "file"
35 describe "The -n, --name RUBY_NAME option" do
37 @verbose, $VERBOSE = $VERBOSE, nil
38 @options, @config = new_option
45 it "is enabled with #add_name" do
46 @options.should_receive(:on).with("-n", "--name RUBY_NAME",
47 String, an_instance_of(String))
51 it "sets RUBY_NAME when invoked" do
52 Object.should_receive(:const_set).with(:RUBY_NAME, "name").twice
54 @options.parse ["-n", "name"]
55 @options.parse ["--name", "name"]
59 describe "The -t, --target TARGET option" do
61 @options, @config = new_option
65 it "is enabled with #add_targets" do
67 @options.should_receive(:on).with("-t", "--target TARGET",
68 String, an_instance_of(String))
72 it "sets the target to 'ruby' and flags to verbose with TARGET 'ruby'" do
73 ["-t", "--target"].each do |opt|
74 @options.parse [opt, "ruby"]
75 @config[:target].should == "ruby"
76 @config[:flags].should include("-v")
80 it "sets the target to 'ruby19' with TARGET 'r19' or 'ruby19'" do
81 ["-t", "--target"].each do |opt|
82 ["r19", "ruby19"].each do |t|
83 @options.parse [opt, t]
84 @config[:target].should == "ruby19"
89 it "sets the target to 'jruby' with TARGET 'j' or 'jruby'" do
90 ["-t", "--target"].each do |opt|
91 ["j", "jruby"].each do |t|
92 @options.parse [opt, t]
93 @config[:target].should == "jruby"
98 it "sets the target to 'shotgun/rubinius' with TARGET 'x' or 'rubinius'" do
99 ["-t", "--target"].each do |opt|
100 ["x", "rubinius"].each do |t|
101 @options.parse [opt, t]
102 @config[:target].should == "shotgun/rubinius"
107 it "set the target to 'rbx' with TARGET 'rbx'" do
108 ["-t", "--target"].each do |opt|
109 ["X", "rbx"].each do |t|
110 @options.parse [opt, t]
111 @config[:target].should == "rbx"
116 it "sets the target to TARGET" do
117 ["-t", "--target"].each do |opt|
118 @options.parse [opt, "whateva"]
119 @config[:target].should == "whateva"
124 describe "The -T, --target-opt OPT option" do
126 @options, @config = new_option
130 it "is enabled with #add_targets" do
132 @options.should_receive(:on).with("-T", "--target-opt OPT",
133 String, an_instance_of(String))
137 it "adds OPT to flags" do
138 ["-T", "--target-opt"].each do |opt|
139 @config[:flags].delete "--whateva"
140 @options.parse [opt, "--whateva"]
141 @config[:flags].should include("--whateva")
146 describe "The -I, --include DIR option" do
148 @options, @config = new_option
152 it "is enabled with #add_targets" do
154 @options.should_receive(:on).with("-I", "--include DIR",
155 String, an_instance_of(String))
159 it "add DIR to the includes list" do
160 ["-I", "--include"].each do |opt|
161 @config[:includes].delete "-Ipackage"
162 @options.parse [opt, "package"]
163 @config[:includes].should include("-Ipackage")
168 describe "The -r, --require LIBRARY option" do
170 @options, @config = new_option
174 it "is enabled with #add_targets" do
176 @options.should_receive(:on).with("-r", "--require LIBRARY",
177 String, an_instance_of(String))
181 it "adds LIBRARY to the requires list" do
182 ["-r", "--require"].each do |opt|
183 @config[:requires].delete "-rlibrick"
184 @options.parse [opt, "librick"]
185 @config[:requires].should include("-rlibrick")
190 describe "The -f, --format FORMAT option" do
192 @options, @config = new_option
193 @options.add_formatters
196 it "is enabled with #add_formatters" do
198 @options.should_receive(:on).with("-f", "--format FORMAT",
199 String, an_instance_of(String))
200 @options.add_formatters
203 it "sets the SpecdocFormatter with FORMAT 's' or 'specdoc'" do
204 ["-f", "--format"].each do |opt|
205 ["s", "specdoc"].each do |f|
206 @config[:formatter] = nil
207 @options.parse [opt, f]
208 @config[:formatter].should == SpecdocFormatter
213 it "sets the HtmlFormatter with FORMAT 'h' or 'html'" do
214 ["-f", "--format"].each do |opt|
215 ["h", "html"].each do |f|
216 @config[:formatter] = nil
217 @options.parse [opt, f]
218 @config[:formatter].should == HtmlFormatter
223 it "sets the DottedFormatter with FORMAT 'd', 'dot' or 'dotted'" do
224 ["-f", "--format"].each do |opt|
225 ["d", "dot", "dotted"].each do |f|
226 @config[:formatter] = nil
227 @options.parse [opt, f]
228 @config[:formatter].should == DottedFormatter
233 it "sets the UnitdiffFormatter with FORMAT 'u', 'unit', or 'unitdiff'" do
234 ["-f", "--format"].each do |opt|
235 ["u", "unit", "unitdiff"].each do |f|
236 @config[:formatter] = nil
237 @options.parse [opt, f]
238 @config[:formatter].should == UnitdiffFormatter
243 it "sets the SummaryFormatter with FORMAT 'm' or 'summary'" do
244 ["-f", "--format"].each do |opt|
245 ["m", "summary"].each do |f|
246 @config[:formatter] = nil
247 @options.parse [opt, f]
248 @config[:formatter].should == SummaryFormatter
253 it "sets the SpinnerFormatter with FORMAT 'a', '*', or 'spin'" do
254 ["-f", "--format"].each do |opt|
255 ["a", "*", "spin"].each do |f|
256 @config[:formatter] = nil
257 @options.parse [opt, f]
258 @config[:formatter].should == SpinnerFormatter
264 describe "The -o, --output FILE option" do
266 @options, @config = new_option
267 @options.add_formatters
270 it "is enabled with #add_formatters" do
272 @options.should_receive(:on).with("-o", "--output FILE",
273 String, an_instance_of(String))
274 @options.add_formatters
277 it "sets the output to FILE" do
278 ["-o", "--output"].each do |opt|
279 @config[:output] = nil
280 @options.parse [opt, "some/file"]
281 @config[:output].should == "some/file"
286 describe "The -e, --example STR" do
288 @options, @config = new_option
292 it "is enabled with #add_filters" do
294 @options.should_receive(:on).with("-e", "--example STR",
295 String, an_instance_of(String))
299 it "adds STR to the includes list" do
300 ["-e", "--example"].each do |opt|
301 @config[:includes] = []
302 @options.parse [opt, "this spec"]
303 @config[:includes].should include("this spec")
308 describe "The -E, --exclude STR" do
310 @options, @config = new_option
314 it "is enabled with #add_filters" do
316 @options.should_receive(:on).with("-E", "--exclude STR",
317 String, an_instance_of(String))
321 it "adds STR to the excludes list" do
322 ["-E", "--exclude"].each do |opt|
323 @config[:excludes] = []
324 @options.parse [opt, "this spec"]
325 @config[:excludes].should include("this spec")
330 describe "The -p, --pattern PATTERN" do
332 @options, @config = new_option
336 it "is enabled with #add_filters" do
338 @options.should_receive(:on).with("-p", "--pattern PATTERN",
339 Regexp, an_instance_of(String))
343 it "adds PATTERN to the included patterns list" do
344 ["-p", "--pattern"].each do |opt|
345 @config[:patterns] = []
346 @options.parse [opt, "this spec"]
347 @config[:patterns].should include(/this spec/)
352 describe "The -P, --excl-pattern PATTERN" do
354 @options, @config = new_option
358 it "is enabled with #add_filters" do
360 @options.should_receive(:on).with("-P", "--excl-pattern PATTERN",
361 Regexp, an_instance_of(String))
365 it "adds PATTERN to the excluded patterns list" do
366 ["-P", "--excl-pattern"].each do |opt|
367 @config[:xpatterns] = []
368 @options.parse [opt, "this spec"]
369 @config[:xpatterns].should include(/this spec/)
374 describe "The -g, --tag TAG" do
376 @options, @config = new_option
380 it "is enabled with #add_filters" do
382 @options.should_receive(:on).with("-g", "--tag TAG",
383 String, an_instance_of(String))
387 it "adds TAG to the included tags list" do
388 ["-g", "--tag"].each do |opt|
390 @options.parse [opt, "this spec"]
391 @config[:tags].should include("this spec")
396 describe "The -G, --excl-tag TAG" do
398 @options, @config = new_option
402 it "is enabled with #add_filters" do
404 @options.should_receive(:on).with("-G", "--excl-tag TAG",
405 String, an_instance_of(String))
409 it "adds TAG to the excluded tags list" do
410 ["-G", "--excl-tag"].each do |opt|
412 @options.parse [opt, "this spec"]
413 @config[:xtags].should include("this spec")
418 describe "The -w, --profile FILE option" do
420 @options, @config = new_option
424 it "is enabled with #add_filters" do
426 @options.should_receive(:on).with("-w", "--profile FILE",
427 String, an_instance_of(String))
431 it "adds FILE to the included profiles list" do
432 ["-w", "--profile"].each do |opt|
433 @config[:profiles] = []
434 @options.parse [opt, "spec/profiles/rails.yaml"]
435 @config[:profiles].should include("spec/profiles/rails.yaml")
440 describe "The -W, --excl-profile FILE option" do
442 @options, @config = new_option
446 it "is enabled with #add_filters" do
448 @options.should_receive(:on).with("-W", "--excl-profile FILE",
449 String, an_instance_of(String))
453 it "adds FILE to the excluded profiles list" do
454 ["-W", "--excl-profile"].each do |opt|
455 @config[:xprofiles] = []
456 @options.parse [opt, "spec/profiles/rails.yaml"]
457 @config[:xprofiles].should include("spec/profiles/rails.yaml")
462 describe "The -Z", "--dry-run option" do
464 @options, @config = new_option
468 it "is enabled with #add_pretend" do
469 @options.should_receive(:on).with("-Z", "--dry-run", an_instance_of(String))
473 it "registers the MSpec pretend mode" do
474 MSpec.should_receive(:register_mode).with(:pretend).twice
475 ["-Z", "--dry-run"].each do |opt|
481 describe "The -H, --random option" do
483 @options, @config = new_option
484 @options.add_randomize
487 it "is enabled with #add_randomize" do
488 @options.should_receive(:on).with("-H", "--random", an_instance_of(String))
489 @options.add_randomize
492 it "registers the MSpec randomize mode" do
493 MSpec.should_receive(:randomize).twice
494 ["-H", "--random"].each do |opt|
500 describe "The -V, --verbose option" do
502 @options, @config = new_option
506 it "is enabled with #add_verbose" do
508 @options.should_receive(:on).with("-V", "--verbose", an_instance_of(String))
512 it "registers a verbose output object with MSpec" do
513 MSpec.should_receive(:register).with(:start, anything()).twice
514 MSpec.should_receive(:register).with(:load, anything()).twice
515 ["-V", "--verbose"].each do |opt|
521 describe "The -m, --marker MARKER option" do
523 @options, @config = new_option
527 it "is enabled with #add_verbose" do
529 @options.should_receive(:on).with("-m", "--marker MARKER",
530 String, an_instance_of(String))
534 it "registers a marker output object with MSpec" do
535 MSpec.should_receive(:register).with(:load, anything()).twice
536 ["-m", "--marker"].each do |opt|
537 @options.parse [opt, ","]
542 describe "The --int-spec option" do
544 @options, @config = new_option
545 @options.add_interrupt
548 it "is enabled with #add_interrupt" do
549 @options.should_receive(:on).with("--int-spec", an_instance_of(String))
550 @options.add_interrupt
553 it "sets the abort config option to false to only abort the running spec with ^C" do
554 @config[:abort] = true
555 @options.parse "--int-spec"
556 @config[:abort].should == false
560 describe "The -Y, --verify option" do
562 @options, @config = new_option
566 it "is enabled with #add_interrupt" do
568 @options.should_receive(:on).with("-Y", "--verify", an_instance_of(String))
572 it "sets the MSpec mode to :verify" do
573 MSpec.should_receive(:set_mode).with(:verify).twice
574 ["-Y", "--verify"].each do |m|
580 describe "The -O, --report option" do
582 @options, @config = new_option
586 it "is enabled with #add_interrupt" do
588 @options.should_receive(:on).with("-O", "--report", an_instance_of(String))
592 it "sets the MSpec mode to :report" do
593 MSpec.should_receive(:set_mode).with(:report).twice
594 ["-O", "--report"].each do |m|
600 describe "The -N, --add TAG option" do
602 @options, @config = new_option
606 it "is enabled with #add_tagging" do
608 @options.should_receive(:on).with("-N", "--add TAG",
609 String, an_instance_of(String))
613 it "sets the mode to :add and sets the tag to TAG" do
614 ["-N", "--add"].each do |opt|
615 @config[:tagger] = nil
617 @options.parse [opt, "taggit"]
618 @config[:tagger].should == :add
619 @config[:tag].should == "taggit:"
624 describe "The -R, --del TAG option" do
626 @options, @config = new_option
630 it "is enabled with #add_tagging" do
632 @options.should_receive(:on).with("-R", "--del TAG",
633 String, an_instance_of(String))
637 it "it sets the mode to :del, the tag to TAG, and the outcome to :pass" do
638 ["-R", "--del"].each do |opt|
639 @config[:tagger] = nil
641 @config[:outcome] = nil
642 @options.parse [opt, "taggit"]
643 @config[:tagger].should == :del
644 @config[:tag].should == "taggit:"
645 @config[:outcome].should == :pass
650 describe "The -Q, --pass option" do
652 @options, @config = new_option
656 it "is enabled with #add_tagging" do
658 @options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
662 it "sets the outcome to :pass" do
663 ["-Q", "--pass"].each do |opt|
664 @config[:outcome] = nil
666 @config[:outcome].should == :pass
671 describe "The -F, --fail option" do
673 @options, @config = new_option
677 it "is enabled with #add_tagging" do
679 @options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
683 it "sets the outcome to :fail" do
684 ["-F", "--fail"].each do |opt|
685 @config[:outcome] = nil
687 @config[:outcome].should == :fail
692 describe "The -L, --all option" do
694 @options, @config = new_option
698 it "is enabled with #add_tagging" do
700 @options.should_receive(:on).with("-L", "--all", an_instance_of(String))
704 it "sets the outcome to :all" do
705 ["-L", "--all"].each do |opt|
706 @config[:outcome] = nil
708 @config[:outcome].should == :all
713 describe "The -K, --action-tag TAG option" do
715 @options, @config = new_option
716 @options.add_action_filters
719 it "is enabled with #add_action_filters" do
721 @options.should_receive(:on).with("-K", "--action-tag TAG",
722 String, an_instance_of(String))
723 @options.add_action_filters
726 it "adds TAG to the list of tags that trigger actions" do
727 ["-K", "--action-tag"].each do |opt|
729 @options.parse [opt, "action-tag"]
730 @config[:atags].should include("action-tag")
735 describe "The -S, --action-string STR option" do
737 @options, @config = new_option
738 @options.add_action_filters
741 it "is enabled with #add_action_filters" do
743 @options.should_receive(:on).with("-S", "--action-string STR",
744 String, an_instance_of(String))
745 @options.add_action_filters
748 it "adds STR to the list of spec descriptions that trigger actions" do
749 ["-S", "--action-string"].each do |opt|
750 @config[:astrings] = []
751 @options.parse [opt, "action-str"]
752 @config[:astrings].should include("action-str")
757 describe "The --spec-debug option" do
759 @options, @config = new_option
763 it "is enabled with #add_actions" do
765 @options.should_receive(:on).with("--spec-debug", an_instance_of(String))
769 it "enables the triggering the ruby debugger" do
770 @options.add_action_filters
771 @options.parse ["-S", "some spec"]
773 @config[:debugger] = nil
774 @options.parse "--spec-debug"
775 @config[:debugger].should == true
779 describe "The --spec-gdb option" do
781 @options, @config = new_option
785 it "is enabled with #add_actions" do
787 @options.should_receive(:on).with("--spec-gdb", an_instance_of(String))
791 it "enables triggering the gdb debugger" do
792 @options.add_action_filters
793 @options.parse ["-S", "some spec"]
796 @options.parse "--spec-gdb"
797 @config[:gdb].should == true
801 describe "The -v, --version option" do
803 @options, @config = new_option
807 it "is enabled with #add_version" do
809 @options.should_receive(:on).with("-v", "--version", an_instance_of(String))
813 it "prints the version and exits" do
814 @options.should_receive(:puts).twice
815 @options.should_receive(:exit).twice
816 ["-v", "--version"].each do |opt|
822 describe "The -h, --help option" do
824 @options, @config = new_option
828 it "is enabled with #add_help" do
830 @options.should_receive(:on).with("-h", "--help", an_instance_of(String))
834 it "prints help and exits" do
835 @options.should_receive(:puts).twice
836 @options.should_receive(:exit).twice
837 ["-h", "--help"].each do |opt|