Class: RSpec::Scaffold::Generator
- Inherits:
-
Ryan
- Object
- Ryan
- RSpec::Scaffold::Generator
- Defined in:
- lib/rspec/scaffold/generator.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Class generate a rspec file based on existing code.
Instance Method Summary collapse
- #const ⇒ Object
-
#initialize(file) ⇒ Generator
constructor
A new instance of Generator.
- #perform ⇒ Object
Constructor Details
#initialize(file) ⇒ Generator
Returns a new instance of Generator.
10 11 12 13 |
# File 'lib/rspec/scaffold/generator.rb', line 10 def initialize(file) @file = file super Ryan.new(file) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Class
generate a rspec file based on existing code
8 9 10 |
# File 'lib/rspec/scaffold/generator.rb', line 8 def file @file end |
Instance Method Details
#const ⇒ Object
15 16 17 |
# File 'lib/rspec/scaffold/generator.rb', line 15 def const @const ||= Kernel.const_get(name) end |
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rspec/scaffold/generator.rb', line 19 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 |