LoginSignup
4
4

More than 5 years have passed since last update.

Ruby + RSpec + Guard + terminal-notifier-guard でテストを自動実行し、結果を通知

Last updated at Posted at 2016-11-10

Ruby + RSpec + Guard + terminal-notifier-guard でテストを自動実行し、結果を通知します

サンプル

テスト対象

sample_spec.rb
require 'spec_helper'

describe "hoge" do
  it "hige" do
    expect(true).to be true
  end
end

Gemfile

Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'

group :development, :test do
  gem 'rake'
  gem 'rspec'
  gem 'guard'
  gem 'terminal-notifier'
  gem 'terminal-notifier-guard'
  gem 'guard-rspec', require: false
  gem 'pry-byebug'
  gem 'rb-readline'
end
  • bundle install
$ bundle install

Guardfile

Guardfile
guard :rspec, cmd: 'bundle exec rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')
end

実行

ファイルの変更を検知して、Gaurdが実行されます

$ bundle exec guard
21:26:44 - INFO - Guard::RSpec is running
21:26:44 - INFO - Guard is now watching at 'path/to/project'
21:27:01 - INFO - Running: spec/sample_spec.rb
.

Finished in 0.002 seconds (files took 0.09395 seconds to load)
1 example, 0 failures
  • 通知が表示されます

success.png

  • テストケースが失敗するように変更します
require 'spec_helper'

describe "hoge" do
  it "hige" do
    expect(true).to be false
  end
end
  • ファイルの変更を検知して、Gaurdが実行されます
21:28:18 - INFO - Running: spec/sample_spec.rb
F

Failures:

  1) hoge hige
     Failure/Error: expect(true).to be false

       expected false
            got true
     # ./spec/sample_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01606 seconds (files took 0.10262 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/sample_spec.rb:4 # hoge hige

  • 通知が表示されます

fail.png

外部資料

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