Skip to content

Commit

Permalink
Report an error when passing a non-existing file to MSpec.
Browse files Browse the repository at this point in the history
* Otherwise it just silently ignored the pattern.
  • Loading branch information
eregon committed May 25, 2015
1 parent 28f312a commit 539b558
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/mspec/utils/script.rb
Expand Up @@ -163,7 +163,7 @@ def signals
# If it is a directory, returns all *_spec.rb files in the
# directory and subdirectories.
#
# If unable to resolve +partial+, returns <tt>Dir[partial]</tt>.
# If unable to resolve +partial+, +Kernel.abort+ is called.
def entries(partial)
file = partial + "_spec.rb"
patterns = [partial, file]
Expand All @@ -181,7 +181,7 @@ def entries(partial)
end
end

Dir[partial]
abort "Could not find spec file #{partial}"
end

# Resolves each entry in +list+ to a set of files.
Expand Down
7 changes: 5 additions & 2 deletions spec/commands/mspec_run_spec.rb
Expand Up @@ -2,6 +2,9 @@
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
Expand All @@ -16,7 +19,7 @@
before :each do
@stdout, $stdout = $stdout, IOStub.new

@argv = ["a", "b"]
@argv = [one_spec, two_spec]
@options, @config = new_option
MSpecOptions.stub(:new).and_return(@options)

Expand Down Expand Up @@ -50,7 +53,7 @@

it "provides a custom action (block) to the config option" do
@script.should_receive(:load).with("cfg.mspec")
@script.options ["-B", "cfg.mspec", "a"]
@script.options ["-B", "cfg.mspec", one_spec]
end

it "enables the name option" do
Expand Down
41 changes: 22 additions & 19 deletions spec/commands/mspec_tag_spec.rb
Expand Up @@ -5,6 +5,9 @@
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
Expand All @@ -31,7 +34,7 @@
before :each do
@stdout, $stdout = $stdout, IOStub.new

@argv = ["a", "b"]
@argv = [one_spec, two_spec]
@options, @config = new_option
MSpecOptions.stub(:new).and_return(@options)

Expand All @@ -55,7 +58,7 @@

it "provides a custom action (block) to the config option" do
@script.should_receive(:load).with("cfg.mspec")
@script.options ["-B", "cfg.mspec", "a"]
@script.options ["-B", "cfg.mspec", one_spec]
end

it "enables the name option" do
Expand Down Expand Up @@ -123,14 +126,14 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-N", "--add", "TAG", an_instance_of(String))
@script.options ["file.rb"]
@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", "file.rb"]
@script.options [opt, "taggit", one_spec]
@config[:tagger].should == :add
@config[:tag].should == "taggit:"
end
Expand All @@ -142,15 +145,15 @@
@options.stub(:on)
@options.should_receive(:on).with("-R", "--del", "TAG",
an_instance_of(String))
@script.options ["file.rb"]
@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", "file.rb"]
@script.options [opt, "taggit", one_spec]
@config[:tagger].should == :del
@config[:tag].should == "taggit:"
@config[:outcome].should == :pass
Expand All @@ -162,13 +165,13 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-Q", "--pass", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the outcome to :pass" do
["-Q", "--pass"].each do |opt|
@config[:outcome] = nil
@script.options [opt, "file.rb"]
@script.options [opt, one_spec]
@config[:outcome].should == :pass
end
end
Expand All @@ -178,13 +181,13 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-F", "--fail", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the outcome to :fail" do
["-F", "--fail"].each do |opt|
@config[:outcome] = nil
@script.options [opt, "file.rb"]
@script.options [opt, one_spec]
@config[:outcome].should == :fail
end
end
Expand All @@ -194,13 +197,13 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("-L", "--all", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the outcome to :all" do
["-L", "--all"].each do |opt|
@config[:outcome] = nil
@script.options [opt, "file.rb"]
@script.options [opt, one_spec]
@config[:outcome].should == :all
end
end
Expand All @@ -210,18 +213,18 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--list", "TAG", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the mode to :list" do
@config[:tagger] = nil
@script.options ["--list", "TAG", "file.rb"]
@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", "file.rb"]
@script.options ["--list", "TAG", one_spec]
@config[:ltags].should == ["TAG"]
end
end
Expand All @@ -230,12 +233,12 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--list-all", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the mode to :list_all" do
@config[:tagger] = nil
@script.options ["--list-all", "file.rb"]
@script.options ["--list-all", one_spec]
@config[:tagger].should == :list_all
end
end
Expand All @@ -244,12 +247,12 @@
it "is enabled with #options" do
@options.stub(:on)
@options.should_receive(:on).with("--purge", an_instance_of(String))
@script.options ["file.rb"]
@script.options [one_spec]
end

it "sets the mode to :purge" do
@config[:tagger] = nil
@script.options ["--purge", "file.rb"]
@script.options ["--purge", one_spec]
@config[:tagger].should == :purge
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/utils/script_spec.rb
Expand Up @@ -351,9 +351,9 @@ class MSSClass < MSpecScript; end
@script.entries("name").should == ["dir1", "dir2"]
end

it "returns Dir[pattern] if pattern is neither a file nor a directory" do
Dir.should_receive(:[]).with("pattern").and_return(["file1", "file2"])
@script.entries("pattern").should == ["file1", "file2"]
it "aborts if pattern cannot be resolved to a file nor a directory" do
@script.should_receive(:abort)
@script.entries("pattern")
end

describe "with config[:prefix] set" do
Expand All @@ -376,9 +376,9 @@ class MSSClass < MSpecScript; end
@script.entries("name").should == ["dir1", "dir2"]
end

it "returns Dir[pattern] if pattern is neither a file nor a directory" do
Dir.should_receive(:[]).with("pattern").and_return(["file1", "file2"])
@script.entries("pattern").should == ["file1", "file2"]
it "aborts if pattern cannot be resolved to a file nor a directory" do
@script.should_receive(:abort)
@script.entries("pattern")
end
end
end
Expand Down

0 comments on commit 539b558

Please sign in to comment.