Skip to content

Instantly share code, notes, and snippets.

@nathmisaki
Created April 23, 2010 15:19
Show Gist options
  • Save nathmisaki/376660 to your computer and use it in GitHub Desktop.
Save nathmisaki/376660 to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] ||= 'test'
require 'rubygems'
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/autorun'
require 'spec/rails'
require 'authlogic/test_case'
require 'fakeweb'
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
# Uncomment the next line to use webrat's matchers
require 'webrat/integrations/rspec-rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
Spec::Runner.configure do |config|
config.include Authlogic::TestCase
# If you're not using ActiveRecord you should remove these
# lines, delete config/database.yml and disable :active_record
# in your config/boot.rb
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
config.before(:all) { Sham.reset(:before_all) }
config.before(:each) { Sham.reset(:before_each) }
config.before(:suite) do
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
end
# == Fixtures
#
# You can declare fixtures for each example_group like this:
# describe "...." do
# fixtures :table_a, :table_b
#
# Alternatively, if you prefer to declare them only once, you can
# do so right here. Just uncomment the next line and replace the fixture
# names with your fixtures.
#
# config.global_fixtures = :table_a, :table_b
#
# If you declare global fixtures, be aware that they will be declared
# for all of your examples, even those that don't use them.
#
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
#
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
#
# == Mock Framework
#
# RSpec uses it's own mocking framework by default. If you prefer to
# use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
#
# == Notes
#
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
end
if defined?(FakeWeb)
FakeWeb.allow_net_connect = false
def register_cpf_resource_uris(model_class)
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support',model_class.element_name.pluralize,'*'))].each do |file|
cpf = file.split('_').last
raw_response = File.read(file)
FakeWeb.register_uri(:any, "#{model_class.site}#{model_class.element_name.to_s.pluralize}/#{cpf}", :response => raw_response)
FakeWeb.register_uri(:any, "#{model_class.site}#{model_class.element_name.to_s.pluralize}/#{cpf.to_i}", :response => raw_response)
FakeWeb.register_uri(:any, "#{model_class.site}#{model_class.element_name.to_s.pluralize}/#{cpf}.xml", :response => raw_response)
FakeWeb.register_uri(:any, "#{model_class.site}#{model_class.element_name.to_s.pluralize}/#{cpf.to_i}.xml", :response => raw_response)
end
end
register_cpf_resource_uris(RfcpfOnline)
register_cpf_resource_uris(TelefoneOnline)
register_cpf_resource_uris(SinteseCadastralOnline)
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
# --- Instructions ---
# - Sort through your spec_helper file. Place as much environment loading
# code that you don't normally modify during development in the
# Spork.prefork block.
# - Place the rest under Spork.each_run block
# - Any code that is left outside of the blocks will be ran during preforking
# and during each_run!
# - These instructions should self-destruct in 10 seconds. If they don't,
# feel free to delete them.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment