Last active
August 29, 2015 13:56
-
-
Save jennifersmith/9337852 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
require 'rspec/expectations' | |
class Pain | |
def tear_inducing? | |
true | |
end | |
end | |
class Fear | |
def tear_inducing? | |
false | |
end | |
end | |
class Onion | |
attr_reader :spices | |
def initialize properties | |
@spices = [:pain, :fear] | |
end | |
def get_spice spice | |
if(spice == :pain) # cant be arsed to remember how switch sstatements work | |
Pain.new | |
elsif (spice == :fear) | |
Fear.new | |
else | |
nil | |
end | |
end | |
end | |
class Vampire | |
def sent_to_drain? | |
true | |
end | |
end | |
class HaveSpice | |
def initialize(expected) | |
@expected = expected | |
end | |
def matches?(target) | |
target.get_spice(@expected) do |spice| | |
yield( spice) | |
end | |
end | |
def failure_message_for_should | |
"whatever fail" | |
end | |
def failure_message_for_should_not | |
"dont care" | |
end | |
end | |
def have_spice spice | |
HaveSpice.new(spice) | |
end | |
describe "The World" do | |
context "is a vampire" do | |
let(:the_world) { Vampire.new } | |
it "should be sent to dra-ee-a-ee-aaain" do | |
the_world.should be_sent_to_drain | |
end | |
end | |
context "is just a great big onion" do | |
let(:the_world) { Onion.new(size: :great_big) } | |
it "should contain pain and fear as spices that make you cry" do | |
# This doesn't call my block. Actually I have no clue how to passs it in | |
# following this: | |
# http://stackoverflow.com/questions/16222450/custom-rspec-matcher-that-takes-a-block | |
# But I don;t understand how yield() is actually going to do stuff with that block. Confused. | |
the_world.should have_spice(:pain) do |spice| | |
spice.should be_tear_inducing | |
end | |
the_world.should have_spice(:fear) do |spice| | |
spice.should be_tear_inducing | |
end | |
#the less elegant version | |
pain = the_world.get_spice(:pain) | |
pain.should be_tear_inducing | |
fear = the_world.get_spice(:fear) | |
fear.should be_tear_inducing | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment