インストール
Gemfile
に下記を追加してbundle install --path vendor/bundle
などして必要なgem
をインストール。
Gemfile
group :spec do
gem 'motion-redgreen'
gem 'guard-motion'
end
設定
続いてguard
の設定。
bundle exec guard init
をするなりしてGuardfile
を作成し、自身の環境に応じて監視するファイルを指定する。
ここではapp
配下はcontrollers
、models
、lib
ディレクトリに分けてファイルを配置しているが、spec
配下はフラットにファイルを配置しているのを想定。
Guardfile
guard 'motion' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/controllers/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
watch(%r{^app/models/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
watch(%r{^app/lib/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "./spec/#{m[1]}_spec.rb" }
end
更にRakefile
の修正。
テスト時のみ関連のgem
を読み込むようにする。
app.redgreen_style
はテスト結果の書式設定。
Rakefile
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'bundler'
is_test = ARGV.join(' ') =~ /spec/
if is_test
require 'guard/motion'
Bundler.require :default, :spec
else
Bundler.require
end
Motion::Project::App.setup do |app|
app.name = 'Hoge'
if is_test
app.redgreen_style = :full
end
end
実行
後は普通に実行するだけ。
bundle exec guard