Sha256: 86f742d6ee84f76f08e8109b7037cf7e3a5b711721e250fa98f96549c8ab8743

Contents?: true

Size: 1.71 KB

Versions: 6

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'
require 'mspec/guards'

describe Object, "#conflicts_with" do
  before :each do
    ScratchPad.clear
  end

  it "does not yield if Object.constants includes any of the arguments" do
    Object.stub!(:constants).and_return(["SomeClass", "OtherClass"])
    conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield }
    ScratchPad.recorded.should_not == :yield
  end

  it "does not yield if Object.constants (as Symbols) includes any of the arguments" do
    Object.stub!(:constants).and_return([:SomeClass, :OtherClass])
    conflicts_with(:SomeClass, :AClass, :BClass) { ScratchPad.record :yield }
    ScratchPad.recorded.should_not == :yield
  end

  it "yields if Object.constants does not include any of the arguments" do
    Object.stub!(:constants).and_return(["SomeClass", "OtherClass"])
    conflicts_with(:AClass, :BClass) { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end

  it "yields if Object.constants (as Symbols) does not include any of the arguments" do
    Object.stub!(:constants).and_return([:SomeClass, :OtherClass])
    conflicts_with(:AClass, :BClass) { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end
end

describe Object, "#conflicts_with" do
  before :each do
    @guard = ConflictsGuard.new
    ConflictsGuard.stub!(: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
  end

  it "calls #unregister even when an exception is raised in the guard block" do
    @guard.should_receive(:unregister)
    lambda do
      conflicts_with(:AClass, :BClass) { raise Exception }
    end.should raise_error(Exception)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mspec-1.7.0 spec/guards/conflict_spec.rb
mspec-1.6.0 spec/guards/conflict_spec.rb
mspec-1.5.21 spec/guards/conflict_spec.rb
mspec-1.5.20 spec/guards/conflict_spec.rb
mspec-1.5.19 spec/guards/conflict_spec.rb
mspec-1.5.18 spec/guards/conflict_spec.rb