Sha256: 408930b8474c8fe5c0172d40e8475f812708cb902292626dca66ad8cb13d1ac1
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 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 "spec_helper"), %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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec-scaffold-0.2.0 | lib/rspec/scaffold/generator.rb |
rspec-scaffold-0.1.0 | lib/rspec/scaffold/generator.rb |