Skip to content

Instantly share code, notes, and snippets.

@Peeja
Created June 29, 2012 15:25
Show Gist options
  • Save Peeja/3018590 to your computer and use it in GitHub Desktop.
Save Peeja/3018590 to your computer and use it in GitHub Desktop.
Conditional Whac-A-Mole: Another solution
class User < Struct.new(:username, :followability)
def follow
followability.follow(self)
end
end
class Follow
def self.follow(user)
user.follow
end
end
class PublicFollowability
def follow(user)
Follow.actually_follow(user)
end
end
class PrivateFollowability
def follow(user)
Follow.actually_follow(user) if Follow.confirm_follow(user)
end
end
require_relative "toot"
describe Follow do
context "when the user is public" do
it "follows immediately" do
user = User.new("garybernhardt", PublicFollowability.new)
Follow.should_receive(:actually_follow).with(user)
Follow.follow(user)
end
end
context "when the user is private" do
let(:user) { User.new("garybernhardt", PrivateFollowability.new) }
it "does not follow if the user declines the prompt" do
Follow.stub(:confirm_follow).with(user) { false }
Follow.should_not_receive(:actually_follow).with(user)
Follow.follow(user)
end
it "does not follow if the user declines the prompt" do
Follow.stub(:confirm_follow).with(user) { true }
Follow.should_receive(:actually_follow).with(user)
Follow.follow(user)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment