Sha256: 72409e004107e5bae33d21945c2b96f628717bd23b55140c067f8cca1824c0d7
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
module RSpec module Scaffold class Generator < DelegateClass(Ryan) # = Class # generate a rspec file based on existing code attr_reader :file def initialize(file) @file = file super Ryan.new(file) end def const @const ||= Kernel.const_get(name) end def perform indent = (' ' * 2) second_indent = indent * 2 lines = [%Q(require "#{helper_file}"), %Q(), %Q(describe #{const} do)] if class? initialization_args.each do |arg| lines << %Q(#{indent}let(:#{arg.to_s.sub(/^[&*]/, '')}) {}) end lines << %Q() lines << %Q(#{indent}subject { described_class.new #{initialization_args.join(', ')} }) elsif module? lines << %Q(#{indent}subject { Class.new { include #{const} }.new }) end lines << %Q() funcs.reject(&:private?).each do |func| lines << %Q(#{indent}describe "#{func.class? ? '.' : '#'}#{func.name}" do) func.assignments.each do |assignment| lines << %Q(#{second_indent}it "#{assignment}" do) << %Q(#{second_indent}end) end lines << %Q() if func.conditions.any? and func.assignments.any? func.conditions.each do |condition| lines.concat ConditionExhibit.new(condition, second_indent).render end lines << %Q(#{indent}end) << %Q() end lines << %Q(end) << %Q() lines end def helper_file if defined?(::Rails) 'rails_helper' else 'spec_helper' end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-scaffold-0.3.0 | lib/rspec/scaffold/generator.rb |
rspec-scaffold-0.2.1 | lib/rspec/scaffold/generator.rb |