Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d4b4a2694a43
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 25e14ae4dcde
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on May 26, 2015

  1. Squashed 'spec/mspec/' changes from 2045fe1..c73601b

    c73601b Add a be_true_or_false matcher.
    658a1bb Remove dependency on FileUtils in MSpec.
    69e72e2 Let mspec know about the conflict between the SpinnerFormatter and MRI 2.0.
    539b558 Report an error when passing a non-existing file to MSpec.
    28f312a Refactor MSpecScript#entries.
    59ffce4 Differentiate an attempt to load a config file from a request (with -B).
    
    git-subtree-dir: spec/mspec
    git-subtree-split: c73601bb55aa17da2c9112e9dd5f0bfc2e3b5e79
    eregon committed May 26, 2015
    Copy the full SHA
    ab00344 View commit details
  2. Copy the full SHA
    25e14ae View commit details
3 changes: 1 addition & 2 deletions spec/mspec/lib/mspec/matchers/output_to_fd.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'mspec/helpers/tmp'
require 'fileutils'

# Lower-level output speccing mechanism for a single
# output stream. Unlike OutputMatcher which provides
@@ -48,7 +47,7 @@ def matches?(block)
# Clean up
ensure
out.close unless out.closed?
FileUtils.rm out.path
File.delete out.path
end

return true
18 changes: 13 additions & 5 deletions spec/mspec/lib/mspec/runner/mspec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'mspec/runner/context'
require 'mspec/runner/exception'
require 'mspec/runner/tag'
require 'fileutils'

module MSpec

@@ -301,12 +300,22 @@ def self.read_tags(keys)
tags
end

def self.make_tag_dir(path)
parent = File.dirname(path)
return if File.exist? parent
begin
Dir.mkdir(parent)
rescue SystemCallError
make_tag_dir(parent)
Dir.mkdir(parent)
end
end

# Writes each tag in +tags+ to the tag file. Overwrites the
# tag file if it exists.
def self.write_tags(tags)
file = tags_file
path = File.dirname file
FileUtils.mkdir_p path unless File.exist? path
make_tag_dir(file)
File.open(file, "wb") do |f|
tags.each { |t| f.puts t }
end
@@ -323,8 +332,7 @@ def self.write_tag(tag)
end

file = tags_file
path = File.dirname file
FileUtils.mkdir_p path unless File.exist? path
make_tag_dir(file)
File.open(file, "ab") { |f| f.puts tag.to_s }
return true
end
39 changes: 25 additions & 14 deletions spec/mspec/lib/mspec/utils/script.rb
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ def config
# Returns +true+ if the file was located in +config[:path]+,
# possibly appending +config[:config_ext]. Returns +false+
# otherwise.
def load(target)
def try_load(target)
names = [target]
unless target[-6..-1] == config[:config_ext]
names << target + config[:config_ext]
@@ -80,20 +80,24 @@ def load(target)
false
end

def load(target)
try_load(target) or abort "Could not load config file #{target}"
end

# Attempts to load a default config file. First tries to load
# 'default.mspec'. If that fails, attempts to load a config
# file name constructed from the value of RUBY_ENGINE and the
# first two numbers in RUBY_VERSION. For example, on MRI 1.8.6,
# the file name would be 'ruby.1.8.mspec'.
def load_default
load 'default.mspec'
try_load 'default.mspec'

if Object.const_defined?(:RUBY_ENGINE)
engine = RUBY_ENGINE
else
engine = 'ruby'
end
load "#{engine}.#{SpecGuard.ruby_version}.mspec"
try_load "#{engine}.#{SpecGuard.ruby_version}.mspec"
end

# Callback for enabling custom options. This version is a no-op.
@@ -106,7 +110,15 @@ def custom_options(options)
# Registers all filters and actions.
def register
if config[:formatter].nil?
config[:formatter] = STDOUT.tty? ? SpinnerFormatter : @files.size < 50 ? DottedFormatter : FileFormatter
# For some unidentified reason, running specs under MRI 2.0
# with the SpinnerFormatter adds a lot of errors.
buggy_spinner_formatter = RUBY_NAME == "ruby" && RUBY_VERSION < "2.1"

if STDOUT.tty? and !buggy_spinner_formatter
config[:formatter] = SpinnerFormatter
else
config[:formatter] = @files.size < 50 ? DottedFormatter : FileFormatter
end
end

if config[:formatter]
@@ -159,26 +171,25 @@ 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]
patterns << file
patterns = [partial, file]
if config[:prefix]
patterns << File.join(config[:prefix], partial)
patterns << File.join(config[:prefix], file)
end

patterns.each do |pattern|
expanded = File.expand_path(pattern)
return [expanded] if File.file?(expanded)

specs = File.join(pattern, "/**/*_spec.rb")
specs = File.expand_path(specs) rescue specs
return Dir[specs].sort if File.directory?(expanded)
if File.file?(expanded)
return [expanded]
elsif File.directory?(expanded)
return Dir["#{expanded}/**/*_spec.rb"].sort
end
end

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

# Resolves each entry in +list+ to a set of files.
@@ -210,7 +221,7 @@ def self.main
$VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
script = new
script.load_default
script.load '~/.mspecrc'
script.try_load '~/.mspecrc'
script.options
script.signals
script.register
7 changes: 5 additions & 2 deletions spec/mspec/spec/commands/mspec_run_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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)

@@ -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
41 changes: 22 additions & 19 deletions spec/mspec/spec/commands/mspec_tag_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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)

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Loading