Sha256: 49b38c9a6f54bec3cc1fe1ee6d5fef4aefe279ad3669ca9104c8186534b5e714
Contents?: true
Size: 1.57 KB
Versions: 3
Compression:
Stored size: 1.57 KB
Contents
class JavascriptSpecGenerator < RubiGen::Base attr_reader :file_path, :class_name, :actions def initialize(runtime_args, runtime_options = {}) super @file_path = args.shift @actions = args end def manifest file_path_with_spec, file_path_without_spec = file_path_with_and_without_spec @class_name = File.basename(file_path_without_spec).split("_").map {|c| c.capitalize }.join("") record do |m| m.directory "#{base_dir}/#{dir_path}" m.directory "#{base_dir}/fixtures/#{dir_path}" options = {:class_name_without_spec => class_name_without_spec, :file_path_without_spec => file_path_without_spec} m.template 'javascript_spec.js.erb', "#{base_dir}/#{file_path_with_spec}.js", :assigns => options if rspec? && !actions.blank? # actions - list of templates to render m.template 'fixture_render_spec.rb.erb', "#{base_dir}/#{file_path_with_spec}.rb", :assigns => options else m.template 'fixture.html.erb', "#{base_dir}/fixtures/#{file_path_without_spec}.html", :assigns => options end end end def rspec? File.exist?("spec") end def base_dir @base_dir ||= File.exist?("spec") ? "spec/javascripts" : "test/javascript" end def dir_path File.dirname(file_path) end def file_path_with_and_without_spec if (file_path =~ /_spec$/i) [file_path, file_path.gsub(/_spec$/, "")] else [file_path + "_spec", file_path] end end def class_name_without_spec (class_name =~ /Spec$/) ? class_name.gsub(/Spec$/, "") : class_name end end
Version data entries
3 entries across 3 versions & 1 rubygems