Class: SpecGeneratorOld

Inherits:
Object
  • Object
show all
Defined in:
lib/tools/spec_generator_old.rb

Overview

spec_helper = File.join(rootpath,‘spec’,‘spec_helper’)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ SpecGeneratorOld

Returns a new instance of SpecGeneratorOld.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tools/spec_generator_old.rb', line 13

def initialize(c)
  @c=c
  #require camel_to_snake_case(c.name)
  i_members = c.instance_methods(include_super=false)
  i_setters = i_members.grep /[^=][=]$/
  i_getters = i_setters.collect { |s| s.gsub(/[=]$/,'') }
  @members = Hash.new
  @members['Instance Variables'] = (i_getters).sort
  @members['Instance Methods'] = (i_members - i_setters - i_getters).sort
  @members['Class Methods'] = c.methods(include_super=false).sort
end

Instance Attribute Details

#cObject

Returns the value of attribute c.



10
11
12
# File 'lib/tools/spec_generator_old.rb', line 10

def c
  @c
end

#membersObject

Returns the value of attribute members.



11
12
13
# File 'lib/tools/spec_generator_old.rb', line 11

def members
  @members
end

Instance Method Details

#camel_to_snake_case(camel) ⇒ Object



45
46
47
# File 'lib/tools/spec_generator_old.rb', line 45

def camel_to_snake_case(camel)
  camel.gsub(/(.)([A-Z])/,'\1_\2').downcase
end

#generateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tools/spec_generator_old.rb', line 25

def generate
  puts "require 'spec_helper'"
  puts ""
  puts "describe '#{@c.name}' do"
  puts ""
  ['Instance Variables','Instance Methods','Class Methods'].each do |type |
    puts "  context '#{type}' do"
    puts ""
    @members[type].each do |member|
      puts "    describe '##{member}' do"
      puts "      pending"
      puts "    end"
      puts ""
    end
    puts "  end"
    puts ""
  end
  puts "end"
end