Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Forked from nathmisaki/gist:376660
Created April 23, 2010 15:27
Show Gist options
  • Save tomas-stefano/376680 to your computer and use it in GitHub Desktop.
Save tomas-stefano/376680 to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] ||= 'test'
require 'rubygems'
require 'spork'
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
require 'spec/autorun'
require 'spec/rails'
require 'authlogic/test_case'
require 'fakeweb'
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.
# 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
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
end
end
Spork.each_run do
# This code will be run each time you run your specs.
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
# - These instructions should self-destruct in 10 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment