diff options
Diffstat (limited to 'spec/mspec/spec/guards')
-rw-r--r-- | spec/mspec/spec/guards/block_device_spec.rb | 26 | ||||
-rw-r--r-- | spec/mspec/spec/guards/bug_spec.rb | 84 | ||||
-rw-r--r-- | spec/mspec/spec/guards/conflict_spec.rb | 30 | ||||
-rw-r--r-- | spec/mspec/spec/guards/endian_spec.rb | 34 | ||||
-rw-r--r-- | spec/mspec/spec/guards/feature_spec.rb | 82 | ||||
-rw-r--r-- | spec/mspec/spec/guards/guard_spec.rb | 218 | ||||
-rw-r--r-- | spec/mspec/spec/guards/platform_spec.rb | 188 | ||||
-rw-r--r-- | spec/mspec/spec/guards/quarantine_spec.rb | 20 | ||||
-rw-r--r-- | spec/mspec/spec/guards/superuser_spec.rb | 22 | ||||
-rw-r--r-- | spec/mspec/spec/guards/support_spec.rb | 28 | ||||
-rw-r--r-- | spec/mspec/spec/guards/user_spec.rb | 10 | ||||
-rw-r--r-- | spec/mspec/spec/guards/version_spec.rb | 92 |
12 files changed, 417 insertions, 417 deletions
diff --git a/spec/mspec/spec/guards/block_device_spec.rb b/spec/mspec/spec/guards/block_device_spec.rb index 3b437b6d74..dd420d4a81 100644 --- a/spec/mspec/spec/guards/block_device_spec.rb +++ b/spec/mspec/spec/guards/block_device_spec.rb @@ -1,46 +1,46 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#with_block_device" do +RSpec.describe Object, "#with_block_device" do before :each do ScratchPad.clear @guard = BlockDeviceGuard.new - BlockDeviceGuard.stub(:new).and_return(@guard) + allow(BlockDeviceGuard).to receive(:new).and_return(@guard) end platform_is_not :freebsd, :windows do it "yields if block device is available" do - @guard.should_receive(:`).and_return("block devices") + expect(@guard).to receive(:`).and_return("block devices") with_block_device { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield if block device is not available" do - @guard.should_receive(:`).and_return(nil) + expect(@guard).to receive(:`).and_return(nil) with_block_device { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end platform_is :freebsd, :windows do it "does not yield, since platform does not support block devices" do - @guard.should_not_receive(:`) + expect(@guard).not_to receive(:`) with_block_device { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end it "sets the name of the guard to :with_block_device" do with_block_device { } - @guard.name.should == :with_block_device + expect(@guard.name).to eq(:with_block_device) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(true) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(true) + expect(@guard).to receive(:unregister) + expect do with_block_device { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/bug_spec.rb b/spec/mspec/spec/guards/bug_spec.rb index c8529a49f7..72a3405dbc 100644 --- a/spec/mspec/spec/guards/bug_spec.rb +++ b/spec/mspec/spec/guards/bug_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'mspec/guards' -describe BugGuard, "#match? when #implementation? is 'ruby'" do +RSpec.describe BugGuard, "#match? when #implementation? is 'ruby'" do before :all do @verbose = $VERBOSE $VERBOSE = nil @@ -23,47 +23,47 @@ describe BugGuard, "#match? when #implementation? is 'ruby'" do end it "returns false when version argument is less than RUBY_VERSION" do - BugGuard.new("#1", "1.8.5").match?.should == false + expect(BugGuard.new("#1", "1.8.5").match?).to eq(false) end it "returns true when version argument is equal to RUBY_VERSION" do - BugGuard.new("#1", "1.8.6").match?.should == true + expect(BugGuard.new("#1", "1.8.6").match?).to eq(true) end it "returns true when version argument is greater than RUBY_VERSION" do - BugGuard.new("#1", "1.8.7").match?.should == true + expect(BugGuard.new("#1", "1.8.7").match?).to eq(true) end it "returns true when version argument implicitly includes RUBY_VERSION" do - BugGuard.new("#1", "1.8").match?.should == true - BugGuard.new("#1", "1.8.6").match?.should == true + expect(BugGuard.new("#1", "1.8").match?).to eq(true) + expect(BugGuard.new("#1", "1.8.6").match?).to eq(true) end it "returns true when the argument range includes RUBY_VERSION" do - BugGuard.new("#1", '1.8.5'..'1.8.7').match?.should == true - BugGuard.new("#1", '1.8'..'1.9').match?.should == true - BugGuard.new("#1", '1.8'...'1.9').match?.should == true - BugGuard.new("#1", '1.8'..'1.8.6').match?.should == true - BugGuard.new("#1", '1.8.5'..'1.8.6').match?.should == true - BugGuard.new("#1", ''...'1.8.7').match?.should == true + expect(BugGuard.new("#1", '1.8.5'..'1.8.7').match?).to eq(true) + expect(BugGuard.new("#1", '1.8'..'1.9').match?).to eq(true) + expect(BugGuard.new("#1", '1.8'...'1.9').match?).to eq(true) + expect(BugGuard.new("#1", '1.8'..'1.8.6').match?).to eq(true) + expect(BugGuard.new("#1", '1.8.5'..'1.8.6').match?).to eq(true) + expect(BugGuard.new("#1", ''...'1.8.7').match?).to eq(true) end it "returns false when the argument range does not include RUBY_VERSION" do - BugGuard.new("#1", '1.8.7'..'1.8.9').match?.should == false - BugGuard.new("#1", '1.8.4'..'1.8.5').match?.should == false - BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false - BugGuard.new("#1", '1.8.5'...'1.8.6').match?.should == false - BugGuard.new("#1", ''...'1.8.6').match?.should == false + expect(BugGuard.new("#1", '1.8.7'..'1.8.9').match?).to eq(false) + expect(BugGuard.new("#1", '1.8.4'..'1.8.5').match?).to eq(false) + expect(BugGuard.new("#1", '1.8.4'...'1.8.6').match?).to eq(false) + expect(BugGuard.new("#1", '1.8.5'...'1.8.6').match?).to eq(false) + expect(BugGuard.new("#1", ''...'1.8.6').match?).to eq(false) end it "returns false when MSpec.mode?(:no_ruby_bug) is true" do - MSpec.should_receive(:mode?).with(:no_ruby_bug).twice.and_return(:true) - BugGuard.new("#1", "1.8.5").match?.should == false - BugGuard.new("#1", "1.8").match?.should == false + expect(MSpec).to receive(:mode?).with(:no_ruby_bug).twice.and_return(:true) + expect(BugGuard.new("#1", "1.8.5").match?).to eq(false) + expect(BugGuard.new("#1", "1.8").match?).to eq(false) end end -describe BugGuard, "#match? when #implementation? is not 'ruby'" do +RSpec.describe BugGuard, "#match? when #implementation? is not 'ruby'" do before :all do @verbose = $VERBOSE $VERBOSE = nil @@ -88,64 +88,64 @@ describe BugGuard, "#match? when #implementation? is not 'ruby'" do end it "returns false when version argument is less than RUBY_VERSION" do - BugGuard.new("#1", "1.8").match?.should == false - BugGuard.new("#1", "1.8.6").match?.should == false + expect(BugGuard.new("#1", "1.8").match?).to eq(false) + expect(BugGuard.new("#1", "1.8.6").match?).to eq(false) end it "returns false when version argument is equal to RUBY_VERSION" do - BugGuard.new("#1", "1.8.6").match?.should == false + expect(BugGuard.new("#1", "1.8.6").match?).to eq(false) end it "returns false when version argument is greater than RUBY_VERSION" do - BugGuard.new("#1", "1.8.7").match?.should == false + expect(BugGuard.new("#1", "1.8.7").match?).to eq(false) end it "returns false no matter if the argument range includes RUBY_VERSION" do - BugGuard.new("#1", '1.8'...'1.9').match?.should == false - BugGuard.new("#1", '1.8.5'...'1.8.7').match?.should == false - BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false + expect(BugGuard.new("#1", '1.8'...'1.9').match?).to eq(false) + expect(BugGuard.new("#1", '1.8.5'...'1.8.7').match?).to eq(false) + expect(BugGuard.new("#1", '1.8.4'...'1.8.6').match?).to eq(false) end it "returns false when MSpec.mode?(:no_ruby_bug) is true" do - MSpec.stub(:mode?).and_return(:true) - BugGuard.new("#1", "1.8.6").match?.should == false + allow(MSpec).to receive(:mode?).and_return(:true) + expect(BugGuard.new("#1", "1.8.6").match?).to eq(false) end end -describe Object, "#ruby_bug" do +RSpec.describe Object, "#ruby_bug" do before :each do hide_deprecation_warnings @guard = BugGuard.new "#1234", "x.x.x" - BugGuard.stub(:new).and_return(@guard) + allow(BugGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields when #match? returns false" do - @guard.stub(:match?).and_return(false) + allow(@guard).to receive(:match?).and_return(false) ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield when #match? returns true" do - @guard.stub(:match?).and_return(true) + allow(@guard).to receive(:match?).and_return(true) ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "requires a bug tracker number and a version number" do - lambda { ruby_bug { } }.should raise_error(ArgumentError) - lambda { ruby_bug("#1234") { } }.should raise_error(ArgumentError) + expect { ruby_bug { } }.to raise_error(ArgumentError) + expect { ruby_bug("#1234") { } }.to raise_error(ArgumentError) end it "sets the name of the guard to :ruby_bug" do ruby_bug("#1234", "1.8.6") { } - @guard.name.should == :ruby_bug + expect(@guard.name).to eq(:ruby_bug) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:unregister) + expect do ruby_bug("", "") { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/conflict_spec.rb b/spec/mspec/spec/guards/conflict_spec.rb index deada96821..7dbe83153d 100644 --- a/spec/mspec/spec/guards/conflict_spec.rb +++ b/spec/mspec/spec/guards/conflict_spec.rb @@ -1,53 +1,53 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#conflicts_with" do +RSpec.describe Object, "#conflicts_with" do before :each do hide_deprecation_warnings ScratchPad.clear end it "does not yield if Object.constants includes any of the arguments" do - Object.stub(:constants).and_return(["SomeClass", "OtherClass"]) + allow(Object).to receive(:constants).and_return(["SomeClass", "OtherClass"]) conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "does not yield if Object.constants (as Symbols) includes any of the arguments" do - Object.stub(:constants).and_return([:SomeClass, :OtherClass]) + allow(Object).to receive(:constants).and_return([:SomeClass, :OtherClass]) conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "yields if Object.constants does not include any of the arguments" do - Object.stub(:constants).and_return(["SomeClass", "OtherClass"]) + allow(Object).to receive(:constants).and_return(["SomeClass", "OtherClass"]) conflicts_with(:AClass, :BClass) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "yields if Object.constants (as Symbols) does not include any of the arguments" do - Object.stub(:constants).and_return([:SomeClass, :OtherClass]) + allow(Object).to receive(:constants).and_return([:SomeClass, :OtherClass]) conflicts_with(:AClass, :BClass) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end end -describe Object, "#conflicts_with" do +RSpec.describe Object, "#conflicts_with" do before :each do hide_deprecation_warnings @guard = ConflictsGuard.new - ConflictsGuard.stub(:new).and_return(@guard) + allow(ConflictsGuard).to receive(:new).and_return(@guard) end it "sets the name of the guard to :conflicts_with" do conflicts_with(:AClass, :BClass) { } - @guard.name.should == :conflicts_with + expect(@guard.name).to eq(:conflicts_with) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:unregister) + expect do conflicts_with(:AClass, :BClass) { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/endian_spec.rb b/spec/mspec/spec/guards/endian_spec.rb index 5b40c203ab..943b558ed3 100644 --- a/spec/mspec/spec/guards/endian_spec.rb +++ b/spec/mspec/spec/guards/endian_spec.rb @@ -1,55 +1,55 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#big_endian" do +RSpec.describe Object, "#big_endian" do before :each do @guard = BigEndianGuard.new - BigEndianGuard.stub(:new).and_return(@guard) + allow(BigEndianGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields on big-endian platforms" do - @guard.stub(:pattern).and_return([?\001]) + allow(@guard).to receive(:pattern).and_return([?\001]) big_endian { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield on little-endian platforms" do - @guard.stub(:pattern).and_return([?\000]) + allow(@guard).to receive(:pattern).and_return([?\000]) big_endian { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "sets the name of the guard to :big_endian" do big_endian { } - @guard.name.should == :big_endian + expect(@guard.name).to eq(:big_endian) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.stub(:pattern).and_return([?\001]) - @guard.should_receive(:unregister) - lambda do + allow(@guard).to receive(:pattern).and_return([?\001]) + expect(@guard).to receive(:unregister) + expect do big_endian { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#little_endian" do +RSpec.describe Object, "#little_endian" do before :each do @guard = BigEndianGuard.new - BigEndianGuard.stub(:new).and_return(@guard) + allow(BigEndianGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields on little-endian platforms" do - @guard.stub(:pattern).and_return([?\000]) + allow(@guard).to receive(:pattern).and_return([?\000]) little_endian { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield on big-endian platforms" do - @guard.stub(:pattern).and_return([?\001]) + allow(@guard).to receive(:pattern).and_return([?\001]) little_endian { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end diff --git a/spec/mspec/spec/guards/feature_spec.rb b/spec/mspec/spec/guards/feature_spec.rb index 8761cb2fbb..fcb8997591 100644 --- a/spec/mspec/spec/guards/feature_spec.rb +++ b/spec/mspec/spec/guards/feature_spec.rb @@ -1,120 +1,120 @@ require 'spec_helper' require 'mspec/guards' -describe FeatureGuard, ".enabled?" do +RSpec.describe FeatureGuard, ".enabled?" do it "returns true if the feature is enabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true) - FeatureGuard.enabled?(:encoding).should be_true + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true) + expect(FeatureGuard.enabled?(:encoding)).to be_truthy end it "returns false if the feature is not enabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false) - FeatureGuard.enabled?(:encoding).should be_false + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false) + expect(FeatureGuard.enabled?(:encoding)).to be_falsey end it "returns true if all the features are enabled" do - MSpec.should_receive(:feature_enabled?).with(:one).and_return(true) - MSpec.should_receive(:feature_enabled?).with(:two).and_return(true) - FeatureGuard.enabled?(:one, :two).should be_true + expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(true) + expect(FeatureGuard.enabled?(:one, :two)).to be_truthy end it "returns false if any of the features are not enabled" do - MSpec.should_receive(:feature_enabled?).with(:one).and_return(true) - MSpec.should_receive(:feature_enabled?).with(:two).and_return(false) - FeatureGuard.enabled?(:one, :two).should be_false + expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(false) + expect(FeatureGuard.enabled?(:one, :two)).to be_falsey end end -describe Object, "#with_feature" do +RSpec.describe Object, "#with_feature" do before :each do ScratchPad.clear @guard = FeatureGuard.new :encoding - FeatureGuard.stub(:new).and_return(@guard) + allow(FeatureGuard).to receive(:new).and_return(@guard) end it "sets the name of the guard to :with_feature" do with_feature(:encoding) { } - @guard.name.should == :with_feature + expect(@guard.name).to eq(:with_feature) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(true) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(true) + expect(@guard).to receive(:unregister) + expect do with_feature { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#with_feature" do +RSpec.describe Object, "#with_feature" do before :each do ScratchPad.clear end it "yields if the feature is enabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true) with_feature(:encoding) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "yields if all the features are enabled" do - MSpec.should_receive(:feature_enabled?).with(:one).and_return(true) - MSpec.should_receive(:feature_enabled?).with(:two).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(true) with_feature(:one, :two) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield if the feature is not enabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false) + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false) with_feature(:encoding) { ScratchPad.record :yield } - ScratchPad.recorded.should be_nil + expect(ScratchPad.recorded).to be_nil end it "does not yield if any of the features are not enabled" do - MSpec.should_receive(:feature_enabled?).with(:one).and_return(true) - MSpec.should_receive(:feature_enabled?).with(:two).and_return(false) + expect(MSpec).to receive(:feature_enabled?).with(:one).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:two).and_return(false) with_feature(:one, :two) { ScratchPad.record :yield } - ScratchPad.recorded.should be_nil + expect(ScratchPad.recorded).to be_nil end end -describe Object, "#without_feature" do +RSpec.describe Object, "#without_feature" do before :each do ScratchPad.clear @guard = FeatureGuard.new :encoding - FeatureGuard.stub(:new).and_return(@guard) + allow(FeatureGuard).to receive(:new).and_return(@guard) end it "sets the name of the guard to :without_feature" do without_feature(:encoding) { } - @guard.name.should == :without_feature + expect(@guard.name).to eq(:without_feature) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(false) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(false) + expect(@guard).to receive(:unregister) + expect do without_feature { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#without_feature" do +RSpec.describe Object, "#without_feature" do before :each do ScratchPad.clear end it "does not yield if the feature is enabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true) + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(true) without_feature(:encoding) { ScratchPad.record :yield } - ScratchPad.recorded.should be_nil + expect(ScratchPad.recorded).to be_nil end it "yields if the feature is disabled" do - MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false) + expect(MSpec).to receive(:feature_enabled?).with(:encoding).and_return(false) without_feature(:encoding) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end end diff --git a/spec/mspec/spec/guards/guard_spec.rb b/spec/mspec/spec/guards/guard_spec.rb index 2c3317afe6..e29d235747 100644 --- a/spec/mspec/spec/guards/guard_spec.rb +++ b/spec/mspec/spec/guards/guard_spec.rb @@ -2,41 +2,41 @@ require 'spec_helper' require 'mspec/guards' require 'rbconfig' -describe SpecGuard, ".ruby_version" do +RSpec.describe SpecGuard, ".ruby_version" do before :each do stub_const "RUBY_VERSION", "8.2.3" end it "returns the full version for :full" do - SpecGuard.ruby_version(:full).should == "8.2.3" + expect(SpecGuard.ruby_version(:full)).to eq("8.2.3") end it "returns major.minor.tiny for :tiny" do - SpecGuard.ruby_version(:tiny).should == "8.2.3" + expect(SpecGuard.ruby_version(:tiny)).to eq("8.2.3") end it "returns major.minor.tiny for :teeny" do - SpecGuard.ruby_version(:tiny).should == "8.2.3" + expect(SpecGuard.ruby_version(:tiny)).to eq("8.2.3") end it "returns major.minor for :minor" do - SpecGuard.ruby_version(:minor).should == "8.2" + expect(SpecGuard.ruby_version(:minor)).to eq("8.2") end it "defaults to :minor" do - SpecGuard.ruby_version.should == "8.2" + expect(SpecGuard.ruby_version).to eq("8.2") end it "returns major for :major" do - SpecGuard.ruby_version(:major).should == "8" + expect(SpecGuard.ruby_version(:major)).to eq("8") end end -describe SpecGuard, "#yield?" do +RSpec.describe SpecGuard, "#yield?" do before :each do MSpec.clear_modes @guard = SpecGuard.new - @guard.stub(:match?).and_return(false) + allow(@guard).to receive(:match?).and_return(false) end after :each do @@ -47,77 +47,77 @@ describe SpecGuard, "#yield?" do it "returns true if MSpec.mode?(:unguarded) is true" do MSpec.register_mode :unguarded - @guard.yield?.should == true + expect(@guard.yield?).to eq(true) end it "returns true if MSpec.mode?(:verify) is true" do MSpec.register_mode :verify - @guard.yield?.should == true + expect(@guard.yield?).to eq(true) end it "returns true if MSpec.mode?(:verify) is true regardless of invert being true" do MSpec.register_mode :verify - @guard.yield?(true).should == true + expect(@guard.yield?(true)).to eq(true) end it "returns true if MSpec.mode?(:report) is true" do MSpec.register_mode :report - @guard.yield?.should == true + expect(@guard.yield?).to eq(true) end it "returns true if MSpec.mode?(:report) is true regardless of invert being true" do MSpec.register_mode :report - @guard.yield?(true).should == true + expect(@guard.yield?(true)).to eq(true) end it "returns true if MSpec.mode?(:report_on) is true and SpecGuards.guards contains the named guard" do MSpec.register_mode :report_on SpecGuard.guards << :guard_name - @guard.yield?.should == false + expect(@guard.yield?).to eq(false) @guard.name = :guard_name - @guard.yield?.should == true + expect(@guard.yield?).to eq(true) end it "returns #match? if neither report nor verify mode are true" do - @guard.stub(:match?).and_return(false) - @guard.yield?.should == false - @guard.stub(:match?).and_return(true) - @guard.yield?.should == true + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.yield?).to eq(false) + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.yield?).to eq(true) end it "returns #match? if invert is true and neither report nor verify mode are true" do - @guard.stub(:match?).and_return(false) - @guard.yield?(true).should == true - @guard.stub(:match?).and_return(true) - @guard.yield?(true).should == false + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.yield?(true)).to eq(true) + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.yield?(true)).to eq(false) end end -describe SpecGuard, "#match?" do +RSpec.describe SpecGuard, "#match?" do before :each do @guard = SpecGuard.new end it "must be implemented in subclasses" do - lambda { + expect { @guard.match? - }.should raise_error("must be implemented by the subclass") + }.to raise_error("must be implemented by the subclass") end end -describe SpecGuard, "#unregister" do +RSpec.describe SpecGuard, "#unregister" do before :each do - MSpec.stub(:unregister) + allow(MSpec).to receive(:unregister) @guard = SpecGuard.new end it "unregisters from MSpec :add actions" do - MSpec.should_receive(:unregister).with(:add, @guard) + expect(MSpec).to receive(:unregister).with(:add, @guard) @guard.unregister end end -describe SpecGuard, "#record" do +RSpec.describe SpecGuard, "#record" do after :each do SpecGuard.clear end @@ -126,28 +126,28 @@ describe SpecGuard, "#record" do guard = SpecGuard.new "a", "1.8"..."1.9" guard.name = :named_guard guard.record "SomeClass#action returns true" - SpecGuard.report.should == { + expect(SpecGuard.report).to eq({ 'named_guard a, 1.8...1.9' => ["SomeClass#action returns true"] - } + }) end end -describe SpecGuard, ".guards" do +RSpec.describe SpecGuard, ".guards" do it "returns an Array" do - SpecGuard.guards.should be_kind_of(Array) + expect(SpecGuard.guards).to be_kind_of(Array) end end -describe SpecGuard, ".clear_guards" do +RSpec.describe SpecGuard, ".clear_guards" do it "resets the array to empty" do SpecGuard.guards << :guard - SpecGuard.guards.should == [:guard] + expect(SpecGuard.guards).to eq([:guard]) SpecGuard.clear_guards - SpecGuard.guards.should == [] + expect(SpecGuard.guards).to eq([]) end end -describe SpecGuard, ".finish" do +RSpec.describe SpecGuard, ".finish" do before :each do $stdout = @out = IOStub.new end @@ -163,88 +163,88 @@ describe SpecGuard, ".finish" do guard.record "SomeClass#action returns true" guard.record "SomeClass#reverse returns false" SpecGuard.finish - $stdout.should == %[ + expect($stdout).to eq(%[ 2 specs omitted by guard: named_guard a, 1.8...1.9: SomeClass#action returns true SomeClass#reverse returns false -] +]) end end -describe SpecGuard, ".run_if" do +RSpec.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) + allow(@guard).to receive(:match?).and_return(true) @guard.run_if(:name) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield if match? returns false" do - @guard.stub(:match?).and_return(false) + allow(@guard).to receive(: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 + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.run_if(:name) { 42 }).to eq(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 + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.run_if(:name) { 42 }).to eq(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 + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.run_if(:name)).to eq(true) + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.run_if(:name)).to eq(false) end end -describe SpecGuard, ".run_unless" do +RSpec.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) + allow(@guard).to receive(:match?).and_return(false) @guard.run_unless(:name) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield if match? returns true" do - @guard.stub(:match?).and_return(true) + allow(@guard).to receive(: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 + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.run_unless(:name) { 42 }).to eq(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 + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.run_unless(:name) { 42 }).to eq(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 + allow(@guard).to receive(:match?).and_return(true) + expect(@guard.run_unless(:name)).to eq(false) + allow(@guard).to receive(:match?).and_return(false) + expect(@guard.run_unless(:name)).to eq(true) end end -describe Object, "#guard" do +RSpec.describe Object, "#guard" do before :each do ScratchPad.clear end @@ -255,31 +255,31 @@ describe Object, "#guard" do it "allows to combine guards" do guard1 = VersionGuard.new '1.2.3', 'x.x.x' - VersionGuard.stub(:new).and_return(guard1) + allow(VersionGuard).to receive(:new).and_return(guard1) guard2 = PlatformGuard.new :dummy - PlatformGuard.stub(:new).and_return(guard2) + allow(PlatformGuard).to receive(:new).and_return(guard2) - guard1.stub(:match?).and_return(true) - guard2.stub(:match?).and_return(true) + allow(guard1).to receive(:match?).and_return(true) + allow(guard2).to receive(:match?).and_return(true) guard -> { ruby_version_is "2.4" and platform_is :linux } do ScratchPad.record :yield end - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) - guard1.stub(:match?).and_return(false) - guard2.stub(:match?).and_return(true) + allow(guard1).to receive(:match?).and_return(false) + allow(guard2).to receive(: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) + allow(guard1).to receive(:match?).and_return(true) + allow(guard2).to receive(: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) + allow(guard1).to receive(:match?).and_return(false) + allow(guard2).to receive(:match?).and_return(false) guard -> { ruby_version_is "2.4" and platform_is :linux } do fail end @@ -289,7 +289,7 @@ describe Object, "#guard" do guard -> { true } do ScratchPad.record :yield end - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield when the Proc returns false" do @@ -304,12 +304,12 @@ describe Object, "#guard" do guard -> { false } do ScratchPad.record :yield1 end - ScratchPad.recorded.should == :yield1 + expect(ScratchPad.recorded).to eq(:yield1) guard -> { true } do ScratchPad.record :yield2 end - ScratchPad.recorded.should == :yield2 + expect(ScratchPad.recorded).to eq(:yield2) end it "yields if MSpec.mode?(:verify) is true" do @@ -318,12 +318,12 @@ describe Object, "#guard" do guard -> { false } do ScratchPad.record :yield1 end - ScratchPad.recorded.should == :yield1 + expect(ScratchPad.recorded).to eq(:yield1) guard -> { true } do ScratchPad.record :yield2 end - ScratchPad.recorded.should == :yield2 + expect(ScratchPad.recorded).to eq(:yield2) end it "yields if MSpec.mode?(:report) is true" do @@ -332,72 +332,72 @@ describe Object, "#guard" do guard -> { false } do ScratchPad.record :yield1 end - ScratchPad.recorded.should == :yield1 + expect(ScratchPad.recorded).to eq(:yield1) guard -> { true } do ScratchPad.record :yield2 end - ScratchPad.recorded.should == :yield2 + expect(ScratchPad.recorded).to eq(:yield2) end it "raises an error if no Proc is given" do - -> { guard :foo }.should raise_error(RuntimeError) + expect { guard :foo }.to raise_error(RuntimeError) end it "requires a block" do - -> { + expect { guard(-> { true }) - }.should raise_error(LocalJumpError) - -> { + }.to raise_error(LocalJumpError) + expect { guard(-> { false }) - }.should raise_error(LocalJumpError) + }.to raise_error(LocalJumpError) end end -describe Object, "#guard_not" do +RSpec.describe Object, "#guard_not" do before :each do ScratchPad.clear end it "allows to combine guards" do guard1 = VersionGuard.new '1.2.3', 'x.x.x' - VersionGuard.stub(:new).and_return(guard1) + allow(VersionGuard).to receive(:new).and_return(guard1) guard2 = PlatformGuard.new :dummy - PlatformGuard.stub(:new).and_return(guard2) + allow(PlatformGuard).to receive(:new).and_return(guard2) - guard1.stub(:match?).and_return(true) - guard2.stub(:match?).and_return(true) + allow(guard1).to receive(:match?).and_return(true) + allow(guard2).to receive(: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) + allow(guard1).to receive(:match?).and_return(false) + allow(guard2).to receive(:match?).and_return(true) guard_not -> { ruby_version_is "2.4" and platform_is :linux } do ScratchPad.record :yield1 end - ScratchPad.recorded.should == :yield1 + expect(ScratchPad.recorded).to eq(:yield1) - guard1.stub(:match?).and_return(true) - guard2.stub(:match?).and_return(false) + allow(guard1).to receive(:match?).and_return(true) + allow(guard2).to receive(:match?).and_return(false) guard_not -> { ruby_version_is "2.4" and platform_is :linux } do ScratchPad.record :yield2 end - ScratchPad.recorded.should == :yield2 + expect(ScratchPad.recorded).to eq(:yield2) - guard1.stub(:match?).and_return(false) - guard2.stub(:match?).and_return(false) + allow(guard1).to receive(:match?).and_return(false) + allow(guard2).to receive(:match?).and_return(false) guard_not -> { ruby_version_is "2.4" and platform_is :linux } do ScratchPad.record :yield3 end - ScratchPad.recorded.should == :yield3 + expect(ScratchPad.recorded).to eq(:yield3) end it "yields when the Proc returns false" do guard_not -> { false } do ScratchPad.record :yield end - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield when the Proc returns true" do @@ -407,15 +407,15 @@ describe Object, "#guard_not" do end it "raises an error if no Proc is given" do - -> { guard_not :foo }.should raise_error(RuntimeError) + expect { guard_not :foo }.to raise_error(RuntimeError) end it "requires a block" do - -> { + expect { guard_not(-> { true }) - }.should raise_error(LocalJumpError) - -> { + }.to raise_error(LocalJumpError) + expect { guard_not(-> { false }) - }.should raise_error(LocalJumpError) + }.to raise_error(LocalJumpError) end end diff --git a/spec/mspec/spec/guards/platform_spec.rb b/spec/mspec/spec/guards/platform_spec.rb index 6088fb2ba6..88a7ad86f2 100644 --- a/spec/mspec/spec/guards/platform_spec.rb +++ b/spec/mspec/spec/guards/platform_spec.rb @@ -1,252 +1,252 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#platform_is" do +RSpec.describe Object, "#platform_is" do before :each do @guard = PlatformGuard.new :dummy - PlatformGuard.stub(:new).and_return(@guard) + allow(PlatformGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "does not yield when #os? returns false" do - PlatformGuard.stub(:os?).and_return(false) + allow(PlatformGuard).to receive(:os?).and_return(false) platform_is(:ruby) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "yields when #os? returns true" do - PlatformGuard.stub(:os?).and_return(true) + allow(PlatformGuard).to receive(:os?).and_return(true) platform_is(:solarce) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(: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 + allow(PlatformGuard).to receive(:os?).and_return(true) + expect(platform_is(:solarce)).to eq(true) + allow(PlatformGuard).to receive(:os?).and_return(false) + expect(platform_is(:solarce)).to eq(false) end it "sets the name of the guard to :platform_is" do platform_is(:solarce) { } - @guard.name.should == :platform_is + expect(@guard.name).to eq(:platform_is) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(true) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(true) + expect(@guard).to receive(:unregister) + expect do platform_is(:solarce) { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#platform_is_not" do +RSpec.describe Object, "#platform_is_not" do before :each do @guard = PlatformGuard.new :dummy - PlatformGuard.stub(:new).and_return(@guard) + allow(PlatformGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "does not yield when #os? returns true" do - PlatformGuard.stub(:os?).and_return(true) + allow(PlatformGuard).to receive(:os?).and_return(true) platform_is_not(:ruby) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "yields when #os? returns false" do - PlatformGuard.stub(:os?).and_return(false) + allow(PlatformGuard).to receive(:os?).and_return(false) platform_is_not(:solarce) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(: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 + allow(PlatformGuard).to receive(:os?).and_return(true) + expect(platform_is_not(:solarce)).to eq(false) + allow(PlatformGuard).to receive(:os?).and_return(false) + expect(platform_is_not(:solarce)).to eq(true) end it "sets the name of the guard to :platform_is_not" do platform_is_not(:solarce) { } - @guard.name.should == :platform_is_not + expect(@guard.name).to eq(:platform_is_not) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(false) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(false) + expect(@guard).to receive(:unregister) + expect do platform_is_not(:solarce) { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#platform_is :wordsize => SIZE_SPEC" do +RSpec.describe Object, "#platform_is :wordsize => SIZE_SPEC" do before :each do @guard = PlatformGuard.new :darwin, :wordsize => 32 - PlatformGuard.stub(:os?).and_return(true) - PlatformGuard.stub(:new).and_return(@guard) + allow(PlatformGuard).to receive(:os?).and_return(true) + allow(PlatformGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields when #wordsize? returns true" do - PlatformGuard.stub(:wordsize?).and_return(true) + allow(PlatformGuard).to receive(:wordsize?).and_return(true) platform_is(:wordsize => 32) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "doesn not yield when #wordsize? returns false" do - PlatformGuard.stub(:wordsize?).and_return(false) + allow(PlatformGuard).to receive(:wordsize?).and_return(false) platform_is(:wordsize => 32) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end -describe Object, "#platform_is_not :wordsize => SIZE_SPEC" do +RSpec.describe Object, "#platform_is_not :wordsize => SIZE_SPEC" do before :each do @guard = PlatformGuard.new :darwin, :wordsize => 32 - PlatformGuard.stub(:os?).and_return(true) - PlatformGuard.stub(:new).and_return(@guard) + allow(PlatformGuard).to receive(:os?).and_return(true) + allow(PlatformGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields when #wordsize? returns false" do - PlatformGuard.stub(:wordsize?).and_return(false) + allow(PlatformGuard).to receive(:wordsize?).and_return(false) platform_is_not(:wordsize => 32) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "doesn not yield when #wordsize? returns true" do - PlatformGuard.stub(:wordsize?).and_return(true) + allow(PlatformGuard).to receive(:wordsize?).and_return(true) platform_is_not(:wordsize => 32) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end -describe PlatformGuard, ".implementation?" do +RSpec.describe PlatformGuard, ".implementation?" do it "returns true if passed :ruby and RUBY_ENGINE == 'ruby'" do stub_const 'RUBY_ENGINE', 'ruby' - PlatformGuard.implementation?(:ruby).should == true + expect(PlatformGuard.implementation?(:ruby)).to eq(true) end it "returns true if passed :rubinius and RUBY_ENGINE == 'rbx'" do stub_const 'RUBY_ENGINE', 'rbx' - PlatformGuard.implementation?(:rubinius).should == true + expect(PlatformGuard.implementation?(:rubinius)).to eq(true) end it "returns true if passed :jruby and RUBY_ENGINE == 'jruby'" do stub_const 'RUBY_ENGINE', 'jruby' - PlatformGuard.implementation?(:jruby).should == true + expect(PlatformGuard.implementation?(:jruby)).to eq(true) end it "returns true if passed :ironruby and RUBY_ENGINE == 'ironruby'" do stub_const 'RUBY_ENGINE', 'ironruby' - PlatformGuard.implementation?(:ironruby).should == true + expect(PlatformGuard.implementation?(:ironruby)).to eq(true) end it "returns true if passed :maglev and RUBY_ENGINE == 'maglev'" do stub_const 'RUBY_ENGINE', 'maglev' - PlatformGuard.implementation?(:maglev).should == true + expect(PlatformGuard.implementation?(:maglev)).to eq(true) end it "returns true if passed :topaz and RUBY_ENGINE == 'topaz'" do stub_const 'RUBY_ENGINE', 'topaz' - PlatformGuard.implementation?(:topaz).should == true + expect(PlatformGuard.implementation?(:topaz)).to eq(true) end it "returns true if passed :ruby and RUBY_ENGINE matches /^ruby/" do stub_const 'RUBY_ENGINE', 'ruby' - PlatformGuard.implementation?(:ruby).should == true + expect(PlatformGuard.implementation?(:ruby)).to eq(true) stub_const 'RUBY_ENGINE', 'ruby1.8' - PlatformGuard.implementation?(:ruby).should == true + expect(PlatformGuard.implementation?(:ruby)).to eq(true) stub_const 'RUBY_ENGINE', 'ruby1.9' - PlatformGuard.implementation?(:ruby).should == true + expect(PlatformGuard.implementation?(:ruby)).to eq(true) end it "works for an unrecognized name" do stub_const 'RUBY_ENGINE', 'myrubyimplementation' - PlatformGuard.implementation?(:myrubyimplementation).should == true - PlatformGuard.implementation?(:other).should == false + expect(PlatformGuard.implementation?(:myrubyimplementation)).to eq(true) + expect(PlatformGuard.implementation?(:other)).to eq(false) end end -describe PlatformGuard, ".standard?" do +RSpec.describe PlatformGuard, ".standard?" do it "returns true if implementation? returns true" do - PlatformGuard.should_receive(:implementation?).with(:ruby).and_return(true) - PlatformGuard.standard?.should be_true + expect(PlatformGuard).to receive(:implementation?).with(:ruby).and_return(true) + expect(PlatformGuard.standard?).to be_truthy end it "returns false if implementation? returns false" do - PlatformGuard.should_receive(:implementation?).with(:ruby).and_return(false) - PlatformGuard.standard?.should be_false + expect(PlatformGuard).to receive(:implementation?).with(:ruby).and_return(false) + expect(PlatformGuard.standard?).to be_falsey end end -describe PlatformGuard, ".wordsize?" do +RSpec.describe PlatformGuard, ".wordsize?" do it "returns true when arg is 32 and 1.size is 4" do - PlatformGuard.wordsize?(32).should == (1.size == 4) + expect(PlatformGuard.wordsize?(32)).to eq(1.size == 4) end it "returns true when arg is 64 and 1.size is 8" do - PlatformGuard.wordsize?(64).should == (1.size == 8) + expect(PlatformGuard.wordsize?(64)).to eq(1.size == 8) end end -describe PlatformGuard, ".os?" do +RSpec.describe PlatformGuard, ".os?" do before :each do stub_const 'PlatformGuard::PLATFORM', 'solarce' end it "returns false when arg does not match the platform" do - PlatformGuard.os?(:ruby).should == false + expect(PlatformGuard.os?(:ruby)).to eq(false) end it "returns false when no arg matches the platform" do - PlatformGuard.os?(:ruby, :jruby, :rubinius, :maglev).should == false + expect(PlatformGuard.os?(:ruby, :jruby, :rubinius, :maglev)).to eq(false) end it "returns true when arg matches the platform" do - PlatformGuard.os?(:solarce).should == true + expect(PlatformGuard.os?(:solarce)).to eq(true) end it "returns true when any arg matches the platform" do - PlatformGuard.os?(:ruby, :jruby, :solarce, :rubinius, :maglev).should == true + expect(PlatformGuard.os?(:ruby, :jruby, :solarce, :rubinius, :maglev)).to eq(true) end it "returns true when arg is :windows and the platform contains 'mswin'" do stub_const 'PlatformGuard::PLATFORM', 'mswin32' - PlatformGuard.os?(:windows).should == true + expect(PlatformGuard.os?(:windows)).to eq(true) end it "returns true when arg is :windows and the platform contains 'mingw'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.os?(:windows).should == true + expect(PlatformGuard.os?(:windows)).to eq(true) end it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mswin32' - PlatformGuard.os?(:linux).should == false + expect(PlatformGuard.os?(:linux)).to eq(false) end it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.os?(:linux).should == false + expect(PlatformGuard.os?(:linux)).to eq(false) end end -describe PlatformGuard, ".os?" do +RSpec.describe PlatformGuard, ".os?" do it "returns true if called with the current OS or architecture" do os = RbConfig::CONFIG["host_os"].sub("-gnu", "") arch = RbConfig::CONFIG["host_arch"] - PlatformGuard.os?(os).should == true - PlatformGuard.os?(arch).should == true - PlatformGuard.os?("#{arch}-#{os}").should == true + expect(PlatformGuard.os?(os)).to eq(true) + expect(PlatformGuard.os?(arch)).to eq(true) + expect(PlatformGuard.os?("#{arch}-#{os}")).to eq(true) end end -describe PlatformGuard, ".os? on JRuby" do +RSpec.describe PlatformGuard, ".os? on JRuby" do before :all do @verbose = $VERBOSE $VERBOSE = nil @@ -266,72 +266,72 @@ describe PlatformGuard, ".os? on JRuby" do end it "raises an error when testing for a :java platform" do - lambda { + expect { PlatformGuard.os?(:java) - }.should raise_error(":java is not a valid OS") + }.to raise_error(":java is not a valid OS") end it "returns true when arg is :windows and RUBY_PLATFORM contains 'java' and os?(:windows) is true" do stub_const 'PlatformGuard::PLATFORM', 'mswin32' - PlatformGuard.os?(:windows).should == true + expect(PlatformGuard.os?(:windows)).to eq(true) end it "returns true when RUBY_PLATFORM contains 'java' and os?(argument) is true" do stub_const 'PlatformGuard::PLATFORM', 'amiga' - PlatformGuard.os?(:amiga).should == true + expect(PlatformGuard.os?(:amiga)).to eq(true) end end -describe PlatformGuard, ".os?" do +RSpec.describe PlatformGuard, ".os?" do before :each do stub_const 'PlatformGuard::PLATFORM', 'unreal' end it "returns true if argument matches RbConfig::CONFIG['host_os']" do - PlatformGuard.os?(:unreal).should == true + expect(PlatformGuard.os?(:unreal)).to eq(true) end it "returns true if any argument matches RbConfig::CONFIG['host_os']" do - PlatformGuard.os?(:bsd, :unreal, :amiga).should == true + expect(PlatformGuard.os?(:bsd, :unreal, :amiga)).to eq(true) end it "returns false if no argument matches RbConfig::CONFIG['host_os']" do - PlatformGuard.os?(:bsd, :netbsd, :amiga, :msdos).should == false + expect(PlatformGuard.os?(:bsd, :netbsd, :amiga, :msdos)).to eq(false) end it "returns false if argument does not match RbConfig::CONFIG['host_os']" do - PlatformGuard.os?(:amiga).should == false + expect(PlatformGuard.os?(:amiga)).to eq(false) end it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mswin32' - PlatformGuard.os?(:windows).should == true + expect(PlatformGuard.os?(:windows)).to eq(true) end it "returns true when arg is :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.os?(:windows).should == true + expect(PlatformGuard.os?(:windows)).to eq(true) end it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mswin'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.os?(:linux).should == false + expect(PlatformGuard.os?(:linux)).to eq(false) end it "returns false when arg is not :windows and RbConfig::CONFIG['host_os'] contains 'mingw'" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.os?(:linux).should == false + expect(PlatformGuard.os?(:linux)).to eq(false) end end -describe PlatformGuard, ".windows?" do +RSpec.describe PlatformGuard, ".windows?" do it "returns true on windows" do stub_const 'PlatformGuard::PLATFORM', 'i386-mingw32' - PlatformGuard.windows?.should == true + expect(PlatformGuard.windows?).to eq(true) end it "returns false on non-windows" do stub_const 'PlatformGuard::PLATFORM', 'i586-linux' - PlatformGuard.windows?.should == false + expect(PlatformGuard.windows?).to eq(false) end end diff --git a/spec/mspec/spec/guards/quarantine_spec.rb b/spec/mspec/spec/guards/quarantine_spec.rb index e5c7da7939..eb5ff1da27 100644 --- a/spec/mspec/spec/guards/quarantine_spec.rb +++ b/spec/mspec/spec/guards/quarantine_spec.rb @@ -1,35 +1,35 @@ require 'spec_helper' require 'mspec/guards' -describe QuarantineGuard, "#match?" do +RSpec.describe QuarantineGuard, "#match?" do it "returns true" do - QuarantineGuard.new.match?.should == true + expect(QuarantineGuard.new.match?).to eq(true) end end -describe Object, "#quarantine!" do +RSpec.describe Object, "#quarantine!" do before :each do ScratchPad.clear @guard = QuarantineGuard.new - QuarantineGuard.stub(:new).and_return(@guard) + allow(QuarantineGuard).to receive(:new).and_return(@guard) end it "does not yield" do quarantine! { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "sets the name of the guard to :quarantine!" do quarantine! { } - @guard.name.should == :quarantine! + expect(@guard.name).to eq(:quarantine!) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(false) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(false) + expect(@guard).to receive(:unregister) + expect do quarantine! { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/superuser_spec.rb b/spec/mspec/spec/guards/superuser_spec.rb index f8815057e1..aba2cc2bb0 100644 --- a/spec/mspec/spec/guards/superuser_spec.rb +++ b/spec/mspec/spec/guards/superuser_spec.rb @@ -1,35 +1,35 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#as_superuser" do +RSpec.describe Object, "#as_superuser" do before :each do @guard = SuperUserGuard.new - SuperUserGuard.stub(:new).and_return(@guard) + allow(SuperUserGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "does not yield when Process.euid is not 0" do - Process.stub(:euid).and_return(501) + allow(Process).to receive(:euid).and_return(501) as_superuser { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "yields when Process.euid is 0" do - Process.stub(:euid).and_return(0) + allow(Process).to receive(:euid).and_return(0) as_superuser { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "sets the name of the guard to :as_superuser" do as_superuser { } - @guard.name.should == :as_superuser + expect(@guard.name).to eq(:as_superuser) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(true) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(true) + expect(@guard).to receive(:unregister) + expect do as_superuser { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/support_spec.rb b/spec/mspec/spec/guards/support_spec.rb index 38414abebd..a61d003d6c 100644 --- a/spec/mspec/spec/guards/support_spec.rb +++ b/spec/mspec/spec/guards/support_spec.rb @@ -1,54 +1,54 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#not_supported_on" do +RSpec.describe Object, "#not_supported_on" do before :each do ScratchPad.clear end it "raises an Exception when passed :ruby" do stub_const "RUBY_ENGINE", "jruby" - lambda { + expect { not_supported_on(:ruby) { ScratchPad.record :yield } - }.should raise_error(Exception) - ScratchPad.recorded.should_not == :yield + }.to raise_error(Exception) + expect(ScratchPad.recorded).not_to eq(:yield) end it "does not yield when #implementation? returns true" do stub_const "RUBY_ENGINE", "jruby" not_supported_on(:jruby) { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end it "yields when #standard? returns true" do stub_const "RUBY_ENGINE", "ruby" not_supported_on(:rubinius) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "yields when #implementation? returns false" do stub_const "RUBY_ENGINE", "jruby" not_supported_on(:rubinius) { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end end -describe Object, "#not_supported_on" do +RSpec.describe Object, "#not_supported_on" do before :each do @guard = SupportedGuard.new - SupportedGuard.stub(:new).and_return(@guard) + allow(SupportedGuard).to receive(:new).and_return(@guard) end it "sets the name of the guard to :not_supported_on" do not_supported_on(:rubinius) { } - @guard.name.should == :not_supported_on + expect(@guard.name).to eq(:not_supported_on) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(false) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(false) + expect(@guard).to receive(:unregister) + expect do not_supported_on(:rubinius) { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end diff --git a/spec/mspec/spec/guards/user_spec.rb b/spec/mspec/spec/guards/user_spec.rb index 2de4db7390..2526504656 100644 --- a/spec/mspec/spec/guards/user_spec.rb +++ b/spec/mspec/spec/guards/user_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' require 'mspec/guards' -describe Object, "#as_user" do +RSpec.describe Object, "#as_user" do before :each do ScratchPad.clear end it "yields when the Process.euid is not 0" do - Process.stub(:euid).and_return(501) + allow(Process).to receive(:euid).and_return(501) as_user { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield when the Process.euid is 0" do - Process.stub(:euid).and_return(0) + allow(Process).to receive(:euid).and_return(0) as_user { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(:yield) end end diff --git a/spec/mspec/spec/guards/version_spec.rb b/spec/mspec/spec/guards/version_spec.rb index b0025efcfb..5a5f4ddc3b 100644 --- a/spec/mspec/spec/guards/version_spec.rb +++ b/spec/mspec/spec/guards/version_spec.rb @@ -11,102 +11,102 @@ require 'mspec/guards' # is as typically understood: a..b means v >= a and v <= b; # a...b means v >= a and v < b. -describe VersionGuard, "#match?" do +RSpec.describe VersionGuard, "#match?" do before :each do hide_deprecation_warnings @current = '1.8.6' end it "returns true when the argument is equal to RUBY_VERSION" do - VersionGuard.new(@current, '1.8.6').match?.should == true + expect(VersionGuard.new(@current, '1.8.6').match?).to eq(true) end it "returns true when the argument is less than RUBY_VERSION" do - VersionGuard.new(@current, '1.8').match?.should == true - VersionGuard.new(@current, '1.8.5').match?.should == true + expect(VersionGuard.new(@current, '1.8').match?).to eq(true) + expect(VersionGuard.new(@current, '1.8.5').match?).to eq(true) end it "returns false when the argument is greater than RUBY_VERSION" do - VersionGuard.new(@current, '1.8.7').match?.should == false - VersionGuard.new(@current, '1.9.2').match?.should == false + expect(VersionGuard.new(@current, '1.8.7').match?).to eq(false) + expect(VersionGuard.new(@current, '1.9.2').match?).to eq(false) end it "returns true when the argument range includes RUBY_VERSION" do - VersionGuard.new(@current, '1.8.5'..'1.8.7').match?.should == true - VersionGuard.new(@current, '1.8'..'1.9').match?.should == true - VersionGuard.new(@current, '1.8'...'1.9').match?.should == true - VersionGuard.new(@current, '1.8'..'1.8.6').match?.should == true - VersionGuard.new(@current, '1.8.5'..'1.8.6').match?.should == true - VersionGuard.new(@current, ''...'1.8.7').match?.should == true + expect(VersionGuard.new(@current, '1.8.5'..'1.8.7').match?).to eq(true) + expect(VersionGuard.new(@current, '1.8'..'1.9').match?).to eq(true) + expect(VersionGuard.new(@current, '1.8'...'1.9').match?).to eq(true) + expect(VersionGuard.new(@current, '1.8'..'1.8.6').match?).to eq(true) + expect(VersionGuard.new(@current, '1.8.5'..'1.8.6').match?).to eq(true) + expect(VersionGuard.new(@current, ''...'1.8.7').match?).to eq(true) end it "returns false when the argument range does not include RUBY_VERSION" do - VersionGuard.new(@current, '1.8.7'..'1.8.9').match?.should == false - VersionGuard.new(@current, '1.8.4'..'1.8.5').match?.should == false - VersionGuard.new(@current, '1.8.4'...'1.8.6').match?.should == false - VersionGuard.new(@current, '1.8.5'...'1.8.6').match?.should == false - VersionGuard.new(@current, ''...'1.8.6').match?.should == false + expect(VersionGuard.new(@current, '1.8.7'..'1.8.9').match?).to eq(false) + expect(VersionGuard.new(@current, '1.8.4'..'1.8.5').match?).to eq(false) + expect(VersionGuard.new(@current, '1.8.4'...'1.8.6').match?).to eq(false) + expect(VersionGuard.new(@current, '1.8.5'...'1.8.6').match?).to eq(false) + expect(VersionGuard.new(@current, ''...'1.8.6').match?).to eq(false) end end -describe Object, "#ruby_version_is" do +RSpec.describe Object, "#ruby_version_is" do before :each do @guard = VersionGuard.new '1.2.3', 'x.x.x' - VersionGuard.stub(:new).and_return(@guard) + allow(VersionGuard).to receive(:new).and_return(@guard) ScratchPad.clear end it "yields when #match? returns true" do - @guard.stub(:match?).and_return(true) + allow(@guard).to receive(:match?).and_return(true) ruby_version_is('x.x.x') { ScratchPad.record :yield } - ScratchPad.recorded.should == :yield + expect(ScratchPad.recorded).to eq(:yield) end it "does not yield when #match? returns false" do - @guard.stub(:match?).and_return(false) + allow(@guard).to receive(:match?).and_return(false) ruby_version_is('x.x.x') { ScratchPad.record :yield } - ScratchPad.recorded.should_not == :yield + expect(ScratchPad.recorded).not_to eq(: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 + allow(@guard).to receive(:match?).and_return(true) + expect(ruby_version_is('x.x.x')).to eq(true) + allow(@guard).to receive(:match?).and_return(false) + expect(ruby_version_is('x.x.x')).to eq(false) end it "sets the name of the guard to :ruby_version_is" do ruby_version_is("") { } - @guard.name.should == :ruby_version_is + expect(@guard.name).to eq(:ruby_version_is) end it "calls #unregister even when an exception is raised in the guard block" do - @guard.should_receive(:match?).and_return(true) - @guard.should_receive(:unregister) - lambda do + expect(@guard).to receive(:match?).and_return(true) + expect(@guard).to receive(:unregister) + expect do ruby_version_is("") { raise Exception } - end.should raise_error(Exception) + end.to raise_error(Exception) end end -describe Object, "#version_is" do +RSpec.describe Object, "#version_is" do before :each do hide_deprecation_warnings end it "returns the expected values" do - version_is('1.2.3', '1.2.2').should == true - version_is('1.2.3', '1.2.3').should == true - version_is('1.2.3', '1.2.4').should == false - - version_is('1.2.3', '1').should == true - version_is('1.2.3', '1.0').should == true - version_is('1.2.3', '2').should == false - version_is('1.2.3', '2.0').should == false - - version_is('1.2.3', '1.2.2'..'1.2.4').should == true - version_is('1.2.3', '1.2.2'..'1.2.3').should == true - version_is('1.2.3', '1.2.2'...'1.2.3').should == false - version_is('1.2.3', '1.2.3'..'1.2.4').should == true + expect(version_is('1.2.3', '1.2.2')).to eq(true) + expect(version_is('1.2.3', '1.2.3')).to eq(true) + expect(version_is('1.2.3', '1.2.4')).to eq(false) + + expect(version_is('1.2.3', '1')).to eq(true) + expect(version_is('1.2.3', '1.0')).to eq(true) + expect(version_is('1.2.3', '2')).to eq(false) + expect(version_is('1.2.3', '2.0')).to eq(false) + + expect(version_is('1.2.3', '1.2.2'..'1.2.4')).to eq(true) + expect(version_is('1.2.3', '1.2.2'..'1.2.3')).to eq(true) + expect(version_is('1.2.3', '1.2.2'...'1.2.3')).to eq(false) + expect(version_is('1.2.3', '1.2.3'..'1.2.4')).to eq(true) end end |