`
wudixiaotie
  • 浏览: 136899 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Rails Project Init

阅读更多

 1.rspec

$ rails generate rspec:install

 2.guard

$ bundle exec guard init rspec

 3.加入默认 Guardfile 的代码,注意顶部的 require

require 'active_support/inflector'

guard 'rspec', all_after_pass: false do
  .
  .
  .
  watch('config/routes.rb')
  # Custom Rails Tutorial specs
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                      "spec/requests/#{m[1].singularize}_pages_spec.rb")
  end
  watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|
    "spec/requests/authentication_pages_spec.rb"
  end
  .
  .
  .
end

 4.spork

$ bundle exec spork --bootstrap

 5.将环境加载代码加入 Spork.prefork 代码块:spec/spec_helper.rb 

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  # Checks for pending migrations before tests are run.
  # If you are not using ActiveRecord, you can remove this line.
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

  RSpec.configure do |config|
    # ## Mock Framework
    #
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
    #
    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false

    # Run specs in random order to surface order dependencies. If you find an
    # order dependency and want to debug it, you can fix the order by providing
    # the seed, which is printed after each run.
    #     --seed 1234
    config.order = "random"
    config.include Capybara::DSL
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end
 6.Guard 和 Spork 协作

 

$ bundle exec guard init spork
 7.为使用 Spork 而修改的 Guardfile 
require 'active_support/inflector'

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' },
               :rspec_env    => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch('config/environments/test.rb')
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb') { :rspec }
  watch('test/test_helper.rb') { :test_unit }
  watch(%r{features/support/}) { :cucumber }
end

guard 'rspec', all_after_pass: false, cli: '--drb' do
  .
  .
  .
end
 8.修改完之后,我们就可以通过 guard 命令同时启动 Guard 和 Spork 了:
最新的配置方法参见 http://railstutorial-china.org/chapter3.html#fnref-3-6
分享到:
评论

相关推荐

    ruby on rails开发

    使用`rails new project_name`命令创建一个新的Rails项目。此命令会生成一系列文件和目录,构成一个基本的Rails应用结构。 5. **理解Rails目录结构** Rails的目录结构包括`app`、`bin`、`config`、`db`、`lib`、`...

    career-paths

    使用带初始化一个新项目克隆存储库git clone git@github.com:dmbf29/middleman-boilerplate.git NAME_OF_YOUR_PROJECT 移至目录cd NAME_OF_YOUR_PROJECT 删除模板git rm -rf .git 启动一个新的git repo git init 在...

    webdevelopment-portfolio:布兰登·林德伯格(Brandon Lindberg)的网络开发产品组合

    使用带初始化一个新项目克隆存储库git clone git@github.com:dmbf29/middleman-boilerplate.git NAME_OF_YOUR_PROJECT 移至目录cd NAME_OF_YOUR_PROJECT 删除模板git rm -rf .git 启动一个新的git repo git init 在...

    rubyinstaller+配置方法

    然后,你可以通过`gem install <gem_name>`命令安装你需要的Ruby库或框架,例如安装Rails,只需输入`gem install rails`。 现在,我们转向集成开发环境(IDE)的配置。Eclipse是一款强大的跨平台IDE,对于Ruby开发...

    gitlab安装1

    下载Ruby源代码,编译并安装,同时设置Ruby Gem源为淘宝镜像,安装Rails和Bundler: ``` mkdir /tmp/ruby && cd /tmp/ruby curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar xz cd ...

    ruby开发的基本流程.doc

    - **创建新项目**:通过`rails new [project_name]`命令可以快速创建一个新的Rails项目。 - **初始化Git仓库**:为了更好地进行版本控制和团队协作,建议在项目创建之初就初始化一个Git仓库。可以通过`git init`命令...

    rpush:Ruby的推送通知服务

    Rpush。 Ruby的推送通知服务。 Rpush旨在成为在Ruby中发送推送通知的事实宝库。 它的核心目标是易于使用,可靠性和... $ cd /path/to/project$ bundle$ bundle exec rpush init创建一个应用和通知苹果推送通知服务可

    Python Web框架Pylons中使用MongoDB的例子

    Pylons 经过漫长的开发,终于放出了 1.0 版本。对于正规的产品开发来说,1.0 版本的意义很大,这表明 Pylons 的 API 终于稳定下来了。 Pylons 虽是山寨 Rails 而生,但作为一个纯 ...在 PROJECT/model/__init__.py 中

    redmine安装脚本 2.6.10版本

    /etc/init.d/mysqld start ``` 2. **创建数据库及用户**: - 创建数据库 redmine,并设置字符集为 utf8。 ```bash mysql -u root -p -e 'DROP DATABASE redmine;' mysql -u root -p -e 'CREATE DATABASE ...

    Pycharm 简单使用教程.docx

    - **创建 Python 包**:创建新文件或目录时,务必选择“Python Package”选项,这样 PyCharm 将会自动创建一个 `__init__.py` 文件,这是 Python 包的重要组成部分。 - **创建不同类型的文件**:根据项目需求,...

    Github与Git简明教程1

    你可以通过`git init`命令在本地创建一个新的Git仓库,或者使用`git clone`命令从远程服务器(如GitHub)克隆一个现有的仓库。 2. **分支(Branch)**:分支代表项目的不同开发线路。默认分支通常名为“master”,...

    middleman_starter_kit:Middleman前端入门套件

    middleman init your_project_name --template=middleman-starter-kit 安装宝石bundle install 安装NPM模块npm install 运行middleman server 为了使yarn run build最小化yarn run build 更多信息在 包括什么 ...

    生成:用于搭建GitHub项目的新命令行工具和开发人员框架。 生成提供Yeoman的鲁棒性和可配置性,Slush的表达性和简单性,以及比任何一种更强大的流控制和可组合性

    用于构建新GitHub项目的命令行工具和开发人员框架。 生成提供Yeoman的鲁棒性和可配置性,Slush的表达性和简单性,以及比这两者更强大的流控制和可组合性。 生成 您可能也对感兴趣。 目录 (使用生成的TOC) ...

Global site tag (gtag.js) - Google Analytics