Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created February 1, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sephi-Chan/1718889 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/1718889 to your computer and use it in GitHub Desktop.
module Attacker
def attack(target)
end
end
class CharacterAttacksAnotherCharacter
attr_reader :attacker, :target
def initialize(attacker, target)
@attacker = attacker.extend(Attacker)
@target = target.extend(Target)
end
def execute
attacker.attack(target)
self
end
end
require 'spec_helper'
describe CharacterAttacksAnotherCharacter do
before do
@luke = stub
@vader = stub
@attack = CharacterAttacksAnotherCharacter.new(@luke, @vader)
end
describe "constructor" do
it "should assign the attacker and the target" do
@attack.attacker.should be(@luke)
@attack.target.should be(@vader)
end
it "should give roles to actors" do
@attack.attacker.should be_an(Attacker)
@attack.target.should be_a(Target)
end
end
describe "#execute" do
# This example tests the implementation. How to test the behaviour instead?
it "should make the attacker to attack the target" do
@luke.should_receive(:attack).with(@vader)
@attack.execute
end
it "should expose the actors" do
@executed_attack = @attack.execute
@executed_attack.attacker.should be(@luke)
@executed_attack.target.should be(@vader)
end
end
end
module Target
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment