Skip to content

Instantly share code, notes, and snippets.

@jwo
Created October 12, 2011 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jwo/1281093 to your computer and use it in GitHub Desktop.
Save jwo/1281093 to your computer and use it in GitHub Desktop.
Fast Rails Tests -- Test in Isolation
class Burro < ActiveRecord::Base
#guacamole defined on schema
def delicious?
BurroDeliciousPolicy.new(self).delicious?
end
end
require_relative '../../app/models/burro_delicious_policy'
describe BurroDeliciousPolicy do
it "should be delicioso if it has guacamole" do
policy = BurroDeliciousPolicy.new(double(:guacamole? => true))
policy.delicious?.should be_true
end
it "should not be delioso if we lack the guac" do
policy = BurroDeliciousPolicy.new(double(:guacamole? => false))
policy.should_not be_delicious
end
end
require_relative '../../app/models/burro_delicious_policy'
describe BurroDeliciousPolicy do
it "should be delicioso if it has guacamole" do
policy = BurroDeliciousPolicy.new(double(:guacamole? => true))
policy.delicious?.should be_true
end
it "should not be delioso if we lack the guac" do
policy = BurroDeliciousPolicy.new(double(:guacamole? => false))
policy.should_not be_delicious
end
end
module ActiveRecord
class Base; end
end
class Burro < ActiveRecord::Base
attr_accessor :guacamole
def guacamole?
@guacamole
end
end
require_relative '../../app/models/burro'
require_relative '../../app/models/burro_delicious_policy'
describe Burro do
it "is delicious with guacamole" do
subject.guacamole = true
subject.should be_delicious
end
it "is not delicious without guacamole" do
subject.guacamole = false
subject.should_not be_delicious
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment