From 974e862db9f6c91dc9448570d1a103aad357a6e5 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 28 Oct 2017 15:14:55 +0000 Subject: Update to ruby/mspec@90925d6 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/mspec/.travis.yml | 8 +++--- spec/mspec/lib/mspec/commands/mspec.rb | 3 ++- spec/mspec/lib/mspec/matchers/complain.rb | 34 ++++++++++++++------------ spec/mspec/lib/mspec/matchers/raise_error.rb | 8 +++++- spec/mspec/lib/mspec/runner/context.rb | 2 +- spec/mspec/lib/mspec/utils/script.rb | 34 ++++++++++++++------------ spec/mspec/lib/mspec/utils/warnings.rb | 14 +++++++++-- spec/mspec/spec/commands/mspec_run_spec.rb | 11 ++------- spec/mspec/spec/matchers/raise_error_spec.rb | 12 +++++++++ spec/mspec/spec/mocks/mock_spec.rb | 6 ++--- spec/mspec/spec/runner/filters/profile_spec.rb | 8 +++--- spec/mspec/spec/utils/script_spec.rb | 9 ++++--- 12 files changed, 89 insertions(+), 60 deletions(-) (limited to 'spec/mspec') diff --git a/spec/mspec/.travis.yml b/spec/mspec/.travis.yml index c710e536fc..73f141d2ae 100644 --- a/spec/mspec/.travis.yml +++ b/spec/mspec/.travis.yml @@ -7,12 +7,12 @@ script: - bundle exec rspec matrix: include: - - rvm: 2.2.7 - - rvm: 2.3.4 - - rvm: 2.4.1 + - rvm: 2.2.8 + - rvm: 2.3.5 + - rvm: 2.4.2 - rvm: ruby-head - jdk: oraclejdk8 install: - - curl -L https://github.com/graalvm/truffleruby/releases/download/vm-enterprise-0.27/truffleruby-testing-0.27.tar.gz | tar xz + - curl -L https://github.com/graalvm/truffleruby/releases/download/vm-enterprise-0.28/truffleruby-testing-0.28.tar.gz | tar xz - source truffleruby/setup_env - bundle install diff --git a/spec/mspec/lib/mspec/commands/mspec.rb b/spec/mspec/lib/mspec/commands/mspec.rb index cb1c0fbacb..6cb1e87a58 100755 --- a/spec/mspec/lib/mspec/commands/mspec.rb +++ b/spec/mspec/lib/mspec/commands/mspec.rb @@ -37,7 +37,7 @@ class MSpecMain < MSpecScript options.targets - options.on("--warnings", "Don't supress warnings") do + options.on("--warnings", "Don't suppress warnings") do config[:flags] << '-w' ENV['OUTPUT_WARNINGS'] = '1' end @@ -171,6 +171,7 @@ class MSpecMain < MSpecScript exit multi_exec(argv) else $stderr.puts "$ #{argv.join(' ')}" + $stderr.flush exec(*argv, close_others: false) end end diff --git a/spec/mspec/lib/mspec/matchers/complain.rb b/spec/mspec/lib/mspec/matchers/complain.rb index 71b6a77680..4bcb255040 100644 --- a/spec/mspec/lib/mspec/matchers/complain.rb +++ b/spec/mspec/lib/mspec/matchers/complain.rb @@ -7,44 +7,48 @@ class ComplainMatcher def matches?(proc) @saved_err = $stderr - @stderr = $stderr = IOStub.new @verbose = $VERBOSE - $VERBOSE = false - - proc.call + begin + err = $stderr = IOStub.new + $VERBOSE = false + Thread.current[:in_mspec_complain_matcher] = true + proc.call + ensure + $VERBOSE = @verbose + $stderr = @saved_err + Thread.current[:in_mspec_complain_matcher] = false + end + @warning = err.to_s unless @complaint.nil? case @complaint when Regexp - return false unless $stderr =~ @complaint + return false unless @warning =~ @complaint else - return false unless $stderr == @complaint + return false unless @warning == @complaint end end - return $stderr.empty? ? false : true - ensure - $VERBOSE = @verbose - $stderr = @saved_err + return @warning.empty? ? false : true end def failure_message if @complaint.nil? ["Expected a warning", "but received none"] elsif @complaint.kind_of? Regexp - ["Expected warning to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] else - ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] end end def negative_failure_message if @complaint.nil? - ["Unexpected warning: ", @stderr.chomp.inspect] + ["Unexpected warning: ", @warning.chomp.inspect] elsif @complaint.kind_of? Regexp - ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] else - ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] end end end diff --git a/spec/mspec/lib/mspec/matchers/raise_error.rb b/spec/mspec/lib/mspec/matchers/raise_error.rb index 28c7a5ea2f..2f9afdc687 100644 --- a/spec/mspec/lib/mspec/matchers/raise_error.rb +++ b/spec/mspec/lib/mspec/matchers/raise_error.rb @@ -53,13 +53,19 @@ class RaiseErrorMatcher exception_class_and_message(exception.class, exception.message) end + def format_result(result) + result.pretty_inspect.chomp + rescue => e + "#pretty_inspect raised #{e.class}; A #<#{result.class}>" + end + def failure_message message = ["Expected #{format_expected_exception}"] if @actual message << "but got #{format_exception(@actual)}" else - message << "but no exception was raised (#{@result.pretty_inspect.chomp} was returned)" + message << "but no exception was raised (#{format_result(@result)} was returned)" end message diff --git a/spec/mspec/lib/mspec/runner/context.rb b/spec/mspec/lib/mspec/runner/context.rb index 2b470f226a..30d8a4ad1b 100644 --- a/spec/mspec/lib/mspec/runner/context.rb +++ b/spec/mspec/lib/mspec/runner/context.rb @@ -6,7 +6,7 @@ #-- # A note on naming: this is named _ContextState_ rather # than _DescribeState_ because +describe+ is the keyword -# in the DSL for refering to the context in which an example +# in the DSL for referring to the context in which an example # is evaluated, just as +it+ refers to the example itself. #++ class ContextState diff --git a/spec/mspec/lib/mspec/utils/script.rb b/spec/mspec/lib/mspec/utils/script.rb index 0c8922c4a8..24cd069bb4 100644 --- a/spec/mspec/lib/mspec/utils/script.rb +++ b/spec/mspec/lib/mspec/utils/script.rb @@ -1,4 +1,5 @@ require 'mspec/guards/guard' +require 'mspec/guards/version' require 'mspec/utils/warnings' # MSpecScript provides a skeleton for all the MSpec runner scripts. @@ -38,7 +39,7 @@ class MSpecScript end def initialize - if RUBY_VERSION < '2.2' + ruby_version_is ""..."2.2" do abort "MSpec needs Ruby 2.2 or more recent" end @@ -200,27 +201,30 @@ class MSpecScript abort "Could not find spec file #{partial}" end - # Resolves each entry in +list+ to a set of files. + # Resolves each entry in +patterns+ to a set of files. # - # If the entry has a leading '^' character, the list of files + # If the pattern has a leading '^' character, the list of files # is subtracted from the list of files accumulated to that point. # # If the entry has a leading ':' character, the corresponding # key is looked up in the config object and the entries in the # value retrieved are processed through #entries. - def files(list) - list.inject([]) do |files, item| - case item[0] + def files(patterns) + list = [] + patterns.each do |pattern| + case pattern[0] when ?^ - files -= entries(item[1..-1]) + list -= entries(pattern[1..-1]) when ?: - key = item[1..-1].to_sym - files += files(Array(config[key])) + key = pattern[1..-1].to_sym + value = config[key] + abort "Key #{pattern} not found in mspec config." unless value + list += files(Array(value)) else - files += entries(item) + list += entries(pattern) end - files end + list end def files_from_patterns(patterns) @@ -231,12 +235,10 @@ class MSpecScript if patterns.empty? and File.directory? "./spec" patterns = ["spec/"] end - if patterns.empty? - puts "No files specified." - exit 1 - end end - files patterns + list = files(patterns) + abort "No files specified." if list.empty? + list end def cores(max) diff --git a/spec/mspec/lib/mspec/utils/warnings.rb b/spec/mspec/lib/mspec/utils/warnings.rb index ef5e5c692c..4d23474236 100644 --- a/spec/mspec/lib/mspec/utils/warnings.rb +++ b/spec/mspec/lib/mspec/utils/warnings.rb @@ -1,6 +1,6 @@ require 'mspec/guards/version' -if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0" +if RUBY_ENGINE == "ruby" and ruby_version_is("2.4") ruby_version_is "2.4"..."2.5" do # Kernel#warn does not delegate to Warning.warn in 2.4 module Kernel @@ -16,9 +16,19 @@ if RUBY_ENGINE == "ruby" and RUBY_VERSION >= "2.4.0" end def Warning.warn(message) + if Thread.current[:in_mspec_complain_matcher] + return $stderr.write(message) + end + case message # $VERBOSE = true warnings - when /possibly useless use of (<|<=|==|>=|>|\+|-) in void context/ + when /(.+\.rb):(\d+):.+possibly useless use of (<|<=|==|>=|>) in void context/ + # Make sure there is a .should otherwise it is missing + line_nb = Integer($2) + unless File.exist?($1) and /\.should(_not)? (<|<=|==|>=|>)/ === File.readlines($1)[line_nb-1] + $stderr.write message + end + when /possibly useless use of (\+|-) in void context/ when /assigned but unused variable/ when /method redefined/ when /previous definition of/ diff --git a/spec/mspec/spec/commands/mspec_run_spec.rb b/spec/mspec/spec/commands/mspec_run_spec.rb index 90a42bd62b..fcb44ad5a9 100644 --- a/spec/mspec/spec/commands/mspec_run_spec.rb +++ b/spec/mspec/spec/commands/mspec_run_spec.rb @@ -17,8 +17,6 @@ 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) @@ -27,10 +25,6 @@ describe MSpecRun, "#options" do @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 @@ -114,15 +108,14 @@ describe MSpecRun, "#options" do 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.should_receive(:abort).with("No files specified.") @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.should_receive(:files).with(["spec/"]).and_return(["spec/a_spec.rb"]) @script.options end diff --git a/spec/mspec/spec/matchers/raise_error_spec.rb b/spec/mspec/spec/matchers/raise_error_spec.rb index 88aab34d53..7c93f0f64c 100644 --- a/spec/mspec/spec/matchers/raise_error_spec.rb +++ b/spec/mspec/spec/matchers/raise_error_spec.rb @@ -90,6 +90,18 @@ describe RaiseErrorMatcher do ["Expected ExpectedException (expected)", "but no exception was raised (nil was returned)"] end + it "provides a useful failure message when no exception is raised and the result raises in #pretty_inspect" do + result = Object.new + def result.pretty_inspect + raise ArgumentError, "bad" + end + proc = Proc.new { result } + matcher = RaiseErrorMatcher.new(ExpectedException, "expected") + matcher.matches?(proc) + matcher.failure_message.should == + ["Expected ExpectedException (expected)", "but no exception was raised (#pretty_inspect raised ArgumentError; A # was returned)"] + end + it "provides a useful negative failure message" do proc = Proc.new { raise ExpectedException, "expected" } matcher = RaiseErrorMatcher.new(ExpectedException, "expected") diff --git a/spec/mspec/spec/mocks/mock_spec.rb b/spec/mspec/spec/mocks/mock_spec.rb index d996b5285c..c814ec7bfe 100644 --- a/spec/mspec/spec/mocks/mock_spec.rb +++ b/spec/mspec/spec/mocks/mock_spec.rb @@ -284,21 +284,21 @@ describe Mock, ".verify_call" do ScratchPad.recorded.should == 1 end - it "raises an expection when it is expected to yield but no block is given" do + it "raises an exception when it is expected to yield but no block is given" do @proxy.and_yield(1, 2, 3) lambda { Mock.verify_call(@mock, :method_call) }.should raise_error(SpecExpectationNotMetError) end - it "raises an expection when it is expected to yield more arguments than the block can take" do + it "raises an exception when it is expected to yield more arguments than the block can take" do @proxy.and_yield(1, 2, 3) lambda { Mock.verify_call(@mock, :method_call) {|a, b|} }.should raise_error(SpecExpectationNotMetError) end - it "does not raise an expection when it is expected to yield to a block that can take any number of arguments" do + it "does not raise an exception when it is expected to yield to a block that can take any number of arguments" do @proxy.and_yield(1, 2, 3) expect { Mock.verify_call(@mock, :method_call) {|*a|} diff --git a/spec/mspec/spec/runner/filters/profile_spec.rb b/spec/mspec/spec/runner/filters/profile_spec.rb index 78807bca5c..89d0ad1911 100644 --- a/spec/mspec/spec/runner/filters/profile_spec.rb +++ b/spec/mspec/spec/runner/filters/profile_spec.rb @@ -15,25 +15,25 @@ describe ProfileFilter, "#find" do @filter.find(@file).should == @file end - it "attemps to locate the file in 'spec/profiles'" do + it "attempts to locate the file in 'spec/profiles'" do path = File.join "spec/profiles", @file File.should_receive(:exist?).with(path).and_return(true) @filter.find(@file).should == path end - it "attemps to locate the file in 'spec'" do + it "attempts to locate the file in 'spec'" do path = File.join "spec", @file File.should_receive(:exist?).with(path).and_return(true) @filter.find(@file).should == path end - it "attemps to locate the file in 'profiles'" do + it "attempts to locate the file in 'profiles'" do path = File.join "profiles", @file File.should_receive(:exist?).with(path).and_return(true) @filter.find(@file).should == path end - it "attemps to locate the file in '.'" do + it "attempts to locate the file in '.'" do path = File.join ".", @file File.should_receive(:exist?).with(path).and_return(true) @filter.find(@file).should == path diff --git a/spec/mspec/spec/utils/script_spec.rb b/spec/mspec/spec/utils/script_spec.rb index 20b5d293b0..2582809fae 100644 --- a/spec/mspec/spec/utils/script_spec.rb +++ b/spec/mspec/spec/utils/script_spec.rb @@ -172,7 +172,7 @@ describe MSpecScript, "#load" do @script.load(@base).should == :loaded end - it "attemps to locate the file in '.'" do + it "attempts to locate the file in '.'" do path = File.expand_path @file, "." File.should_receive(:exist?).with(path).and_return(true) Kernel.should_receive(:load).with(path).and_return(:loaded) @@ -186,7 +186,7 @@ describe MSpecScript, "#load" do @script.load(@base).should == :loaded end - it "attemps to locate the file in 'spec'" do + it "attempts to locate the file in 'spec'" do path = File.expand_path @file, "spec" File.should_receive(:exist?).with(path).and_return(true) Kernel.should_receive(:load).with(path).and_return(:loaded) @@ -438,8 +438,9 @@ describe MSpecScript, "#files" do @script.files([":files"]).should == ["file1", "file2"] end - it "returns an empty list if the config key is not set" do - @script.files([":all_files"]).should == [] + it "aborts if the config key is not set" do + @script.should_receive(:abort).with("Key :all_files not found in mspec config.") + @script.files([":all_files"]) end end -- cgit v1.2.3