Sha256: 7438ff2d355f10c7445b38b10b26f9b656c19243d25e6d4ceb788c6907fecbe0

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require File.dirname(__FILE__) + "/../spec_helper.rb"

class ClrModels::Sword

  def to_s
    "<ClrModels::Sword object_id: #{object_id} >"
  end
  alias_method :inspect, :to_s

end

describe "ClrModels::Sword" do

  before do
    @warrior = Caricature::Isolation.for ClrModels::IWarrior
  end

  it "should call survive_attack on the mock" do
    @warrior.when_receiving(:survive_attack_with).return(5)

    sword = ClrModels::Sword.new
    sword.attack(@warrior).should == 5

    @warrior.did_receive?(:survive_attack_with).should be_successful
  end

  it "should return different results when expectation is defined with arguments" do
    sword1 = ClrModels::Sword.new
    sword2 = ClrModels::Sword.new

    @warrior.when_receiving(:survive_attack_with).with(:any).return(5)
    @warrior.when_receiving(:survive_attack_with).with(sword2).return(15)

    sword1.attack(@warrior).should == 5
    sword2.attack(@warrior).should == 15

    @warrior.did_receive?(:survive_attack_with).with(sword2).should be_successful
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caricature-0.7.7 spec/rspec/unit/sword_spec.rb
caricature-0.7.6 spec/rspec/unit/sword_spec.rb