autocoder.vim


Ⅰ. 插件描述

Ⅱ. 基本信息

创建日期:  2013-07-08
使用用户:  4
Github星:  6
插件作者:  Alex Oliveira

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'kurko/autocoder-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'kurko/autocoder-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'kurko/autocoder-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/kurko/autocoder.vim

Ⅳ. 文档说明

# autocoder.vim

Creating appropriate classes and unit tests in a Rails project improves your

  1. However, their creation process tends to be painful in whatever editor
  2. use.

So I wrote this plugin.

Feature: auto-creating class and unit specs

Type :AC. Vim will ask you what's the path of the class you want to create:

Type the path (e.g store/cart/item):

If you type store/special_cart, it will generate the following two files:

  • lib/store/special_cart.rb
module Store
  class SpecialCart
    def initialize(options)
      @options = options
    end

    private

    attr_reader :options
  end
end
  • spec/lib/store/special_cart_spec.rb
require "store/special_cart"

describe Store::SpecialCart do
  describe "#some_method" do
    it "returns true" do

    end
  end
end

Feature: auto-creating contract classes

Creating contract tests is tedious. Given you have a class like this one:

# lib/user.rb
class User
  def name
    # ...
  end
end

Type :AContract. This will create the following file:

# spec/contracts/lib/user_contract.rb
shared_examples_for "a user" do
  subject { User.new }

  it "responds to name" do
    subject.should respond_to(:name)
  end
end

Explaining the idea behind contract tests is beyond the scope of this readme.

Known issues

  • it only works for files in the lib dir
  • it only works with RSpec
  • if the file already exists, it'll add the boilerplate code anyway

Please, send patches to fix these problems.

License

MIT. Do what you want with it, but please consider contributing back :)

添加新评论