Sha256: 88894d49336a59fc5558c950aa62e6325579dd63f09ee738bbb91c829989e94f

Contents?: true

Size: 965 Bytes

Versions: 5

Compression:

Stored size: 965 Bytes

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/guards/user'

describe Object, "#as_user" do
  before :each do
    @guard = UserGuard.new
    UserGuard.stub!(:new).and_return(@guard)
    ScratchPad.clear
  end

  it "yields when the Process.euid is not 0" do
    Process.stub!(:euid).and_return(501)
    as_user { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end

  it "does not yield when the Process.euid is 0" do
    Process.stub!(:euid).and_return(0)
    as_user { ScratchPad.record :yield }
    ScratchPad.recorded.should_not == :yield
  end

  it "sets the name of the guard to :as_user" do
    as_user { }
    @guard.name.should == :as_user
  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
      as_user { raise Exception }
    end.should raise_error(Exception)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mspec-1.5.17 spec/guards/user_spec.rb
mspec-1.5.16 spec/guards/user_spec.rb
mspec-1.5.15 spec/guards/user_spec.rb
mspec-1.5.14 spec/guards/user_spec.rb
mspec-1.5.13 spec/guards/user_spec.rb