Sha256: 2fa4b07177153e47eca94a6cdf052fd41df01831b341f0f7495f10eb5f171c3b

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'rails/all'
require 'rails/generators'
require 'rails/generators/test_case'
require 'generator_spec/rspec_generator/configure'

module RSpec::Generator
  class << self    
    attr_accessor :generator, :test_method_name, :remove_temp_dir, :debug

    def debug?
      debug
    end

    def remove_rails_dir!
      FileUtils.rm_rf ::TmpRails.root
    end

    def run_generator *args, &block 
      generator.run_generator *args
      if block
        block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self)  
      end      
    end

    def with_generator &block
      with(get_generator, &block)
    end

    def setup_generator test_method_name=nil, &block
      clean! if test_method_name  
      generator = get_generator(test_method_name).extend(RSpec::Generator::Helpers)
      if block
        block.arity < 1 ? generator.class.instance_eval(&block) : block.call(generator.class)  
      end
    end
    
    protected

    def with(generator, &block)
      if block
        block.arity < 1 ? generator.instance_eval(&block) : block.call(generator, self, generator.class)  
      end
    end
    
    def clean!
      if generator
        generator.class.generator_class = nil 
      end
      @generator = nil
    end
  
    def get_generator test_method_name=nil
      @generator ||= RSpec::Generator::TestCase.new(test_method_name + '_spec')
    end
    
  end # class self
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generator-spec-0.4.4 lib/generator_spec/rspec_generator/generator_util.rb