ruby-changes:54671
From: eregon <ko1@a...>
Date: Mon, 21 Jan 2019 05:38:32 +0900 (JST)
Subject: [ruby-changes:54671] eregon:r66887 (trunk): Update to ruby/mspec@e9a482d
eregon 2019-01-21 05:38:27 +0900 (Mon, 21 Jan 2019) New Revision: 66887 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66887 Log: Update to ruby/mspec@e9a482d Modified files: trunk/spec/mspec/README.md trunk/spec/mspec/lib/mspec/matchers/complain.rb trunk/spec/mspec/lib/mspec/matchers/raise_error.rb trunk/spec/mspec/lib/mspec/utils/warnings.rb trunk/spec/mspec/spec/matchers/complain_spec.rb trunk/spec/mspec/spec/matchers/raise_error_spec.rb Index: spec/mspec/spec/matchers/raise_error_spec.rb =================================================================== --- spec/mspec/spec/matchers/raise_error_spec.rb (revision 66886) +++ spec/mspec/spec/matchers/raise_error_spec.rb (revision 66887) @@ -74,6 +74,18 @@ describe RaiseErrorMatcher do https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/matchers/raise_error_spec.rb#L74 ["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"] end + it "provides a useful failure message when the proc raises the expected exception with an unexpected message" do + exc = ExpectedException.new("unexpected") + matcher = RaiseErrorMatcher.new(ExpectedException, "expected") + + matcher.matching_exception?(exc).should == false + lambda { + matcher.matches?(Proc.new { raise exc }) + }.should raise_error(ExpectedException) + matcher.failure_message.should == + ["Expected ExpectedException (expected)", "but got ExpectedException (unexpected)"] + end + it "provides a useful failure message when no exception is raised" do proc = Proc.new { 120 } matcher = RaiseErrorMatcher.new(ExpectedException, "expected") Index: spec/mspec/spec/matchers/complain_spec.rb =================================================================== --- spec/mspec/spec/matchers/complain_spec.rb (revision 66886) +++ spec/mspec/spec/matchers/complain_spec.rb (revision 66887) @@ -49,4 +49,49 @@ describe ComplainMatcher do https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/matchers/complain_spec.rb#L49 matcher.negative_failure_message.should == ["Expected warning not to match: /ou/", "but got: \"ouch\""] end + + context "`verbose` option specified" do + before do + $VERBOSE, @verbose = nil, $VERBOSE + end + + after do + $VERBOSE = @verbose + end + + it "sets $VERBOSE with specified second optional parameter" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(nil, verbose: true).matches?(proc) + verbose.should == true + + ComplainMatcher.new(nil, verbose: false).matches?(proc) + verbose.should == false + end + + it "sets $VERBOSE with false by default" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(nil).matches?(proc) + verbose.should == false + end + + it "does not have side effect" do + proc = lambda { safe_value = $VERBOSE } + + lambda do + ComplainMatcher.new(nil, verbose: true).matches?(proc) + end.should_not change { $VERBOSE } + end + + it "accepts a verbose level as single argument" do + verbose = nil + proc = lambda { verbose = $VERBOSE } + + ComplainMatcher.new(verbose: true).matches?(proc) + verbose.should == true + end + end end Index: spec/mspec/README.md =================================================================== --- spec/mspec/README.md (revision 66886) +++ spec/mspec/README.md (revision 66887) @@ -2,13 +2,14 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/README.md#L2 ## Overview -MSpec is a specialized framework that is syntax-compatible with RSpec for -basic things like 'describe', 'it' blocks and 'before', 'after' actions. MSpec -contains additional features that assist in writing the RubySpecs used by -multiple Ruby implementations. +MSpec is a specialized framework that is syntax-compatible with RSpec 2 for +basic things like `describe`, `it` blocks and `before`, `after` actions. +MSpec contains additional features that assist in writing specs for +Ruby implementations in [ruby/spec](https://github.com/ruby/spec). MSpec attempts to use the simplest Ruby language features so that beginning -Ruby implementations can run the Ruby specs. +Ruby implementations can run the Ruby specs. For example, no file from the +standard library or RubyGems is necessary to run MSpec. MSpec is not intended as a replacement for RSpec. MSpec attempts to provide a subset of RSpec's features in some cases and a superset in others. It does not @@ -23,8 +24,6 @@ specs in a manner compatible with multip https://github.com/ruby/ruby/blob/trunk/spec/mspec/README.md#L24 2. MSpec provides a different shared spec implementation specifically designed to ease writing specs for the numerous aliased methods in Ruby. - The MSpec shared spec implementation should not conflict with RSpec's own - shared behavior facility. 3. MSpec provides various helper methods to simplify some specs, for example, creating temporary file names. @@ -33,6 +32,10 @@ specs in a manner compatible with multip https://github.com/ruby/ruby/blob/trunk/spec/mspec/README.md#L32 configuration facility with a default project file and user-specific overrides. + 5. MSpec support "tagging", that is excluding specs known as failing on + a particular Ruby implementation, and automatically adding and removing tags + while running the specs. + ## Requirements MSpec requires Ruby 2.3 or more recent. @@ -63,29 +66,21 @@ After installing the gem dependencies, t https://github.com/ruby/ruby/blob/trunk/spec/mspec/README.md#L66 ruby -S bundle exec rspec ``` -Or - -```bash -ruby -S rake -``` - To run an individual spec file, use the following example: ```bash ruby -S bundle exec rspec spec/helpers/ruby_exe_spec.rb ``` - ## Documentation -See http://ruby.github.io/rubyspec.github.io/ - +See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) in ruby/spec +for a list of matchers and how to use `mspec`. ## Source Code See https://github.com/ruby/mspec - ## License See the LICENSE in the source code. Index: spec/mspec/lib/mspec/matchers/complain.rb =================================================================== --- spec/mspec/lib/mspec/matchers/complain.rb (revision 66886) +++ spec/mspec/lib/mspec/matchers/complain.rb (revision 66887) @@ -1,8 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/complain.rb#L1 require 'mspec/helpers/io' class ComplainMatcher - def initialize(complaint) - @complaint = complaint + def initialize(complaint = nil, options = nil) + # the proper solution is to use double splat operator e.g. + # def initialize(complaint = nil, **options) + # but we are trying to minimize language features required to run MSpec + if complaint.is_a?(Hash) + @complaint = nil + @options = complaint + else + @complaint = complaint + @options = options || {} + end end def matches?(proc) @@ -10,7 +19,7 @@ class ComplainMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/complain.rb#L19 @verbose = $VERBOSE begin err = $stderr = IOStub.new - $VERBOSE = false + $VERBOSE = @options.key?(:verbose) ? @options[:verbose] : false Thread.current[:in_mspec_complain_matcher] = true proc.call ensure @@ -54,7 +63,7 @@ class ComplainMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/complain.rb#L63 end module MSpecMatchers - private def complain(complaint=nil) - ComplainMatcher.new(complaint) + private def complain(complaint = nil, options = nil) + ComplainMatcher.new(complaint, options) end end Index: spec/mspec/lib/mspec/matchers/raise_error.rb =================================================================== --- spec/mspec/lib/mspec/matchers/raise_error.rb (revision 66886) +++ spec/mspec/lib/mspec/matchers/raise_error.rb (revision 66887) @@ -12,6 +12,9 @@ class RaiseErrorMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L12 rescue Exception => actual @actual = actual if matching_exception?(actual) + # The block has its own expectations and will throw an exception if it fails + @block[actual] if @block + return true else raise actual @@ -20,6 +23,7 @@ class RaiseErrorMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L23 def matching_exception?(exc) return false unless @exception === exc + if @message then case @message when String @@ -29,9 +33,6 @@ class RaiseErrorMatcher https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/raise_error.rb#L33 end end - # The block has its own expectations and will throw an exception if it fails - @block[exc] if @block - return true end Index: spec/mspec/lib/mspec/utils/warnings.rb =================================================================== --- spec/mspec/lib/mspec/utils/warnings.rb (revision 66886) +++ spec/mspec/lib/mspec/utils/warnings.rb (revision 66887) @@ -51,7 +51,7 @@ if RUBY_ENGINE == "ruby" and ruby_versio https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/utils/warnings.rb#L51 when /hash\/shared\/index\.rb:\d+: warning: Hash#index is deprecated; use Hash#key/ when /env\/shared\/key\.rb:\d+: warning: ENV\.index is deprecated; use ENV\.key/ when /exponent(_spec)?\.rb:\d+: warning: in a\*\*b, b may be too big/ - when /enumerator\/(new|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/ + when /enumerator\/(new_spec|initialize_spec)\.rb:\d+: warning: Enumerator\.new without a block is deprecated/ else $stderr.write message end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/