public

Fast Rails Burro Test -- Modules

  • Download Gist
burrito_delicious_policy.rb
Ruby
1 2 3 4 5 6
class BurritoDeliciousPolicy
 
def delicious?(burrito)
burrito.guacamole?
end
end
burrito_delicious_policy_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require_relative '../../app/models/burrito_delicious_policy'
 
describe BurritoDeliciousPolicy do
 
it "should be delicious when there is guac" do
subject.delicious?(stub( :guacamole? => true)).should be_true
end
 
it "should not de delicious without guac" do
subject.delicious?(stub( :guacamole? => false)).should be_false
end
 
end
burro.rb
Ruby
1 2 3 4
class Burro < ActiveRecord::Base
include Deliciousness
# boolean guacamole defined in schema
end
burro_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
require_relative '../../lib/deliciousness'
require_relative '../../app/models/burrito_delicious_policy'
class Burro
include Deliciousness
 
attr_accessor :guacamole
def guacamole?
true
end
end
 
describe Burro do
 
it "should tell the policy to decide if this is delicious" do
our_mock = mock BurritoDeliciousPolicy
our_mock.should_receive(:delicious?)
BurritoDeliciousPolicy.stub(:new => our_mock)
subject.delicious?
end
 
 
end
delicious.rb
Ruby
1 2 3 4 5 6 7
module Deliciousness
 
def delicious?
BurritoDeliciousPolicy.new.delicious?(self)
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.