0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsチュートリアル第3章 ざっくり何やったか備忘録

0
Posted at

経緯

Railsチュートリアルを1日1章分以上終わらすことを目標にしている
今回は第3章でざっくり何やったかを自分用に残しておく

概要

ほぼ静的なページの作成を
新規プロジェクト「sample_app」を通して学習

Gemfile更新。--without productionオプションを使って、
production環境でしか使わないgemはインストールしない。
Git初期化。READMEを書き換えてコミット。
sample_appのリモートリポジトリ作成し、push。
第1章や第2章と同様に、hello, world」の手順に従って
コミット、プッシュ。 herokuもcreate -> push!

静的なページの生成

$ git checkout -b static-pages
$ rails generate controller StaticPages home help

home アクションと helpアクションを生成した。

config/routes.rb
Rails.application.routes.draw do
  get  'static_pages/home'
  get  'static_pages/help'
  root 'application#hello'
end

railsチュートリアル記載の短縮系一覧

完全なコマンド 短縮形
$ rails server $ rails s
$ rails console $ rails c
$ rails generate $ rails g
$ rails test $ rails t
$ bundle install $ bundle
$ bundle destroy $ rails d

テスト駆動開発のサイクル

  • 失敗するテストを最初に書く
  • 次にアプリケーションのコードを書いて成功させる(パスさせる)
  • 必要ならリファクタリングするのように進む。

多くのテストツールでは、テストの失敗をred、成功したときをgreenで表す。

test/controllers/static_pages_controller_test.rb
省略
  test "should get home" do
    get static_pages_home_url
    assert_response :success
  end
省略

get -> GETリクエストをhomeアクションへ送信
response:success -> リクエストに対するレスポンスは[成功]になるはず

RED

$ rails test
3 tests, 2 assertions, 0 f##ailures, 1 errors, 0 skips

GREEN

$ rails test
3 tests, 3 assertions, 0 failures, 0 errors, 0 skips
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?