Created
November 23, 2012 09:04
-
-
Save cheald/4134638 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 'active_support/core_ext/array' | |
class FactoryGirl | |
attr_accessor :options | |
def self.create(model, options = {}) | |
new(model, options) | |
end | |
def initialize(model, options) | |
@model = model | |
@options = options | |
end | |
end | |
class DatabaseCleaner | |
def self.clean; end | |
end | |
def sign_in(u); end | |
def sign_out(u); end | |
def authenticated_as(roles, options = nil, &block) | |
Array.wrap(roles).each do |role| | |
context "when logged in as a #{role}" do | |
before(:each) { | |
options = self.instance_eval &options if options.is_a? Proc | |
@user = FactoryGirl.create role, *Array.wrap(options) | |
sign_in @user | |
} | |
after(:each) { sign_out @user } | |
instance_eval &block | |
end | |
end | |
end | |
describe "Foo" do | |
let(:test_val) { "Test Value" } | |
authenticated_as :user, Proc.new{ {value: test_val.upcase} } do | |
context "A case to populate params" do | |
let(:params) { "original recipe" } | |
specify { params.should == "original recipe" } | |
end | |
context "and a case to reuse them" do | |
let(:params) { "extra crispy" } | |
specify { params.should == "extra crispy"} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment