neopoly/neo-rails

View on GitHub
lib/generators/mock/mock_generator.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'rails/generators'

class MockGenerator < Rails::Generators::NamedBase

  source_root File.expand_path('../templates', __FILE__)

  def create_mock_file
    path = "app/mocks/#{file_name}_mock.rb"
    if FileTest.exist? path
      raise FileExistError, "This filename ist used by another mock:#{path}"
    end

    copy_file "mock_template.rb", path
    gsub_file path, '-MockName-' , "#{class_name}"
  end

end

class FileExistError < StandardError; end