Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add initial spec helper

  • Loading branch information...
commit 7be19a864a62c67d18cfc1d34c3e79ddd3591b41 1 parent b20c377
@jakeboxer authored
View
8 .gitignore
@@ -16,6 +16,9 @@ bin
# jeweler generated
pkg
+# rspec generated
+spec.log
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
@@ -26,10 +29,9 @@ pkg
# saving you from having to 'pollute' every project you touch with them
#
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
-#
+
# For MacOS:
-#
-#.DS_Store
+.DS_Store
# For TextMate
*.tmproj
View
6 spec/allow_mass_assignment_of_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-describe "AllowMassAssignmentOf" do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
+describe 'AllowMassAssignmentOf' do
+ it 'fails' do
+ fail 'hey buddy, you should probably rename this file and start specing for real'
end
end
View
44 spec/spec_helper.rb
@@ -1,12 +1,54 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'sqlite3'
require 'rspec'
+require 'active_record'
require 'allow_mass_assignment_of'
+require 'rspec/rails/adapters'
+require 'rspec/rails/fixture_support'
+
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
+ActiveRecord::Base.configurations = true
+
+File.open('spec.log', 'w').close
+ActiveRecord::Base.logger = Logger.new('spec.log')
+
+ActiveRecord::Schema.verbose = false
+ActiveRecord::Schema.define :version => 1 do
+ create_table :post do |t|
+ t.string :title
+ t.text :body
+ t.integer :category_id
+ t.timestamps
+ end
+
+ create_table :categories do |t|
+ t.string :name
+ end
+end
+
RSpec.configure do |config|
-
+ config.use_transactional_examples = true
+
+ config.before :each do
+ class ::Category < ActiveRecord::Base
+ has_many :posts
+ end
+
+ class ::Post < ActiveRecord::Base
+ belongs_to :category
+ attr_accessible :title, :body
+ end
+ end
+
+ config.after :each do
+ Object.send :remove_const, :Post
+ Object.send :remove_const, :Category
+ end
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.