rails建立項目,部署,測試流程(rails5.0+ruby2.3.1)

rails new test_app --skip-test-unit 不生成默認的test,稍後用rspec
cd test_app

修改Gemfile(大部分爲自動生成)jquery

source 'https://ruby.taobao.org' -- 使用淘寶鏡像,由於鏈接不了rubygem

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1' --rails版本
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
gem "slim-rails" --可以讓erb轉slim
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'rspec-rails', '3.5.1' -- 此處添加最新rspec
  # Use sqlite3 as the database for Active Record  gem 'sqlite3'
end

group :test do -- 添加capybara及其依賴gem,可以編寫類英語交互語句
    gem 'selenium-webdriver', '~> 2.53', '>= 2.53.4'
    gem 'capybara', '2.8.0'
end

group :production do
    gem 'pg', '~> 0.18.4'
end

group :development do --heroku部署用
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

bundle installgit

bundle install --without production
bundle update
bundle install

生成rspec測試模塊github

rails generate rspec:install

push至git上web

git init
git add .
git commit -m "Initial commit"
git remote add origin url
git push -u origin master

設置rails,讓其服務於靜態資源文件redis

config/environments/production.rb spring

TestApp::Application.configure do
  .
  .
  .
  config.serve_static_assets = true
  .
  .
  .
end

 spec測試文件:sql

require 'rails_helper'

RSpec.describe "StaticPages", :type => :feature do
  describe "Home page" do
    it "should have the content 'Help'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end

  describe "Help page" do
    it "should have the content 'Help'" do
      visit '/static_pages/help'
      expect(page).to have_content('Help')
    end
 end
end

 測試語句api

bundle exec rspec spec/requests/static_pages_spec.rb

 啓動railssass

rails s
相關文章
相關標籤/搜索