Class: RspecGem
- Inherits:
-
Object
- Object
- RspecGem
- Defined in:
- lib/rspec_gem.rb,
lib/rspec_gem/version.rb
Constant Summary collapse
- VERSION =
"0.2.4"
Class Method Summary collapse
- .name_of_gem ⇒ Object
- .path ⇒ Object
- .path_rails_environment ⇒ Object
-
.require_model_environment ⇒ Object
require active record with database.
-
.require_rails_environment ⇒ Object
require full rails environment.
-
.require_unit_environment ⇒ Object
require simply environment without active records.
Instance Method Summary collapse
-
#initialize(path, name_of_gem) ⇒ RspecGem
constructor
create task for your gem path - path into directory of your gem name_of_gem - name of your gem.
Constructor Details
#initialize(path, name_of_gem) ⇒ RspecGem
create task for your gem path - path into directory of your gem name_of_gem - name of your gem
9 10 11 12 13 |
# File 'lib/rspec_gem.rb', line 9 def initialize(path, name_of_gem) @@path = path @@name_of_gem = name_of_gem load File.("../tasks/rspec_gem.rake", __FILE__) if defined?(Rake) end |
Class Method Details
.name_of_gem ⇒ Object
16 17 18 |
# File 'lib/rspec_gem.rb', line 16 def name_of_gem @@name_of_gem end |
.path ⇒ Object
20 21 22 |
# File 'lib/rspec_gem.rb', line 20 def path @@path end |
.path_rails_environment ⇒ Object
24 25 26 27 |
# File 'lib/rspec_gem.rb', line 24 def path_rails_environment return File.("config/environment", Rails.root) if defined?(Rails) File.("config/environment", ENV["PWD"]) end |
.require_model_environment ⇒ Object
require active record with database
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rspec_gem.rb', line 45 def require_model_environment require_unit_environment ENV["RAILS_ENV"] ||= "test" # ActiveRecord require "yaml" require "active_record" ActiveRecord::Base.establish_connection( YAML.load(File.read(ENV["PWD"] + "/config/database.yml"))["test"] ) # DatabaseCleaner require "database_cleaner" RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end end # configurations into database ActiveRecord::Base.send(:configurations=, YAML::load(ERB.new(IO.read(ENV["PWD"] + "/config/database.yml")).result)) end |
.require_rails_environment ⇒ Object
require full rails environment
30 31 32 |
# File 'lib/rspec_gem.rb', line 30 def require_rails_environment require File.("config/environment", ENV["PWD"]) end |
.require_unit_environment ⇒ Object
require simply environment without active records
35 36 37 38 39 40 41 42 |
# File 'lib/rspec_gem.rb', line 35 def require_unit_environment require "active_support" require "active_support/dependencies" %w{ extensions helpers mailers models presenters }.each do |dir| ActiveSupport::Dependencies.autoload_paths << File.("app/#{dir}", ENV["PWD"]) end end |