aboutsummaryrefslogtreecommitdiffstats
path: root/spec/mspec/spec/commands
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/spec/commands')
-rw-r--r--spec/mspec/spec/commands/fixtures/four.txt0
-rw-r--r--spec/mspec/spec/commands/fixtures/level2/three_spec.rb0
-rw-r--r--spec/mspec/spec/commands/fixtures/one_spec.rb0
-rw-r--r--spec/mspec/spec/commands/fixtures/three.rb0
-rw-r--r--spec/mspec/spec/commands/fixtures/two_spec.rb0
-rw-r--r--spec/mspec/spec/commands/mkspec_spec.rb363
-rw-r--r--spec/mspec/spec/commands/mspec_ci_spec.rb155
-rw-r--r--spec/mspec/spec/commands/mspec_run_spec.rb185
-rw-r--r--spec/mspec/spec/commands/mspec_spec.rb215
-rw-r--r--spec/mspec/spec/commands/mspec_tag_spec.rb419
10 files changed, 1337 insertions, 0 deletions
diff --git a/spec/mspec/spec/commands/fixtures/four.txt b/spec/mspec/spec/commands/fixtures/four.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/mspec/spec/commands/fixtures/four.txt
diff --git a/spec/mspec/spec/commands/fixtures/level2/three_spec.rb b/spec/mspec/spec/commands/fixtures/level2/three_spec.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/mspec/spec/commands/fixtures/level2/three_spec.rb
diff --git a/spec/mspec/spec/commands/fixtures/one_spec.rb b/spec/mspec/spec/commands/fixtures/one_spec.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/mspec/spec/commands/fixtures/one_spec.rb
diff --git a/spec/mspec/spec/commands/fixtures/three.rb b/spec/mspec/spec/commands/fixtures/three.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/mspec/spec/commands/fixtures/three.rb
diff --git a/spec/mspec/spec/commands/fixtures/two_spec.rb b/spec/mspec/spec/commands/fixtures/two_spec.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/mspec/spec/commands/fixtures/two_spec.rb
diff --git a/spec/mspec/spec/commands/mkspec_spec.rb b/spec/mspec/spec/commands/mkspec_spec.rb
new file mode 100644
index 0000000000..ab3410af50
--- /dev/null
+++ b/spec/mspec/spec/commands/mkspec_spec.rb
@@ -0,0 +1,363 @@
+require 'spec_helper'
+require 'mspec/commands/mkspec'
+
+
+describe "The -c, --constant CONSTANT option" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MkSpec.new
+ @config = @script.config
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-c", "--constant", "CONSTANT",
+ an_instance_of(String))
+ @script.options []
+ end
+
+ it "adds CONSTANT to the list of constants" do
+ ["-c", "--constant"].each do |opt|
+ @config[:constants] = []
+ @script.options [opt, "Object"]
+ @config[:constants].should include("Object")
+ end
+ end
+end
+
+describe "The -b, --base DIR option" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MkSpec.new
+ @config = @script.config
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-b", "--base", "DIR",
+ an_instance_of(String))
+ @script.options
+ end
+
+ it "sets the base directory relative to which the spec directories are created" do
+ ["-b", "--base"].each do |opt|
+ @config[:base] = nil
+ @script.options [opt, "superspec"]
+ @config[:base].should == File.expand_path("superspec")
+ end
+ end
+end
+
+describe "The -r, --require LIBRARY option" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MkSpec.new
+ @config = @script.config
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-r", "--require", "LIBRARY",
+ an_instance_of(String))
+ @script.options
+ end
+
+ it "adds CONSTANT to the list of constants" do
+ ["-r", "--require"].each do |opt|
+ @config[:requires] = []
+ @script.options [opt, "libspec"]
+ @config[:requires].should include("libspec")
+ end
+ end
+end
+
+describe "The -V, --version-guard VERSION option" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MkSpec.new
+ @config = @script.config
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-V", "--version-guard", "VERSION",
+ an_instance_of(String))
+ @script.options
+ end
+
+ it "sets the version for the ruby_version_is guards to VERSION" do
+ ["-r", "--require"].each do |opt|
+ @config[:requires] = []
+ @script.options [opt, "libspec"]
+ @config[:requires].should include("libspec")
+ end
+ end
+end
+
+describe MkSpec, "#options" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MkSpec.new
+ end
+
+ it "parses the command line options" do
+ @options.should_receive(:parse).with(["--this", "and", "--that"])
+ @script.options ["--this", "and", "--that"]
+ end
+
+ it "parses ARGV unless passed other options" do
+ @options.should_receive(:parse).with(ARGV)
+ @script.options
+ end
+
+ it "prints help and exits if passed an unrecognized option" do
+ @options.should_receive(:raise).with(MSpecOptions::ParseError, an_instance_of(String))
+ @options.stub(:puts)
+ @options.stub(:exit)
+ @script.options "--iunknown"
+ end
+end
+
+describe MkSpec, "#create_directory" do
+ before :each do
+ @script = MkSpec.new
+ @script.config[:base] = "spec"
+ end
+
+ it "prints a warning if a file with the directory name exists" do
+ File.should_receive(:exist?).and_return(true)
+ File.should_receive(:directory?).and_return(false)
+ FileUtils.should_not_receive(:mkdir_p)
+ @script.should_receive(:puts).with("spec/class already exists and is not a directory.")
+ @script.create_directory("Class").should == nil
+ end
+
+ it "does nothing if the directory already exists" do
+ File.should_receive(:exist?).and_return(true)
+ File.should_receive(:directory?).and_return(true)
+ FileUtils.should_not_receive(:mkdir_p)
+ @script.create_directory("Class").should == "spec/class"
+ end
+
+ it "creates the directory if it does not exist" do
+ File.should_receive(:exist?).and_return(false)
+ @script.should_receive(:mkdir_p).with("spec/class")
+ @script.create_directory("Class").should == "spec/class"
+ end
+
+ it "creates the directory for a namespaced module if it does not exist" do
+ File.should_receive(:exist?).and_return(false)
+ @script.should_receive(:mkdir_p).with("spec/struct/tms")
+ @script.create_directory("Struct::Tms").should == "spec/struct/tms"
+ end
+end
+
+describe MkSpec, "#write_requires" do
+ before :each do
+ @script = MkSpec.new
+ @script.config[:base] = "spec"
+
+ @file = double("file")
+ File.stub(:open).and_yield(@file)
+ end
+
+ it "writes the spec_helper require line" do
+ @file.should_receive(:puts).with("require File.expand_path('../../../../spec_helper', __FILE__)")
+ @script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
+ end
+
+ it "writes require lines for each library specified on the command line" do
+ @file.stub(:puts)
+ @file.should_receive(:puts).with("require File.expand_path('../../../../spec_helper', __FILE__)")
+ @file.should_receive(:puts).with("require 'complex'")
+ @script.config[:requires] << 'complex'
+ @script.write_requires("spec/core/tcejbo", "spec/core/tcejbo/inspect_spec.rb")
+ end
+end
+
+describe MkSpec, "#write_spec" do
+ before :each do
+ @file = IOStub.new
+ File.stub(:open).and_yield(@file)
+
+ @script = MkSpec.new
+ @script.stub(:puts)
+
+ @response = double("system command response")
+ @response.stub(:include?).and_return(false)
+ @script.stub(:`).and_return(@response)
+ end
+
+ it "checks if specs exist for the method if the spec file exists" do
+ name = Regexp.escape(@script.ruby)
+ @script.should_receive(:`).with(
+ %r"#{name} #{MSPEC_HOME}/bin/mspec-run --dry-run --unguarded -fs -e 'Object#inspect' spec/core/tcejbo/inspect_spec.rb")
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ end
+
+ it "checks for the method name in the spec file output" do
+ @response.should_receive(:include?).with("Array#[]=")
+ @script.write_spec("spec/core/yarra/element_set_spec.rb", "Array#[]=", true)
+ end
+
+ it "returns nil if the spec file exists and contains a spec for the method" do
+ @response.stub(:include?).and_return(true)
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true).should == nil
+ end
+
+ it "does not print the spec file name if it exists and contains a spec for the method" do
+ @response.stub(:include?).and_return(true)
+ @script.should_not_receive(:puts)
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ end
+
+ it "prints the spec file name if a template spec is written" do
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ end
+
+ it "writes a template spec to the file if the spec file does not exist" do
+ @file.should_receive(:puts).twice
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", false)
+ end
+
+ it "writes a template spec to the file if it exists but contains no spec for the method" do
+ @response.should_receive(:include?).and_return(false)
+ @file.should_receive(:puts).twice
+ @script.should_receive(:puts).with("spec/core/tcejbo/inspect_spec.rb")
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ end
+
+ it "writes a template spec" do
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ @file.should == <<EOS
+
+describe "Object#inspect" do
+ it "needs to be reviewed for spec completeness"
+end
+EOS
+ end
+
+ it "writes a template spec with version guard" do
+ @script.config[:version] = '""..."1.9"'
+ @script.write_spec("spec/core/tcejbo/inspect_spec.rb", "Object#inspect", true)
+ @file.should == <<EOS
+
+ruby_version_is ""..."1.9" do
+ describe "Object#inspect" do
+ it "needs to be reviewed for spec completeness"
+ end
+end
+EOS
+
+ end
+end
+
+describe MkSpec, "#create_file" do
+ before :each do
+ @script = MkSpec.new
+ @script.stub(:write_requires)
+ @script.stub(:write_spec)
+
+ File.stub(:exist?).and_return(false)
+ end
+
+ it "generates a file name based on the directory, class/module, and method" do
+ File.should_receive(:join).with("spec/tcejbo", "inspect_spec.rb"
+ ).and_return("spec/tcejbo/inspect_spec.rb")
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
+ end
+
+ it "does not call #write_requires if the spec file already exists" do
+ File.should_receive(:exist?).and_return(true)
+ @script.should_not_receive(:write_requires)
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
+ end
+
+ it "calls #write_requires if the spec file does not exist" do
+ File.should_receive(:exist?).and_return(false)
+ @script.should_receive(:write_requires).with(
+ "spec/tcejbo", "spec/tcejbo/inspect_spec.rb")
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
+ end
+
+ it "calls #write_spec with the file, method name" do
+ @script.should_receive(:write_spec).with(
+ "spec/tcejbo/inspect_spec.rb", "Object#inspect", false)
+ @script.create_file("spec/tcejbo", "Object", "inspect", "Object#inspect")
+ end
+end
+
+describe MkSpec, "#run" do
+ before :each do
+ @options = MSpecOptions.new
+ MSpecOptions.stub(:new).and_return(@options)
+
+ @map = NameMap.new
+ NameMap.stub(:new).and_return(@map)
+
+ @script = MkSpec.new
+ @script.stub(:create_directory).and_return("spec/mkspec")
+ @script.stub(:create_file)
+ @script.config[:constants] = [MkSpec]
+ end
+
+ it "loads files in the requires list" do
+ @script.stub(:require)
+ @script.should_receive(:require).with("alib")
+ @script.should_receive(:require).with("blib")
+ @script.config[:requires] = ["alib", "blib"]
+ @script.run
+ end
+
+ it "creates a map of constants to methods" do
+ @map.should_receive(:map).with({}, @script.config[:constants]).and_return({})
+ @script.run
+ end
+
+ it "calls #create_directory for each class/module in the map" do
+ @script.should_receive(:create_directory).with("MkSpec").twice
+ @script.run
+ end
+
+ it "calls #create_file for each method on each class/module in the map" do
+ @map.should_receive(:map).with({}, @script.config[:constants]
+ ).and_return({"MkSpec#" => ["run"]})
+ @script.should_receive(:create_file).with("spec/mkspec", "MkSpec", "run", "MkSpec#run")
+ @script.run
+ end
+end
+
+describe MkSpec, ".main" do
+ before :each do
+ @script = double("MkSpec").as_null_object
+ MkSpec.stub(:new).and_return(@script)
+ end
+
+ it "sets MSPEC_RUNNER = '1' in the environment" do
+ ENV["MSPEC_RUNNER"] = "0"
+ MkSpec.main
+ ENV["MSPEC_RUNNER"].should == "1"
+ end
+
+ it "creates an instance of MSpecScript" do
+ MkSpec.should_receive(:new).and_return(@script)
+ MkSpec.main
+ end
+
+ it "calls the #options method on the script" do
+ @script.should_receive(:options)
+ MkSpec.main
+ end
+
+ it "calls the #run method on the script" do
+ @script.should_receive(:run)
+ MkSpec.main
+ end
+end
diff --git a/spec/mspec/spec/commands/mspec_ci_spec.rb b/spec/mspec/spec/commands/mspec_ci_spec.rb
new file mode 100644
index 0000000000..1e8949b0d3
--- /dev/null
+++ b/spec/mspec/spec/commands/mspec_ci_spec.rb
@@ -0,0 +1,155 @@
+require 'spec_helper'
+require 'mspec/runner/mspec'
+require 'mspec/runner/filters/tag'
+require 'mspec/commands/mspec-ci'
+
+describe MSpecCI, "#options" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+
+ @script = MSpecCI.new
+ @script.stub(:config).and_return(@config)
+ @script.stub(:files).and_return([])
+ end
+
+ it "enables the chdir option" do
+ @options.should_receive(:chdir)
+ @script.options
+ end
+
+ it "enables the prefix option" do
+ @options.should_receive(:prefix)
+ @script.options
+ end
+
+ it "enables the config option" do
+ @options.should_receive(:configure)
+ @script.options
+ end
+
+ it "provides a custom action (block) to the config option" do
+ @script.should_receive(:load).with("cfg.mspec")
+ @script.options ["-B", "cfg.mspec"]
+ end
+
+ it "enables the name option" do
+ @options.should_receive(:name)
+ @script.options
+ end
+
+ it "enables the dry run option" do
+ @options.should_receive(:pretend)
+ @script.options
+ end
+
+ it "enables the unguarded option" do
+ @options.should_receive(:unguarded)
+ @script.options
+ end
+
+ it "enables the interrupt single specs option" do
+ @options.should_receive(:interrupt)
+ @script.options
+ end
+
+ it "enables the formatter options" do
+ @options.should_receive(:formatters)
+ @script.options
+ end
+
+ it "enables the verbose option" do
+ @options.should_receive(:verbose)
+ @script.options
+ end
+
+ it "enables the action options" do
+ @options.should_receive(:actions)
+ @script.options
+ end
+
+ it "enables the action filter options" do
+ @options.should_receive(:action_filters)
+ @script.options
+ end
+
+ it "enables the version option" do
+ @options.should_receive(:version)
+ @script.options
+ end
+
+ it "enables the help option" do
+ @options.should_receive(:help)
+ @script.options
+ end
+
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options
+ end
+end
+
+describe MSpecCI, "#run" do
+ before :each do
+ MSpec.stub(:process)
+
+ @filter = double("TagFilter")
+ TagFilter.stub(:new).and_return(@filter)
+ @filter.stub(:register)
+
+ @tags = ["fails", "critical", "unstable", "incomplete", "unsupported"]
+
+ @config = { :ci_files => ["one", "two"] }
+ @script = MSpecCI.new
+ @script.stub(:exit)
+ @script.stub(:config).and_return(@config)
+ @script.stub(:files).and_return(["one", "two"])
+ @script.options
+ end
+
+ it "registers the tags patterns" do
+ @config[:tags_patterns] = [/spec/, "tags"]
+ MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
+ @script.run
+ end
+
+ it "registers the files to process" do
+ MSpec.should_receive(:register_files).with(["one", "two"])
+ @script.run
+ end
+
+ it "registers a tag filter for 'fails', 'unstable', 'incomplete', 'critical', 'unsupported'" do
+ filter = double("fails filter")
+ TagFilter.should_receive(:new).with(:exclude, *@tags).and_return(filter)
+ filter.should_receive(:register)
+ @script.run
+ end
+
+ it "registers an additional exclude tag specified by :ci_xtags" do
+ @config[:ci_xtags] = "windows"
+ filter = double("fails filter")
+ TagFilter.should_receive(:new).with(:exclude, *(@tags + ["windows"])).and_return(filter)
+ filter.should_receive(:register)
+ @script.run
+ end
+
+ it "registers additional exclude tags specified by a :ci_xtags array" do
+ @config[:ci_xtags] = ["windows", "windoze"]
+ filter = double("fails filter")
+ TagFilter.should_receive(:new).with(:exclude,
+ *(@tags + ["windows", "windoze"])).and_return(filter)
+ filter.should_receive(:register)
+ @script.run
+ end
+
+ it "processes the files" do
+ MSpec.should_receive(:process)
+ @script.run
+ end
+
+ it "exits with the exit code registered with MSpec" do
+ MSpec.stub(:exit_code).and_return(7)
+ @script.should_receive(:exit).with(7)
+ @script.run
+ end
+end
diff --git a/spec/mspec/spec/commands/mspec_run_spec.rb b/spec/mspec/spec/commands/mspec_run_spec.rb
new file mode 100644
index 0000000000..4d350cdc02
--- /dev/null
+++ b/spec/mspec/spec/commands/mspec_run_spec.rb
@@ -0,0 +1,185 @@
+require 'spec_helper'
+require 'mspec/runner/mspec'
+require 'mspec/commands/mspec-run'
+
+one_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/one_spec.rb'
+two_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/two_spec.rb'
+
+describe MSpecRun, ".new" do
+ before :each do
+ @script = MSpecRun.new
+ end
+
+ it "sets config[:files] to an empty list" do
+ @script.config[:files].should == []
+ end
+end
+
+describe MSpecRun, "#options" do
+ before :each do
+ @stdout, $stdout = $stdout, IOStub.new
+
+ @argv = [one_spec, two_spec]
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+
+ @script = MSpecRun.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ after :each do
+ $stdout = @stdout
+ end
+
+ it "enables the filter options" do
+ @options.should_receive(:filters)
+ @script.options @argv
+ end
+
+ it "enables the chdir option" do
+ @options.should_receive(:chdir)
+ @script.options @argv
+ end
+
+ it "enables the prefix option" do
+ @options.should_receive(:prefix)
+ @script.options @argv
+ end
+
+ it "enables the configure option" do
+ @options.should_receive(:configure)
+ @script.options @argv
+ end
+
+ it "provides a custom action (block) to the config option" do
+ @script.should_receive(:load).with("cfg.mspec")
+ @script.options ["-B", "cfg.mspec", one_spec]
+ end
+
+ it "enables the name option" do
+ @options.should_receive(:name)
+ @script.options @argv
+ end
+
+ it "enables the randomize option to runs specs in random order" do
+ @options.should_receive(:randomize)
+ @script.options @argv
+ end
+
+ it "enables the dry run option" do
+ @options.should_receive(:pretend)
+ @script.options @argv
+ end
+
+ it "enables the unguarded option" do
+ @options.should_receive(:unguarded)
+ @script.options @argv
+ end
+
+ it "enables the interrupt single specs option" do
+ @options.should_receive(:interrupt)
+ @script.options @argv
+ end
+
+ it "enables the formatter options" do
+ @options.should_receive(:formatters)
+ @script.options @argv
+ end
+
+ it "enables the verbose option" do
+ @options.should_receive(:verbose)
+ @script.options @argv
+ end
+
+ it "enables the verify options" do
+ @options.should_receive(:verify)
+ @script.options @argv
+ end
+
+ it "enables the action options" do
+ @options.should_receive(:actions)
+ @script.options @argv
+ end
+
+ it "enables the action filter options" do
+ @options.should_receive(:action_filters)
+ @script.options @argv
+ end
+
+ it "enables the version option" do
+ @options.should_receive(:version)
+ @script.options @argv
+ end
+
+ it "enables the help option" do
+ @options.should_receive(:help)
+ @script.options @argv
+ end
+
+ it "exits if there are no files to process and './spec' is not a directory" do
+ File.should_receive(:directory?).with("./spec").and_return(false)
+ @options.should_receive(:parse).and_return([])
+ @script.should_receive(:exit)
+ @script.options
+ $stdout.should include "No files specified"
+ end
+
+ it "process 'spec/' if it is a directory and no files were specified" do
+ File.should_receive(:directory?).with("./spec").and_return(true)
+ @options.should_receive(:parse).and_return([])
+ @script.should_receive(:files).with(["spec/"])
+ @script.options
+ end
+
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options @argv
+ end
+end
+
+describe MSpecRun, "#run" do
+ before :each do
+ @script = MSpecRun.new
+ @script.stub(:exit)
+ @spec_dir = File.expand_path(File.dirname(__FILE__)+"/fixtures")
+ @file_patterns = [
+ @spec_dir+"/level2",
+ @spec_dir+"/one_spec.rb",
+ @spec_dir+"/two_spec.rb"]
+ @files = [
+ @spec_dir+"/level2/three_spec.rb",
+ @spec_dir+"/one_spec.rb",
+ @spec_dir+"/two_spec.rb"]
+ @script.options @file_patterns
+ MSpec.stub :process
+ end
+
+ it "registers the tags patterns" do
+ @script.config[:tags_patterns] = [/spec/, "tags"]
+ MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
+ @script.run
+ end
+
+ it "registers the files to process" do
+ MSpec.should_receive(:register_files).with(@files)
+ @script.run
+ end
+
+ it "uses config[:files] if no files are given on the command line" do
+ @script.config[:files] = @file_patterns
+ MSpec.should_receive(:register_files).with(@files)
+ @script.options []
+ @script.run
+ end
+
+ it "processes the files" do
+ MSpec.should_receive(:process)
+ @script.run
+ end
+
+ it "exits with the exit code registered with MSpec" do
+ MSpec.stub(:exit_code).and_return(7)
+ @script.should_receive(:exit).with(7)
+ @script.run
+ end
+end
diff --git a/spec/mspec/spec/commands/mspec_spec.rb b/spec/mspec/spec/commands/mspec_spec.rb
new file mode 100644
index 0000000000..8b8b8fcc41
--- /dev/null
+++ b/spec/mspec/spec/commands/mspec_spec.rb
@@ -0,0 +1,215 @@
+require 'spec_helper'
+require 'yaml'
+require 'mspec/commands/mspec'
+
+describe MSpecMain, "#options" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ @script.stub(:load)
+ end
+
+ it "enables the configure option" do
+ @options.should_receive(:configure)
+ @script.options
+ end
+
+ it "provides a custom action (block) to the config option" do
+ @script.options ["-B", "config"]
+ @config[:options].should include("-B", "config")
+ end
+
+ it "loads the file specified by the config option" do
+ @script.should_receive(:load).with("config")
+ @script.options ["-B", "config"]
+ end
+
+ it "enables the target options" do
+ @options.should_receive(:targets)
+ @script.options
+ end
+
+ it "sets config[:options] to all argv entries that are not registered options" do
+ @options.on "-X", "--exclude", "ARG", "description"
+ @script.options [".", "-G", "fail", "-X", "ARG", "--list", "unstable", "some/file.rb"]
+ @config[:options].should == [".", "-G", "fail", "--list", "unstable", "some/file.rb"]
+ end
+
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options
+ end
+end
+
+describe MSpecMain, "#run" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ @script.stub(:exec)
+ @err = $stderr
+ $stderr = IOStub.new
+ end
+
+ after :each do
+ $stderr = @err
+ end
+
+ it "uses exec to invoke the runner script" do
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.options []
+ @script.run
+ end
+
+ it "shows the command line on stderr" do
+ @script.should_receive(:exec).with("ruby", "#{MSPEC_HOME}/bin/mspec-run")
+ @script.options []
+ @script.run
+ $stderr.to_s.should == "$ ruby #{Dir.pwd}/bin/mspec-run\n"
+ end
+
+ it "adds config[:launch] to the exec options" do
+ @script.should_receive(:exec).with("ruby",
+ "-Xlaunch.option", "#{MSPEC_HOME}/bin/mspec-run")
+ @config[:launch] << "-Xlaunch.option"
+ @script.options []
+ @script.run
+ $stderr.to_s.should == "$ ruby -Xlaunch.option #{Dir.pwd}/bin/mspec-run\n"
+ end
+
+ it "calls #multi_exec if the command is 'ci' and the multi option is passed" do
+ @script.should_receive(:multi_exec).and_return do |argv|
+ argv.should == ["ruby", "#{MSPEC_HOME}/bin/mspec-ci", "-fy"]
+ end
+ @script.options ["ci", "-j"]
+ lambda do
+ @script.run
+ end.should raise_error(SystemExit)
+ end
+end
+
+describe "The --warnings option" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("--warnings", an_instance_of(String))
+ @script.options
+ end
+
+ it "sets flags to -w" do
+ @config[:flags] = []
+ @script.options ["--warnings"]
+ @config[:flags].should include("-w")
+ end
+
+ it "set OUTPUT_WARNINGS = '1' in the environment" do
+ ENV['OUTPUT_WARNINGS'] = '0'
+ @script.options ["--warnings"]
+ ENV['OUTPUT_WARNINGS'].should == '1'
+ end
+end
+
+describe "The -j, --multi option" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-j", "--multi", an_instance_of(String))
+ @script.options
+ end
+
+ it "sets the multiple process option" do
+ ["-j", "--multi"].each do |opt|
+ @config[:multi] = nil
+ @script.options [opt]
+ @config[:multi].should == true
+ end
+ end
+
+ it "sets the formatter to YamlFormatter" do
+ ["-j", "--multi"].each do |opt|
+ @config[:options] = []
+ @script.options [opt]
+ @config[:options].should include("-fy")
+ end
+ end
+end
+
+describe "The -h, --help option" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-h", "--help", an_instance_of(String))
+ @script.options
+ end
+
+ it "passes the option to the subscript" do
+ ["-h", "--help"].each do |opt|
+ @config[:options] = []
+ @script.options ["ci", opt]
+ @config[:options].sort.should == ["-h"]
+ end
+ end
+
+ it "prints help and exits" do
+ @script.should_receive(:puts).twice
+ @script.should_receive(:exit).twice
+ ["-h", "--help"].each do |opt|
+ @script.options [opt]
+ end
+ end
+end
+
+describe "The -v, --version option" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecMain.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ it "is enabled by #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-v", "--version", an_instance_of(String))
+ @script.options
+ end
+
+ it "passes the option to the subscripts" do
+ ["-v", "--version"].each do |opt|
+ @config[:options] = []
+ @script.options ["ci", opt]
+ @config[:options].sort.should == ["-v"]
+ end
+ end
+
+ it "prints the version and exits if no subscript is invoked" do
+ @config[:command] = nil
+ File.stub(:basename).and_return("mspec")
+ @script.should_receive(:puts).twice.with("mspec #{MSpec::VERSION}")
+ @script.should_receive(:exit).twice
+ ["-v", "--version"].each do |opt|
+ @script.options [opt]
+ end
+ end
+end
diff --git a/spec/mspec/spec/commands/mspec_tag_spec.rb b/spec/mspec/spec/commands/mspec_tag_spec.rb
new file mode 100644
index 0000000000..3c2e94db52
--- /dev/null
+++ b/spec/mspec/spec/commands/mspec_tag_spec.rb
@@ -0,0 +1,419 @@
+require 'spec_helper'
+require 'mspec/runner/mspec'
+require 'mspec/commands/mspec-tag'
+require 'mspec/runner/actions/tag'
+require 'mspec/runner/actions/taglist'
+require 'mspec/runner/actions/tagpurge'
+
+one_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/one_spec.rb'
+two_spec = File.expand_path(File.dirname(__FILE__)) + '/fixtures/two_spec.rb'
+
+describe MSpecTag, ".new" do
+ before :each do
+ @script = MSpecTag.new
+ end
+
+ it "sets config[:ltags] to an empty list" do
+ @script.config[:ltags].should == []
+ end
+
+ it "sets config[:tagger] to :add" do
+ @script.config[:tagger] = :add
+ end
+
+ it "sets config[:tag] to 'fails:'" do
+ @script.config[:tag] = 'fails:'
+ end
+
+ it "sets config[:outcome] to :fail" do
+ @script.config[:outcome] = :fail
+ end
+end
+
+describe MSpecTag, "#options" do
+ before :each do
+ @stdout, $stdout = $stdout, IOStub.new
+
+ @argv = [one_spec, two_spec]
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+
+ @script = MSpecTag.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ after :each do
+ $stdout = @stdout
+ end
+
+ it "enables the filter options" do
+ @options.should_receive(:filters)
+ @script.options @argv
+ end
+
+ it "enables the configure option" do
+ @options.should_receive(:configure)
+ @script.options @argv
+ end
+
+ it "provides a custom action (block) to the config option" do
+ @script.should_receive(:load).with("cfg.mspec")
+ @script.options ["-B", "cfg.mspec", one_spec]
+ end
+
+ it "enables the name option" do
+ @options.should_receive(:name)
+ @script.options @argv
+ end
+
+ it "enables the dry run option" do
+ @options.should_receive(:pretend)
+ @script.options @argv
+ end
+
+ it "enables the unguarded option" do
+ @options.should_receive(:unguarded)
+ @script.options @argv
+ end
+
+ it "enables the interrupt single specs option" do
+ @options.should_receive(:interrupt)
+ @script.options @argv
+ end
+
+ it "enables the formatter options" do
+ @options.should_receive(:formatters)
+ @script.options @argv
+ end
+
+ it "enables the verbose option" do
+ @options.should_receive(:verbose)
+ @script.options @argv
+ end
+
+ it "enables the version option" do
+ @options.should_receive(:version)
+ @script.options @argv
+ end
+
+ it "enables the help option" do
+ @options.should_receive(:help)
+ @script.options @argv
+ end
+
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options @argv
+ end
+
+ it "exits if there are no files to process" do
+ @options.should_receive(:parse).and_return([])
+ @script.should_receive(:exit)
+ @script.options
+ $stdout.should include "No files specified"
+ end
+end
+
+describe MSpecTag, "options" do
+ before :each do
+ @options, @config = new_option
+ MSpecOptions.stub(:new).and_return(@options)
+ @script = MSpecTag.new
+ @script.stub(:config).and_return(@config)
+ end
+
+ describe "-N, --add TAG" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-N", "--add", "TAG", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the mode to :add and sets the tag to TAG" do
+ ["-N", "--add"].each do |opt|
+ @config[:tagger] = nil
+ @config[:tag] = nil
+ @script.options [opt, "taggit", one_spec]
+ @config[:tagger].should == :add
+ @config[:tag].should == "taggit:"
+ end
+ end
+ end
+
+ describe "-R, --del TAG" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-R", "--del", "TAG",
+ an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "it sets the mode to :del, the tag to TAG, and the outcome to :pass" do
+ ["-R", "--del"].each do |opt|
+ @config[:tagger] = nil
+ @config[:tag] = nil
+ @config[:outcome] = nil
+ @script.options [opt, "taggit", one_spec]
+ @config[:tagger].should == :del
+ @config[:tag].should == "taggit:"
+ @config[:outcome].should == :pass
+ end
+ end
+ end
+
+ describe "-Q, --pass" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the outcome to :pass" do
+ ["-Q", "--pass"].each do |opt|
+ @config[:outcome] = nil
+ @script.options [opt, one_spec]
+ @config[:outcome].should == :pass
+ end
+ end
+ end
+
+ describe "-F, --fail" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the outcome to :fail" do
+ ["-F", "--fail"].each do |opt|
+ @config[:outcome] = nil
+ @script.options [opt, one_spec]
+ @config[:outcome].should == :fail
+ end
+ end
+ end
+
+ describe "-L, --all" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("-L", "--all", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the outcome to :all" do
+ ["-L", "--all"].each do |opt|
+ @config[:outcome] = nil
+ @script.options [opt, one_spec]
+ @config[:outcome].should == :all
+ end
+ end
+ end
+
+ describe "--list TAG" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("--list", "TAG", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the mode to :list" do
+ @config[:tagger] = nil
+ @script.options ["--list", "TAG", one_spec]
+ @config[:tagger].should == :list
+ end
+
+ it "sets ltags to include TAG" do
+ @config[:tag] = nil
+ @script.options ["--list", "TAG", one_spec]
+ @config[:ltags].should == ["TAG"]
+ end
+ end
+
+ describe "--list-all" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("--list-all", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the mode to :list_all" do
+ @config[:tagger] = nil
+ @script.options ["--list-all", one_spec]
+ @config[:tagger].should == :list_all
+ end
+ end
+
+ describe "--purge" do
+ it "is enabled with #options" do
+ @options.stub(:on)
+ @options.should_receive(:on).with("--purge", an_instance_of(String))
+ @script.options [one_spec]
+ end
+
+ it "sets the mode to :purge" do
+ @config[:tagger] = nil
+ @script.options ["--purge", one_spec]
+ @config[:tagger].should == :purge
+ end
+ end
+end
+
+describe MSpecTag, "#run" do
+ before :each do
+ MSpec.stub(:process)
+
+ options = double("MSpecOptions").as_null_object
+ options.stub(:parse).and_return(["one", "two"])
+ MSpecOptions.stub(:new).and_return(options)
+
+ @config = { }
+ @script = MSpecTag.new
+ @script.stub(:exit)
+ @script.stub(:config).and_return(@config)
+ @script.stub(:files).and_return(["one", "two"])
+ @script.options
+ end
+
+ it "registers the tags patterns" do
+ @config[:tags_patterns] = [/spec/, "tags"]
+ MSpec.should_receive(:register_tags_patterns).with([/spec/, "tags"])
+ @script.run
+ end
+
+ it "registers the files to process" do
+ MSpec.should_receive(:register_files).with(["one", "two"])
+ @script.run
+ end
+
+ it "processes the files" do
+ MSpec.should_receive(:process)
+ @script.run
+ end
+
+ it "exits with the exit code registered with MSpec" do
+ MSpec.stub(:exit_code).and_return(7)
+ @script.should_receive(:exit).with(7)
+ @script.run
+ end
+end
+
+describe MSpecTag, "#register" do
+ before :each do
+ @script = MSpecTag.new
+ @config = @script.config
+ @config[:tag] = "fake:"
+ @config[:atags] = []
+ @config[:astrings] = []
+ @config[:ltags] = ["fails", "unstable"]
+
+ @script.stub(:files).and_return([])
+ @script.options "fake"
+
+ @t = double("TagAction")
+ @t.stub(:register)
+
+ @tl = double("TagListAction")
+ @tl.stub(:register)
+ end
+
+ it "raises an ArgumentError if no recognized action is given" do
+ @config[:tagger] = :totally_whack
+ lambda { @script.register }.should raise_error(ArgumentError)
+ end
+
+ describe "when config[:tagger] is the default (:add)" do
+ before :each do
+ @config[:formatter] = false
+ end
+
+ it "creates a TagAction" do
+ TagAction.should_receive(:new).and_return(@t)
+ @script.register
+ end
+
+ it "creates a TagAction if config[:tagger] is :del" do
+ @config[:tagger] = :del
+ @config[:outcome] = :pass
+ TagAction.should_receive(:new).with(:del, :pass, "fake", nil, [], []).and_return(@t)
+ @script.register
+ end
+
+ it "calls #register on the TagAction instance" do
+ TagAction.should_receive(:new).and_return(@t)
+ @t.should_receive(:register)
+ @script.register
+ end
+ end
+
+ describe "when config[:tagger] is :list" do
+ before :each do
+ TagListAction.should_receive(:new).with(@config[:ltags]).and_return(@tl)
+ @config[:tagger] = :list
+ end
+
+ it "creates a TagListAction" do
+ @tl.should_receive(:register)
+ @script.register
+ end
+
+ it "registers MSpec pretend mode" do
+ MSpec.should_receive(:register_mode).with(:pretend)
+ @script.register
+ end
+
+ it "sets config[:formatter] to false" do
+ @script.register
+ @config[:formatter].should be_false
+ end
+ end
+
+ describe "when config[:tagger] is :list_all" do
+ before :each do
+ TagListAction.should_receive(:new).with(nil).and_return(@tl)
+ @config[:tagger] = :list_all
+ end
+
+ it "creates a TagListAction" do
+ @tl.should_receive(:register)
+ @script.register
+ end
+
+ it "registers MSpec pretend mode" do
+ MSpec.should_receive(:register_mode).with(:pretend)
+ @script.register
+ end
+
+ it "sets config[:formatter] to false" do
+ @script.register
+ @config[:formatter].should be_false
+ end
+ end
+
+ describe "when config[:tagger] is :purge" do
+ before :each do
+ TagPurgeAction.should_receive(:new).and_return(@tl)
+ MSpec.stub(:register_mode)
+ @config[:tagger] = :purge
+ end
+
+ it "creates a TagPurgeAction" do
+ @tl.should_receive(:register)
+ @script.register
+ end
+
+ it "registers MSpec in pretend mode" do
+ MSpec.should_receive(:register_mode).with(:pretend)
+ @script.register
+ end
+
+ it "registers MSpec in unguarded mode" do
+ MSpec.should_receive(:register_mode).with(:unguarded)
+ @script.register
+ end
+
+ it "sets config[:formatter] to false" do
+ @script.register
+ @config[:formatter].should be_false
+ end
+ end
+end