Sha256: 0872f47443f720347c76f9beb6b551467d23e90cbf3e9aefbdb29a0bdcff88d0

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

require 'rails_generator'
require 'shenandoah/rails/locator'

module Shenandoah
  module Generators
    class ShenSpecGenerator < ::Rails::Generator::NamedBase
      def manifest
        record do |m|
          m.directory "#{spec_path}/#{File.dirname(file_path)}"
          m.template 'javascript_spec.js.erb', "#{spec_path}/#{file_path}_spec.js"
          m.template 'fixture.html.erb', "#{spec_path}/#{file_path}.html"
        end
      end

      def spec_path
        ENV['SHEN_SPEC_PATH'] || Shenandoah::Rails::Locator.new.spec_path.sub(%r{^#{RAILS_ROOT}/}, '')
      end

      def file_path
        super.sub /_spec$/, ''
      end

      def javascript_class_name
        klass, *mods_rev = class_name.sub(/Spec$/, '').split('::').reverse
        mod_spec = mods_rev.reverse.collect { |m| m.downcase }.join('.')
        [mod_spec, klass].reject { |p| p == "" }.join '.'
      end
      
      def spec_helper?
        File.exist?("#{destination_root}/#{spec_path}/spec_helper.js")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rsutphin-shenandoah-0.1.1 rails_generators/shen_spec/shen_spec_generator.rb
rsutphin-shenandoah-0.1.2 rails_generators/shen_spec/shen_spec_generator.rb
shenandoah-0.1.2 rails_generators/shen_spec/shen_spec_generator.rb