LoginSignup
6
6

More than 5 years have passed since last update.

RubyMotionのテストをGuardで自動化しつつ結果に色を付ける。

Posted at

インストール

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配下はcontrollersmodelslibディレクトリに分けてファイルを配置しているが、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

参考

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