Class: Kata::Setup::Ruby
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Kata::Setup::Base
Instance Method Details
#build_tree ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 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 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kata/setup/ruby.rb', line 6 def build_tree %W{#{repo_name}/lib #{repo_name}/spec/support/helpers #{repo_name}/spec/support/matchers}.each {|path| FileUtils.mkdir_p path} use_kata_name = kata_name.gsub(/( |-)\1?/, '_').downcase class_name = kata_name.split(/ |-|_/).map(&:capitalize).join # create the README file so github is happy File.open(File.join(repo_name, 'README'), 'w') {|f| f.write <<EOF} Leveling up my ruby awesomeness! EOF # create the base class file File.open(File.join(repo_name, 'lib', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF} class #{class_name} end EOF # create the .rspec file File.open(File.join(repo_name, '.rspec'), 'w') {|f| f.write <<EOF} --color --format d EOF # create the spec_helper.rb file File.open(File.join(repo_name, 'spec', 'spec_helper.rb'), 'w') {|f| f.write <<EOF} $: << '.' << File.join(File.dirname(__FILE__), '..', 'lib') require 'rspec' Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f} EOF # create a working spec file for the kata File.open(File.join(repo_name, 'spec', "#{use_kata_name}_spec.rb"), 'w') {|f| f.write <<EOF} require 'spec_helper' require '#{use_kata_name}' describe #{class_name} do describe "#initialize" do it "instantiates" do expect { #{class_name}.new }.to_not raise_exception end end end EOF # stub out a custom matchers file File.open(File.join(repo_name, 'spec', 'support', 'matchers', "#{use_kata_name}.rb"), 'w') {|f| f.write <<EOF} RSpec::Matchers.define :your_method do |expected| match do |your_match| #your_match.method_on_object_to_execute == expected end end EOF end |