Skip to content

Instantly share code, notes, and snippets.

@yevgenko
Created March 5, 2019 11:49
Show Gist options
  • Save yevgenko/a71397e1730a49c313d68a38287a4347 to your computer and use it in GitHub Desktop.
Save yevgenko/a71397e1730a49c313d68a38287a4347 to your computer and use it in GitHub Desktop.
Self Shunt vs Fake Object in Ruby / RSpec
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