ruby-changes:58016
From: Benoit <ko1@a...>
Date: Sun, 29 Sep 2019 23:04:59 +0900 (JST)
Subject: [ruby-changes:58016] 31bb66a19d (master): Update to ruby/mspec@8106083
https://git.ruby-lang.org/ruby.git/commit/?id=31bb66a19d From 31bb66a19df26409c9d47afcf37919c9a065516a Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Sun, 29 Sep 2019 16:03:47 +0200 Subject: Update to ruby/mspec@8106083 diff --git a/spec/mspec/README.md b/spec/mspec/README.md index 5a4605d..e6fe44c 100644 --- a/spec/mspec/README.md +++ b/spec/mspec/README.md @@ -58,7 +58,7 @@ ruby -S bundle install https://github.com/ruby/ruby/blob/trunk/spec/mspec/README.md#L58 ## Running Specs Use RSpec to run the MSpec specs. There are no plans currently to make the -MSpec specs runnable by MSpec. +MSpec specs runnable by MSpec: https://github.com/ruby/mspec/issues/19. After installing the gem dependencies, the specs can be run as follows: diff --git a/spec/mspec/lib/mspec.rb b/spec/mspec/lib/mspec.rb index 42d590c..d24abd9 100644 --- a/spec/mspec/lib/mspec.rb +++ b/spec/mspec/lib/mspec.rb @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec.rb#L1 +require 'mspec/utils/format' require 'mspec/matchers' require 'mspec/expectations' require 'mspec/mocks' @@ -5,16 +6,3 @@ require 'mspec/runner' https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec.rb#L6 require 'mspec/guards' require 'mspec/helpers' require 'mspec/version' - -# If the implementation on which the specs are run cannot -# load pp from the standard library, add a pp.rb file that -# defines the #pretty_inspect method on Object or Kernel. -begin - require 'pp' -rescue LoadError - module Kernel - def pretty_inspect - inspect - end - end -end diff --git a/spec/mspec/lib/mspec/commands/mspec-ci.rb b/spec/mspec/lib/mspec/commands/mspec-ci.rb index cb0193f..2882613 100644 --- a/spec/mspec/lib/mspec/commands/mspec-ci.rb +++ b/spec/mspec/lib/mspec/commands/mspec-ci.rb @@ -24,6 +24,7 @@ class MSpecCI < MSpecScript https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/commands/mspec-ci.rb#L24 options.configure { |f| load f } options.pretend options.interrupt + options.timeout options.doc "\n How to modify the guard behavior" options.unguarded diff --git a/spec/mspec/lib/mspec/commands/mspec-run.rb b/spec/mspec/lib/mspec/commands/mspec-run.rb index 249f9f5..1e62bf2 100644 --- a/spec/mspec/lib/mspec/commands/mspec-run.rb +++ b/spec/mspec/lib/mspec/commands/mspec-run.rb @@ -36,6 +36,7 @@ class MSpecRun < MSpecScript https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/commands/mspec-run.rb#L36 options.repeat options.pretend options.interrupt + options.timeout options.doc "\n How to modify the guard behavior" options.unguarded diff --git a/spec/mspec/lib/mspec/commands/mspec-tag.rb b/spec/mspec/lib/mspec/commands/mspec-tag.rb index 8bc3382..f5d8502 100644 --- a/spec/mspec/lib/mspec/commands/mspec-tag.rb +++ b/spec/mspec/lib/mspec/commands/mspec-tag.rb @@ -33,6 +33,7 @@ class MSpecTag < MSpecScript https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/commands/mspec-tag.rb#L33 options.pretend options.unguarded options.interrupt + options.timeout options.doc "\n How to display their output" options.formatters diff --git a/spec/mspec/lib/mspec/expectations/expectations.rb b/spec/mspec/lib/mspec/expectations/expectations.rb index cfdc2b6..b42dfeb 100644 --- a/spec/mspec/lib/mspec/expectations/expectations.rb +++ b/spec/mspec/lib/mspec/expectations/expectations.rb @@ -12,10 +12,21 @@ class SpecExpectation https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/expectations/expectations.rb#L12 expected_to_s = expected.to_s actual_to_s = actual.to_s if expected_to_s.size + actual_to_s.size > 80 - message = "#{expected_to_s.chomp}\n#{actual_to_s}" + message = "#{expected_to_s}\n#{actual_to_s}" else message = "#{expected_to_s} #{actual_to_s}" end - Kernel.raise SpecExpectationNotMetError, message + raise SpecExpectationNotMetError, message + end + + def self.fail_predicate(receiver, predicate, args, block, result, expectation) + receiver_to_s = MSpec.format(receiver) + before_method = predicate.to_s =~ /^[a-z]/ ? "." : " " + predicate_to_s = "#{before_method}#{predicate}" + predicate_to_s += " " unless args.empty? + args_to_s = args.map { |arg| MSpec.format(arg) }.join(', ') + args_to_s += " { ... }" if block + result_to_s = MSpec.format(result) + raise SpecExpectationNotMetError, "Expected #{receiver_to_s}#{predicate_to_s}#{args_to_s}\n#{expectation} but was #{result_to_s}" end end diff --git a/spec/mspec/lib/mspec/expectations/should.rb b/spec/mspec/lib/mspec/expectations/should.rb index f6d8305..231ad15 100644 --- a/spec/mspec/lib/mspec/expectations/should.rb +++ b/spec/mspec/lib/mspec/expectations/should.rb @@ -4,26 +4,26 @@ class Object https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/expectations/should.rb#L4 def should(matcher = NO_MATCHER_GIVEN) MSpec.expectation MSpec.actions :expectation, MSpec.current.state - unless matcher.equal? NO_MATCHER_GIVEN + if NO_MATCHER_GIVEN.equal?(matcher) + SpecPositiveOperatorMatcher.new(self) + else unless matcher.matches? self expected, actual = matcher.failure_message SpecExpectation.fail_with(expected, actual) end - else - SpecPositiveOperatorMatcher.new(self) end end def should_not(matcher = NO_MATCHER_GIVEN) MSpec.expectation MSpec.actions :expectation, MSpec.current.state - unless matcher.equal? NO_MATCHER_GIVEN + if NO_MATCHER_GIVEN.equal?(matcher) + SpecNegativeOperatorMatcher.new(self) + else if matcher.matches? self expected, actual = matcher.negative_failure_message SpecExpectation.fail_with(expected, actual) end - else - SpecNegativeOperatorMatcher.new(self) end end end diff --git a/spec/mspec/lib/mspec/helpers/io.rb b/spec/mspec/lib/mspec/helpers/io.rb index f2c799d..d12d4b6 100644 --- a/spec/mspec/lib/mspec/helpers/io.rb +++ b/spec/mspec/lib/mspec/helpers/io.rb @@ -78,8 +78,12 @@ end https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/helpers/io.rb#L78 # Creates an IO instance for a temporary file name. The file # must be deleted. -def new_io(name, mode="w:utf-8") - IO.new new_fd(name, mode), mode +def new_io(name, mode = "w:utf-8") + if Hash === mode # Avoid kwargs warnings on Ruby 2.7+ + File.new(name, **mode) + else + File.new(name, mode) + end end def find_unused_fd diff --git a/spec/mspec/lib/mspec/helpers/warning.rb b/spec/mspec/lib/mspec/helpers/warning.rb index 9e09307..f54e4ab 100644 --- a/spec/mspec/lib/mspec/helpers/warning.rb +++ b/spec/mspec/lib/mspec/helpers/warning.rb @@ -5,3 +5,13 @@ def suppress_warning https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/helpers/warning.rb#L5 ensure $VERBOSE = verbose end + +if ruby_version_is("2.7") + def suppress_keyword_warning(&block) + suppress_warning(&block) + end +else + def suppress_keyword_warning + yield + end +end diff --git a/spec/mspec/lib/mspec/matchers/base.rb b/spec/mspec/lib/mspec/matchers/base.rb index fc2d36c..94d3b71 100644 --- a/spec/mspec/lib/mspec/matchers/base.rb +++ b/spec/mspec/lib/mspec/matchers/base.rb @@ -10,98 +10,52 @@ class Module https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/base.rb#L10 include MSpecMatchers end -class SpecPositiveOperatorMatcher +class SpecPositiveOperatorMatcher < BasicObject def initialize(actual) @actual = actual end def ==(expected) - unless @actual == expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to equal #{expected.pretty_inspect}") - end + method_missing(:==, expected) end - def <(expected) - unless @actual < expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to be less than #{expected.pretty_inspect}") - end - end - - def <=(expected) - unless @actual <= expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to be less than or equal to #{expected.pretty_inspect}") - end + def !=(expected) + method_missing(:!=, expected) end - def >(expected) - unless @actual > expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to be greater than #{expected.pretty_inspect}") - end - end - - def >=(expected) - unless @actual >= expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to be greater than or equal to #{expected.pretty_inspect}") - end + def equal?(expected) + method_missing(:equal?, expected) end - def =~(expected) - unless @actual =~ expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "to match #{expected.pretty_inspect}") + def method_missing(name, *args, &block) + result = @actual.__send__(name, *args, &block) + unless result + ::SpecExpectation.fail_predicate(@actual, name, args, block, result, "to be truthy") end end end -class SpecNegativeOperatorMatcher +class SpecNegativeOperatorMatcher < BasicObject def initialize(actual) @actual = actual end def ==(expected) - if @actual == expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "not to equal #{expected.pretty_inspect}") - end + method_missing(:==, expected) end - def <(expected) - if @actual < expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "not to be less than #{expected.pretty_inspect}") - end - end - - def <=(expected) - if @actual <= expected - SpecExpectation.fail_with("Expected #{@actual.pretty_inspect}", - "not to be less than or equal to #{expected.pretty_inspect}") - (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/