Create a gist now

Instantly share code, notes, and snippets.

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