[前][次][番号順一覧][スレッド一覧]

ruby-changes:47316

From: eregon <ko1@a...>
Date: Thu, 27 Jul 2017 21:10:29 +0900 (JST)
Subject: [ruby-changes:47316] eregon:r59430 (trunk): Update to ruby/mspec@353605f

eregon	2017-07-27 21:10:23 +0900 (Thu, 27 Jul 2017)

  New Revision: 59430

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59430

  Log:
    Update to ruby/mspec@353605f

  Added files:
    trunk/spec/mspec/tool/find.rb
  Removed files:
    trunk/spec/mspec/tool/sync/sync.yml
  Modified files:
    trunk/spec/mspec/lib/mspec/guards/guard.rb
    trunk/spec/mspec/lib/mspec/matchers/base.rb
    trunk/spec/mspec/lib/mspec/utils/script.rb
    trunk/spec/mspec/spec/guards/guard_spec.rb
    trunk/spec/mspec/spec/guards/platform_spec.rb
    trunk/spec/mspec/spec/guards/version_spec.rb
Index: spec/mspec/tool/sync/sync.yml
===================================================================
--- spec/mspec/tool/sync/sync.yml	(revision 59429)
+++ spec/mspec/tool/sync/sync.yml	(nonexistent)
@@ -1,4 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/tool/sync/sync.yml#L0
-mri: 4e95b8c265d4d365477a05fe6701186415576303
-truffleruby: c8fb3e592bf354cd67893555c671955cc54c32ff
-jruby: d834e4279090998ba3ef087d81278734cab4c50a
-rbx: 7799d9fa48467cdbfceeed6765a63366d9dc8b0e
Index: spec/mspec/lib/mspec/utils/script.rb
===================================================================
--- spec/mspec/lib/mspec/utils/script.rb	(revision 59429)
+++ spec/mspec/lib/mspec/utils/script.rb	(revision 59430)
@@ -234,7 +234,7 @@ class MSpecScript https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/utils/script.rb#L234
     files patterns
   end
 
-  def cores(max = 1)
+  def cores(max)
     require 'etc'
     [Etc.nprocessors, max].min
   end
Index: spec/mspec/lib/mspec/guards/guard.rb
===================================================================
--- spec/mspec/lib/mspec/guards/guard.rb	(revision 59429)
+++ spec/mspec/lib/mspec/guards/guard.rb	(revision 59430)
@@ -76,14 +76,22 @@ class SpecGuard https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/guards/guard.rb#L76
 
   def run_if(name, &block)
     @name = name
-    yield if yield?(false)
+    if block
+      yield if yield?(false)
+    else
+      yield?(false)
+    end
   ensure
     unregister
   end
 
   def run_unless(name, &block)
     @name = name
-    yield if yield?(true)
+    if block
+      yield if yield?(true)
+    else
+      yield?(true)
+    end
   ensure
     unregister
   end
@@ -115,3 +123,19 @@ class SpecGuard https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/guards/guard.rb#L123
     raise "must be implemented by the subclass"
   end
 end
+
+# Combined guards
+
+def guard(condition, &block)
+  raise "condition must be a Proc" unless condition.is_a?(Proc)
+  raise LocalJumpError, "no block given" unless block
+  return yield if MSpec.mode? :unguarded or MSpec.mode? :verify or MSpec.mode? :report
+  yield if condition.call
+end
+
+def guard_not(condition, &block)
+  raise "condition must be a Proc" unless condition.is_a?(Proc)
+  raise LocalJumpError, "no block given" unless block
+  return yield if MSpec.mode? :unguarded or MSpec.mode? :verify or MSpec.mode? :report
+  yield unless condition.call
+end
Index: spec/mspec/lib/mspec/matchers/base.rb
===================================================================
--- spec/mspec/lib/mspec/matchers/base.rb	(revision 59429)
+++ spec/mspec/lib/mspec/matchers/base.rb	(revision 59430)
@@ -5,7 +5,7 @@ class MSpecEnv https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/base.rb#L5
   include MSpecMatchers
 end
 
-# Expactations are sometimes used in a module body
+# Expectations are sometimes used in a module body
 class Module
   include MSpecMatchers
 end
Index: spec/mspec/spec/guards/guard_spec.rb
===================================================================
--- spec/mspec/spec/guards/guard_spec.rb	(revision 59429)
+++ spec/mspec/spec/guards/guard_spec.rb	(revision 59430)
@@ -178,3 +178,249 @@ SomeClass#reverse returns false https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/guards/guard_spec.rb#L178
 ]
   end
 end
+
+describe SpecGuard, ".run_if" do
+  before :each do
+    @guard = SpecGuard.new
+    ScratchPad.clear
+  end
+
+  it "yields if match? returns true" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_if(:name) { ScratchPad.record :yield }
+    ScratchPad.recorded.should == :yield
+  end
+
+  it "does not yield if match? returns false" do
+    @guard.stub(:match?).and_return(false)
+    @guard.run_if(:name) { fail }
+  end
+
+  it "returns the result of the block if match? is true" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_if(:name) { 42 }.should == 42
+  end
+
+  it "returns nil if given a block and match? is false" do
+    @guard.stub(:match?).and_return(false)
+    @guard.run_if(:name) { 42 }.should == nil
+  end
+
+  it "returns what #match? returns when no block is given" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_if(:name).should == true
+    @guard.stub(:match?).and_return(false)
+    @guard.run_if(:name).should == false
+  end
+end
+
+describe SpecGuard, ".run_unless" do
+  before :each do
+    @guard = SpecGuard.new
+    ScratchPad.clear
+  end
+
+  it "yields if match? returns false" do
+    @guard.stub(:match?).and_return(false)
+    @guard.run_unless(:name) { ScratchPad.record :yield }
+    ScratchPad.recorded.should == :yield
+  end
+
+  it "does not yield if match? returns true" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_unless(:name) { fail }
+  end
+
+  it "returns the result of the block if match? is false" do
+    @guard.stub(:match?).and_return(false)
+    @guard.run_unless(:name) { 42 }.should == 42
+  end
+
+  it "returns nil if given a block and match? is true" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_unless(:name) { 42 }.should == nil
+  end
+
+  it "returns the opposite of what #match? returns when no block is given" do
+    @guard.stub(:match?).and_return(true)
+    @guard.run_unless(:name).should == false
+    @guard.stub(:match?).and_return(false)
+    @guard.run_unless(:name).should == true
+  end
+end
+
+describe Object, "#guard" do
+  before :each do
+    ScratchPad.clear
+  end
+
+  after :each do
+    MSpec.clear_modes
+  end
+
+  it "allows to combine guards" do
+    guard1 = VersionGuard.new 'x.x.x'
+    VersionGuard.stub(:new).and_return(guard1)
+    guard2 = PlatformGuard.new :dummy
+    PlatformGuard.stub(:new).and_return(guard2)
+
+    guard1.stub(:match?).and_return(true)
+    guard2.stub(:match?).and_return(true)
+    guard -> { ruby_version_is "2.4" and platform_is :linux } do
+      ScratchPad.record :yield
+    end
+    ScratchPad.recorded.should == :yield
+
+    guard1.stub(:match?).and_return(false)
+    guard2.stub(:match?).and_return(true)
+    guard -> { ruby_version_is "2.4" and platform_is :linux } do
+      fail
+    end
+
+    guard1.stub(:match?).and_return(true)
+    guard2.stub(:match?).and_return(false)
+    guard -> { ruby_version_is "2.4" and platform_is :linux } do
+      fail
+    end
+
+    guard1.stub(:match?).and_return(false)
+    guard2.stub(:match?).and_return(false)
+    guard -> { ruby_version_is "2.4" and platform_is :linux } do
+      fail
+    end
+  end
+
+  it "yields when the Proc returns true" do
+    guard -> { true } do
+      ScratchPad.record :yield
+    end
+    ScratchPad.recorded.should == :yield
+  end
+
+  it "does not yield when the Proc returns false" do
+    guard -> { false } do
+      fail
+    end
+  end
+
+  it "yields if MSpec.mode?(:unguarded) is true" do
+    MSpec.register_mode :unguarded
+
+    guard -> { false } do
+      ScratchPad.record :yield1
+    end
+    ScratchPad.recorded.should == :yield1
+
+    guard -> { true } do
+      ScratchPad.record :yield2
+    end
+    ScratchPad.recorded.should == :yield2
+  end
+
+  it "yields if MSpec.mode?(:verify) is true" do
+    MSpec.register_mode :verify
+
+    guard -> { false } do
+      ScratchPad.record :yield1
+    end
+    ScratchPad.recorded.should == :yield1
+
+    guard -> { true } do
+      ScratchPad.record :yield2
+    end
+    ScratchPad.recorded.should == :yield2
+  end
+
+  it "yields if MSpec.mode?(:report) is true" do
+    MSpec.register_mode :report
+
+    guard -> { false } do
+      ScratchPad.record :yield1
+    end
+    ScratchPad.recorded.should == :yield1
+
+    guard -> { true } do
+      ScratchPad.record :yield2
+    end
+    ScratchPad.recorded.should == :yield2
+  end
+
+  it "raises an error if no Proc is given" do
+    -> { guard :foo }.should raise_error(RuntimeError)
+  end
+
+  it "requires a block" do
+    -> {
+      guard(-> { true })
+    }.should raise_error(LocalJumpError)
+    -> {
+      guard(-> { false })
+    }.should raise_error(LocalJumpError)
+  end
+end
+
+describe Object, "#guard_not" do
+  before :each do
+    ScratchPad.clear
+  end
+
+  it "allows to combine guards" do
+    guard1 = VersionGuard.new 'x.x.x'
+    VersionGuard.stub(:new).and_return(guard1)
+    guard2 = PlatformGuard.new :dummy
+    PlatformGuard.stub(:new).and_return(guard2)
+
+    guard1.stub(:match?).and_return(true)
+    guard2.stub(:match?).and_return(true)
+    guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
+      fail
+    end
+
+    guard1.stub(:match?).and_return(false)
+    guard2.stub(:match?).and_return(true)
+    guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
+      ScratchPad.record :yield1
+    end
+    ScratchPad.recorded.should == :yield1
+
+    guard1.stub(:match?).and_return(true)
+    guard2.stub(:match?).and_return(false)
+    guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
+      ScratchPad.record :yield2
+    end
+    ScratchPad.recorded.should == :yield2
+
+    guard1.stub(:match?).and_return(false)
+    guard2.stub(:match?).and_return(false)
+    guard_not -> { ruby_version_is "2.4" and platform_is :linux } do
+      ScratchPad.record :yield3
+    end
+    ScratchPad.recorded.should == :yield3
+  end
+
+  it "yields when the Proc returns false" do
+    guard_not -> { false } do
+      ScratchPad.record :yield
+    end
+    ScratchPad.recorded.should == :yield
+  end
+
+  it "does not yield when the Proc returns true" do
+    guard_not -> { true } do
+      fail
+    end
+  end
+
+  it "raises an error if no Proc is given" do
+    -> { guard_not :foo }.should raise_error(RuntimeError)
+  end
+
+  it "requires a block" do
+    -> {
+      guard_not(-> { true })
+    }.should raise_error(LocalJumpError)
+    -> {
+      guard_not(-> { false })
+    }.should raise_error(LocalJumpError)
+  end
+end
Index: spec/mspec/spec/guards/platform_spec.rb
===================================================================
--- spec/mspec/spec/guards/platform_spec.rb	(revision 59429)
+++ spec/mspec/spec/guards/platform_spec.rb	(revision 59430)
@@ -20,6 +20,13 @@ describe Object, "#platform_is" do https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/guards/platform_spec.rb#L20
     ScratchPad.recorded.should == :yield
   end
 
+  it "returns what #os? returns when no block is given" do
+    PlatformGuard.stub(:os?).and_return(true)
+    platform_is(:solarce).should == true
+    PlatformGuard.stub(:os?).and_return(false)
+    platform_is(:solarce).should == false
+  end
+
   it "sets the name of the guard to :platform_is" do
     platform_is(:solarce) { }
     @guard.name.should == :platform_is
@@ -53,6 +60,13 @@ describe Object, "#platform_is_not" do https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/guards/platform_spec.rb#L60
     ScratchPad.recorded.should == :yield
   end
 
+  it "returns the opposite of what #os? returns when no block is given" do
+    PlatformGuard.stub(:os?).and_return(true)
+    platform_is_not(:solarce).should == false
+    PlatformGuard.stub(:os?).and_return(false)
+    platform_is_not(:solarce).should == true
+  end
+
   it "sets the name of the guard to :platform_is_not" do
     platform_is_not(:solarce) { }
     @guard.name.should == :platform_is_not
@@ -110,66 +124,49 @@ describe Object, "#platform_is_not :word https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/guards/platform_spec.rb#L124
 end
 
 describe PlatformGuard, ".implementation?" do
-  before :all do
-    @verbose = $VERBOSE
-    $VERBOSE = nil
-  end
-
-  after :all do
-    $VERBOSE = @verbose
-  end
-
-  before :each do
-    @ruby_engine = Object.const_get :RUBY_ENGINE
-  end
-
-  after :each do
-    Object.const_set :RUBY_ENGINE, @ruby_engine
-  end
-
   it "returns true if passed :ruby and RUBY_ENGINE == 'ruby'" do
-    Object.const_set :RUBY_ENGINE, 'ruby'
+    stub_const 'RUBY_ENGINE', 'ruby'
     PlatformGuard.implementation?(:ruby).should == true
   end
 
   it "returns true if passed :rubinius and RUBY_ENGINE == 'rbx'" do
-    Object.const_set :RUBY_ENGINE, 'rbx'
+    stub_const 'RUBY_ENGINE', 'rbx'
     PlatformGuard.implementation?(:rubinius).should == true
   end
 
   it "returns true if passed :jruby and RUBY_ENGINE == 'jruby'" do
-    Object.const_set :RUBY_ENGINE, 'jruby'
+    stub_const 'RUBY_ENGINE', 'jruby'
     PlatformGuard.implementation?(:jruby).should == true
   end
 
   it "returns true if passed :ironruby and RUBY_ENGINE == 'ironruby'" do
-    Object.const_set :RUBY_ENGINE, 'ironruby'
+    stub_const 'RUBY_ENGINE', 'ironruby'
     PlatformGuard.implementation?(:ironruby).should == true
   end
 
   it "returns true if passed :maglev and RUBY_ENGINE == 'maglev'" do
-    Object.const_set :RUBY_ENGINE, 'maglev'
+    stub_const 'RUBY_ENGINE', 'maglev'
     PlatformGuard.implementation?(:maglev).should == true
   end
 
   it "returns true if passed :topaz and RUBY_ENGINE == 'topaz'" do
-    Object.const_set :RUBY_ENGINE, 'topaz'
+    stub_const 'RUBY_ENGINE', 'topaz'
     PlatformGuard.implementation?(:topaz).should == true
   end
 
   it "returns true if passed :ruby and RUBY_ENGINE matches /^ruby/" do
-    Object.const_set :RUBY_ENGINE, 'ruby'
+    stub_const 'RUBY_ENGINE', 'ruby'
     PlatformGuard.implementation?(:ruby).should == true
 
-    Object.const_set :RUBY_ENGINE, 'ruby1.8'
+    stub_const 'RUBY_ENGINE', 'ruby1.8'
     PlatformGuard.implementation?(:ruby).should == true
 
-    Object.const_set :RUBY_ENGINE, 'ruby1.9'
+    stub_const 'RUBY_ENGINE', 'ruby1.9'
     PlatformGuard.implementation?(:ruby).should == true
   end
 
   it "raises an error when passed an unrecognized name" do
-    Object.const_set :RUBY_ENGINE, 'ruby'
+    stub_const 'RUBY_ENGINE', 'ruby'
     lambda {
       PlatformGuard.implementation?(:python)
     }.should raise_error(/unknown implementation/)
Index: spec/mspec/spec/guards/version_spec.rb
===================================================================
--- spec/mspec/spec/guards/version_spec.rb	(revision 59429)
+++ spec/mspec/spec/guards/version_spec.rb	(revision 59430)
@@ -68,6 +68,13 @@ describe Object, "#ruby_version_is" do https://github.com/ruby/ruby/blob/trunk/spec/mspec/spec/guards/version_spec.rb#L68
     ScratchPad.recorded.should_not == :yield
   end
 
+  it "returns what #match? returns when no block is given" do
+    @guard.stub(:match?).and_return(true)
+    ruby_version_is('x.x.x').should == true
+    @guard.stub(:match?).and_return(false)
+    ruby_version_is('x.x.x').should == false
+  end
+
   it "sets the name of the guard to :ruby_version_is" do
     ruby_version_is("") { }
     @guard.name.should == :ruby_version_is
Index: spec/mspec/tool/find.rb
===================================================================
--- spec/mspec/tool/find.rb	(nonexistent)
+++ spec/mspec/tool/find.rb	(revision 59430)
@@ -0,0 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/tool/find.rb#L1
+#!/usr/bin/env ruby
+Dir.chdir('../rubyspec') do
+  regexp = Regexp.new(ARGV[0])
+  Dir.glob('**/*.rb') do |file|
+    contents = File.read(file)
+    if regexp =~ contents
+      puts file
+    end
+  end
+end

Property changes on: spec/mspec/tool/find.rb
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]