Created
March 5, 2019 11:49
-
-
Save yevgenko/a71397e1730a49c313d68a38287a4347 to your computer and use it in GitHub Desktop.
Self Shunt vs Fake Object in Ruby / RSpec
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 Fubarizable | |
def fubarize | |
"foobar-#{fubarizable}-foobar" | |
end | |
end | |
class FakeFoobar | |
include Fubarizable | |
def fubarizable | |
"fake" | |
end | |
end | |
describe "Fubarizable" do | |
context "with fake object" do | |
it 'is fubarized' do | |
expect(FakeFoobar.new.fubarize).to eq 'foobar-fake-foobar' | |
end | |
end | |
context "with self shunt pattern" do | |
include Fubarizable | |
it 'is fubarized' do | |
expect(fubarize).to eq "foobar-self_shunt-foobar" | |
end | |
def fubarizable | |
'self_shunt' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment