RailsでWebさーびす作ってみる-初日-
明日からダイエッツするぞー!
・・・目標決めても3日で飽きちゃう。
なので日記にして強制してみようそもって。
新人プログラマのWebさーびすプロジェクツの発足です。
ぱちぱちぱちー。
なに作る?
んー昨今の朝マック事情では元気なじーちゃん率が高いそもって。
若者の年金負担率の軽減のため、元気じーちゃん就活サイトにしよー。
さーびすの環境作る
なにはともあれプロジェクト作る。
rspec と jquery 使うから test と prototype.js とかいらない。
プロジェクト名はあるかぱ(意味なし!)に。
$ rails new alcapa -T -J
Gemfile にそれっぽい Gem を詰めこみ。
TDDちっくにしてみる。
gem 'rails', :git => 'git://github.com/rails/rails.git' gem "rack", :git => 'git://github.com/rack/rack.git' gem 'mysql' gem 'jquery-rails' group :development, :test do gem "rspec-rails", ">= 2.5.0" gem 'spork', '~> 0.9.0.rc' gem "cucumber", :git => "git://github.com/aslakhellesoy/cucumber.git" gem "cucumber-rails", :git => "git://github.com/aslakhellesoy/cucumber-rails.git" gem "capybara" gem "capybara-envjs" gem "database_cleaner", :git => 'git://github.com/bmabey/database_cleaner.git' gem 'ruby-debug19' end
まとめてインスト。
$ bundle install
えらー出ちゃった。
extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/home/homepage/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby extconf.rb
checking for libxml/parser.h... no
- -
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
- -
Nokogiri で使ってる libxml2 ないと怒られたのでインスト。
$ sudo yum install -y libxml2 libxml2-devel libxslt libxslt-devel
再チャレンジ!
$ bundle install
今度は capybara で使ってる johnson がエラー。
js_land_proxy.h:11:18: fatal error: node.h: No such file or directory
johnson は ruby1.9 に対応してないのかな?
capybara はやめて webrat にする
gem 'rails', :git => 'git://github.com/rails/rails.git' gem "rack", :git => 'git://github.com/rack/rack.git' gem 'mysql' gem 'jquery-rails' group :development, :test do gem "rspec-rails", ">= 2.5.0" gem 'spork', '~> 0.9.0.rc' gem "cucumber", :git => "git://github.com/aslakhellesoy/cucumber.git" gem "cucumber-rails", :git => "git://github.com/aslakhellesoy/cucumber-rails.git" gem "webrat" gem "mechanize" # gem "capybara" # gem "capybara-envjs" # gem "database_cleaner", :git => 'git://github.com/bmabey/database_cleaner.git' gem 'ruby-debug19' end
気を取り直して!
$ bundle install
ruby-debug でエラー。
Installing linecache19 (0.5.12) /home/homepage/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/rubygems/installer.rb:164:in `install': linecache19 requires Ruby version >= 1.9.2. (Gem::InstallError)
どーやら ruby1.9 だとまだよろしくないようで。
個別に入れてみる。
gem install ruby-debug19 -- --with-ruby-include=/home/homepage/.rvm/src/ruby-1.9.2-rc2/
gem install ruby-debug-ide19 -- --with-ruby-include=/home/homepage/.rvm/src/ruby-1.9.2-rc2/
今度こそー!
$ bundle install
おーけー。
お次は rspec の設定。
.rspec ファイルができるので表示フォーマットとかの設定。
spork を使うので --drb もいれとく。
--colour
--format progress
--drb
-fs
spork の設定。
spork ないと rspec のテストがもっさり。
$ spork --bootstrap
spec/spec_helper.rb を spork 用に修正。
require 'rubygems' require 'spork' 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. ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' # 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 end end Spork.each_run do # This code will be run each time you run your specs. end
cucumber の設定。
オプションもそれっぽく。
ラストにDBの設定。
$ vi config/database.yml
DB は mysql 使うつもり。
コンソールからそれぞれのDB作成
mysql> create database alcapa default character set utf8;
準備ばっちし!
サーバ起動してみる。
$ rails server -u
動いてるぽいねー。
記念に git 使う。
$ git init
$ git add .
$ git commit -m "init"
開発環境できましたー!