Ruby on Rails命令

页码为《Ruby on Rails Tutorial 2nd Edition》


创建controller:P86

rails generate controller StaticPages home help --no-test-framework

之后,创建integration_test

rails generate integration_test XXX


创建model:

rails generate model name:string email:string


将更改反映到数据库:

bundle exec rake db:migrate


准备test数据库:

bundle exec rake db:test:prepare(若test database奇怪地出错,建议使用该命令)


运行rspec测试:

bundle exec rspec ____(文件位置,也可为文件夹)


运行annotation(为model自动创建数据库表结构注释) P229

bundle exec annotate --position before


运行自动测试框架guard:

1. 将guard加入gemfile

2. bundle install

3. bundle exec guard init rspec使其与rspec集成

4. 更改guardfile,guard 'rspec', :version => 2, :all after pass => false, :cli => '--drb' do

5. 运行guard: bundle exec guard


使用spork加速rspec(因为rspec每次运行都会调入自身环境,浪费时间)

1. 加入gemfile: gem 'guard-spork', '0.3.2'       gem 'spork', '0.9.0'

2. bundle install

3. bundle exec spork --bootstrap

4. 更改spec_helper.rb:

Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
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}
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
config.mock with :rspec
# 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
end
end

5. bundle exec spork

6. 更改.spec文件,添加--drb行(distributed ruby)

7. 与guard集成: bundle exec guard init spork


进行数据库更改:

rails generate migration add_index_to_users_email 并自己编辑相关更改

bundle exec rake db:migrate 应用更改

bundle exec rake db:test:prepare 准备测试数据库

bundle exec rake db:migrate RAILS_ENV=production  创建production数据库

bundle exec rake db:reset 重置所有数据库

bundle exec rake db:rollback 撤销更改



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值