Skip to content

Commit

Permalink
rspec/spork setup
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Boertien <chris.boertien@gmail.com>
  • Loading branch information
Cluster444 committed Jun 2, 2011
1 parent 2145e74 commit 10a2fa2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ tmp/
.sass-cache/
Gemfile.lock
config/database.yml
.rvmrc
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour --drb
8 changes: 8 additions & 0 deletions Gemfile
Expand Up @@ -9,3 +9,11 @@ gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'therubyracer'

group :test do
gem 'rspec-rails', '2.6.1.beta1'
gem 'spork', '0.9.0.rc8'
gem 'factory_girl_rails', :require => false
gem 'shoulda-matchers'
gem 'faker'
end
6 changes: 6 additions & 0 deletions spec/factories.rb
@@ -0,0 +1,6 @@
require 'factory_girl'

Dir["#{File.dirname(__FILE__)}/factories/**"].each do |f|
fp = File.expand_path(f)
require fp
end
30 changes: 30 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,30 @@
require 'spork'

Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/integrations/rspec2'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
end

RSpec::Matchers.define :have_valid_factory do |factory|
match do |model|
Factory(factory).new_record?.should be_false
end
end
end

Spork.each_run do
require 'factories'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end

17 changes: 17 additions & 0 deletions spec/support/controller_macros.rb
@@ -0,0 +1,17 @@
module ControllerMacros
def login_admin
before :each do
@request.env["devise.mapping"] = Devise.mappings[:user]
@admin = Factory(:admin)
sign_in @admin
end
end

def login_user
before :each do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = Factory(:user)
sign_in @user
end
end
end

0 comments on commit 10a2fa2

Please sign in to comment.