spec/guards/guard_spec.rb in mspec-1.5.17 vs spec/guards/guard_spec.rb in mspec-1.5.18
- old
+ new
@@ -1,20 +1,34 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'mspec/utils/ruby_name'
-require 'mspec/guards/guard'
+require 'spec_helper'
+require 'mspec/guards'
require 'rbconfig'
+describe SpecGuard, "#ruby_version_override=" do
+ after :each do
+ SpecGuard.ruby_version_override = nil
+ end
+
+ it "returns nil by default" do
+ SpecGuard.ruby_version_override.should be_nil
+ end
+
+ it "returns the value set by #ruby_version_override=" do
+ SpecGuard.ruby_version_override = "8.3.2"
+ SpecGuard.ruby_version_override.should == "8.3.2"
+ end
+end
+
describe SpecGuard, ".ruby_version" do
- before :all do
+ before :each do
@ruby_version = Object.const_get :RUBY_VERSION
@ruby_patchlevel = Object.const_get :RUBY_PATCHLEVEL
Object.const_set :RUBY_VERSION, "8.2.3"
Object.const_set :RUBY_PATCHLEVEL, 71
end
- after :all do
+ after :each do
Object.const_set :RUBY_VERSION, @ruby_version
Object.const_set :RUBY_PATCHLEVEL, @ruby_patchlevel
end
it "returns the version and patchlevel for :full" do
@@ -43,10 +57,49 @@
end
it "returns major for :major" do
SpecGuard.ruby_version(:major).should == "8"
end
+
+ describe "with ruby_version_override set" do
+ before :each do
+ SpecGuard.ruby_version_override = "8.3.2"
+ end
+
+ after :each do
+ SpecGuard.ruby_version_override = nil
+ end
+
+ it "returns the version and patchlevel for :full" do
+ SpecGuard.ruby_version(:full).should == "8.3.2.71"
+ end
+
+ it "returns 0 for negative RUBY_PATCHLEVEL values" do
+ Object.const_set :RUBY_PATCHLEVEL, -1
+ SpecGuard.ruby_version(:full).should == "8.3.2.0"
+ end
+
+ it "returns major.minor.tiny for :tiny" do
+ SpecGuard.ruby_version(:tiny).should == "8.3.2"
+ end
+
+ it "returns major.minor.tiny for :teeny" do
+ SpecGuard.ruby_version(:tiny).should == "8.3.2"
+ end
+
+ it "returns major.minor for :minor" do
+ SpecGuard.ruby_version(:minor).should == "8.3"
+ end
+
+ it "defaults to :minor" do
+ SpecGuard.ruby_version.should == "8.3"
+ end
+
+ it "returns major for :major" do
+ SpecGuard.ruby_version(:major).should == "8"
+ end
+ end
end
describe SpecGuard, "#yield?" do
before :each do
MSpec.clear_modes
@@ -156,10 +209,15 @@
it "returns true if passed :maglev and RUBY_NAME == 'maglev'" do
Object.const_set :RUBY_NAME, 'maglev'
@guard.implementation?(:maglev).should == true
end
+ it "returns true if passed :topaz and RUBY_NAME == 'topaz'" do
+ Object.const_set :RUBY_NAME, 'topaz'
+ @guard.implementation?(:topaz).should == true
+ end
+
it "returns true if passed :ruby and RUBY_NAME matches /^ruby/" do
Object.const_set :RUBY_NAME, 'ruby'
@guard.implementation?(:ruby).should == true
Object.const_set :RUBY_NAME, 'ruby1.8'
@@ -235,16 +293,16 @@
it "returns true when arg is :windows and RUBY_PLATFORM contains 'mingw'" do
Object.const_set :RUBY_PLATFORM, 'i386-mingw32'
@guard.platform?(:windows).should == true
end
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
Object.const_set :RUBY_PLATFORM, 'i386-mswin32'
@guard.platform?(:linux).should == false
end
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
Object.const_set :RUBY_PLATFORM, 'i386-mingw32'
@guard.platform?(:linux).should == false
end
end
@@ -271,16 +329,16 @@
it "returns true when arg is :java and RUBY_PLATFORM contains 'java'" do
@guard.platform?(:java).should == true
end
it "returns true when arg is :windows and RUBY_PLATFORM contains 'java' and os?(:windows) is true" do
- Config::CONFIG.stub!(:[]).and_return('mswin32')
+ RbConfig::CONFIG.stub!(:[]).and_return('mswin32')
@guard.platform?(:windows).should == true
end
it "returns true when RUBY_PLATFORM contains 'java' and os?(argument) is true" do
- Config::CONFIG.stub!(:[]).and_return('amiga')
+ RbConfig::CONFIG.stub!(:[]).and_return('amiga')
@guard.platform?(:amiga).should == true
end
end
describe SpecGuard, "#wordsize?" do
@@ -298,45 +356,45 @@
end
describe SpecGuard, "#os?" do
before :each do
@guard = SpecGuard.new
- Config::CONFIG.stub!(:[]).and_return('unreal')
+ RbConfig::CONFIG.stub!(:[]).and_return('unreal')
end
- it "returns true if argument matches Config::CONFIG['host_os']" do
+ it "returns true if argument matches RbConfig::CONFIG['host_os']" do
@guard.os?(:unreal).should == true
end
- it "returns true if any argument matches Config::CONFIG['host_os']" do
+ it "returns true if any argument matches RbConfig::CONFIG['host_os']" do
@guard.os?(:bsd, :unreal, :amiga).should == true
end
- it "returns false if no argument matches Config::CONFIG['host_os']" do
+ it "returns false if no argument matches RbConfig::CONFIG['host_os']" do
@guard.os?(:bsd, :netbsd, :amiga, :msdos).should == false
end
- it "returns false if argument does not match Config::CONFIG['host_os']" do
+ it "returns false if argument does not match RbConfig::CONFIG['host_os']" do
@guard.os?(:amiga).should == false
end
- it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mswin'" do
- Config::CONFIG.stub!(:[]).and_return('i386-mswin32')
+ it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mswin32')
@guard.os?(:windows).should == true
end
- it "returns true when arg is :windows and Config::CONFIG['host_os'] contains 'mingw'" do
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
+ it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
@guard.os?(:windows).should == true
end
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mswin'" do
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
@guard.os?(:linux).should == false
end
- it "returns false when arg is not :windows and Config::CONFIG['host_os'] contains 'mingw'" do
- Config::CONFIG.stub!(:[]).and_return('i386-mingw32')
+ it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do
+ RbConfig::CONFIG.stub!(:[]).and_return('i386-mingw32')
@guard.os?(:linux).should == false
end
end
describe SpecGuard, "#windows?" do