From fb416df42c3c21ede4431dba04be3c4762f196bf Mon Sep 17 00:00:00 2001 From: Ho-Sheng Hsiao Date: Tue, 25 May 2010 19:38:18 -0400 Subject: [PATCH] [AM/ARCH] Simplified loading scheme for Remarkable::ActiveModel --- path_helpers.rb | 12 ++++++---- .../lib/remarkable/active_model.rb | 24 ++++--------------- remarkable_activemodel/spec/spec_helper.rb | 24 ++++++++----------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/path_helpers.rb b/path_helpers.rb index a97cd6e..91966de 100644 --- a/path_helpers.rb +++ b/path_helpers.rb @@ -1,8 +1,10 @@ # encoding: utf-8 -def load_project_path(project) - project = project.to_s - project_path = File.join(File.dirname(__FILE__), project, 'lib') - return nil if $LOAD_PATH.include?(File.expand_path(project_path)) - $LOAD_PATH.unshift(File.expand_path(project_path)) +def load_project_path(*projects) + projects.each do |project| + project = project.to_s + project_path = File.join(File.dirname(__FILE__), project, 'lib') + return nil if $LOAD_PATH.include?(File.expand_path(project_path)) + $LOAD_PATH.unshift(File.expand_path(project_path)) + end end diff --git a/remarkable_activemodel/lib/remarkable/active_model.rb b/remarkable_activemodel/lib/remarkable/active_model.rb index ad75249..a892e4c 100644 --- a/remarkable_activemodel/lib/remarkable/active_model.rb +++ b/remarkable_activemodel/lib/remarkable/active_model.rb @@ -1,28 +1,14 @@ # Load Remarkable -unless Object.const_defined?('Remarkable') - begin - require 'remarkable' - rescue LoadError - require 'rubygems' - gem 'remarkable' - require 'remarkable' - end -end +require 'remarkable' +require 'remarkable/active_model/base' -# Load Remarkable ActiveModel files +# Add default locale dir = File.dirname(__FILE__) -require File.join(dir, 'active_model', 'base') - -# Add locale -Remarkable.add_locale File.join(dir, '..', '..', 'locale', 'en.yml') +Dir["#{dir}/../../locale/*yml"].each {|f| Remarkable.add_locale(f) } # Add matchers Dir[File.join(dir, 'active_model', 'matchers', '*.rb')].each do |file| require file end -# By default, ActiveModel matchers are not included in any example group. -# The responsibility for this is RemarkableRails. If you are using ActiveModel -# without Rails, put the line below in your spec_helper to include ActiveModel -# matchers into rspec globally. -# Remarkable.include_matchers!(Remarkable::ActiveModel, Rspec::Example::ExampleGroup) +Remarkable.include_matchers!(Remarkable::ActiveModel, Rspec::Core::ExampleGroup) diff --git a/remarkable_activemodel/spec/spec_helper.rb b/remarkable_activemodel/spec/spec_helper.rb index 15077ee..f4b87bf 100644 --- a/remarkable_activemodel/spec/spec_helper.rb +++ b/remarkable_activemodel/spec/spec_helper.rb @@ -1,26 +1,22 @@ -# encoding: utf-8 -require 'rubygems' +$TESTING=true +require 'rubygems' require 'rspec' RAILS_VERSION = ENV['RAILS_VERSION'] || '3.0.0.beta3' gem 'activesupport', RAILS_VERSION require 'active_support/all' - -gem 'activemodel', RAILS_VERSION require 'active_model' -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +require File.expand_path('path_helpers', File.join(File.dirname(__FILE__), '/../../')) +load_project_path :remarkable, :remarkable_activemodel -# Load Remarkable core on place to avoid gem to be loaded -dir = File.dirname(__FILE__) -require File.join(dir, '..', '..', 'remarkable', 'lib', 'remarkable') +require 'remarkable/active_model' -# Load Remarkable ActiveModel -require File.join(dir, '..', 'lib', 'remarkable_activemodel') +# Requires supporting files with custom matchers and macros, etc, +# # in ./support/ and its subdirectories. +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} -# Include matchers -Remarkable.include_matchers!(Remarkable::ActiveModel, Rspec::Core::ExampleGroup) +# Load custom matchers +#Remarkable.include_matchers!(Remarkable::Rspec, Rspec::Core::ExampleGroup)