Created
February 1, 2012 19:46
-
-
Save Sephi-Chan/1718889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Attacker | |
def attack(target) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Target | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment