LoginSignup
13
13

More than 5 years have passed since last update.

超適当 Rails3 TDD BDD CI 環境づくり

Last updated at Posted at 2012-04-08

以下のものを入れます

  • ruby, rails, cucumber, rspec, spork, factorygirl, simplecov

Guard を忘れた・・・

ruby インストール

  • Rails を使うときは ruby 1.9.2 を使う

command:

$ sudo apt-get install git-core build-essential zlib1g-dev sqlite3 libsqlite3-dev libtool libssl-dev nodejs
$ rvm install 1.9.2
  • Gemsetを作成

    $ rvm --create 1.9.2@myproj
    $ rvm use 1.9.2@myproj

Rails

$ cat > $HOME/.gemrc <<EOF
gem: --no-ri --no-rdoc
EOF
$ gem install rails
$ rails new BrilliantApp

Gemfile

group :test, :development do
  gem 'rspec-rails'
end

group :test do
  gem 'simplecov-rcov', :require => false
  gem 'ci_reporter'
  gem 'autotest'
  gem 'autotest-rails'
  gem 'test_notifier'
  gem 'spork'
  gem "factory_girl_rails", "~> 1.2", :require => false

  # cucumber
  gem 'capybara'
  gem 'database_cleaner'
  gem 'cucumber-rails'
  gem 'cucumber'
  gem 'launchy' # So you can do Then show me the page
  gem 'ramaze'
  gem 'webrat'
end

インストール実行

$ bundle

setup

$ rails g rspec:install
$ rails g cucumber:install ja --rspec --capybara --spork
$ spork --bootstrap

spec/spec_helper.rb:

の先頭

# 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'
require "test_notifier/runner/rspec"
require 'spork'
require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter

真ん中あたり

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

  # reload always for model change
  silence_warnings do
    load Rails.root.join('config/routes.rb')
    Dir[Rails.root.join('app/**/*.rb')].each do |file|
      load file
    end
    require 'factory_girl_rails'
  end

end

config/environments/test.rb:

config.cache_classes = true

.rspec:

--colour --drb

features/support/env.rb の最後のほう:

  # Possible values are :truncation and :transaction
  # The :transaction strategy is faster, but might give you threading problems.
  # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
  Cucumber::Rails::Database.javascript_strategy = :truncation

  silence_warnings do
    Dir[Rails.root.join('app/**/*.rb')].each do |file|
      load file
    end
    require 'factory_girl_rails'
    require 'factory_girl/step_definitions'
  end

end

cucumber.yml (ROOTではなく、configの下に書いたほうが良いかも?):

autotest: --drb --color --format progress --strict
autotest-all: --drb --color --format progress --strict

autotest 実行方法

$ spork &
$ spork c &
$ autotest

環境によっては bundle exec 必要

13
13
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
13
13