Slide 1

Slide 1 text

Ruby tools for Infrastructure Engineer

Slide 2

Slide 2 text

RSpec

Slide 3

Slide 3 text

RSpec 4 RSpec is testing tool for the Ruby programming language. 4 Ruby ͷςεςΟϯάϑϨʔϜϫʔΫɻ 4 Serverspec ΍ Infrataster ౳ͷ࠷ۙ࿩୊ͷ Infrastructure testing framework Ͱ΋࢖ΘΕ͍ͯΔɻ ࠷ۙ 3.0rc1 ͕ग़ͨɻ

Slide 4

Slide 4 text

Serverspec

Slide 5

Slide 5 text

Serverspec Infrastructure testing framework cat spec/target.example.jp/http_spec.rb require 'spec_helper' describe package('httpd') do it { should be_installed } end 4 rspec 4 describe, it, its ... ͰςετΛॻ͍͍ͯ͘ 4 http://serverspec.org/resource_types.html

Slide 6

Slide 6 text

Serverspec Run test $ rake spec /usr/bin/ruby -S rspec spec/www.example.jp/httpd_spec.rb ...... : 4 rake?

Slide 7

Slide 7 text

Rake 4 Ruby ੡Ϗϧυπʔϧ 4 Make ͱΑ͘ࣅͨػೳ͕͔ͭ͑Δ 4 "λεΫ" ͱ͍͏جຊ୯ҐͰԿ͔Λ࣮ߦ͢Δ

Slide 8

Slide 8 text

Rakefile require 'rake' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/*/*_spec.rb' end task :default => :spec 4 spec ͱ͍͏໊લͷλεΫ͕ఆٛ͞Ε͍ͯΔ 4 λεΫҰཡ͸ rake -T ͰݟΕΔ

Slide 9

Slide 9 text

spec_helper.rb 4 ςετͰ࢖͏ڞ௨ͷઃఆΛॻ͘ 4 serverspec Ͱ͸ɺserverspec Ͱ࢖͏ sudo password ΍ ssh ઌ host ͷఆٛ౳͕ॻ͔Ε͍ͯΔ 4 host = File.basename(Pathname.new(file).dirname) 4 σϑΥϧτͩͱσΟϨΫτϦͷ໊લ͕ϗετ໊ʹͳΔ 8 -rw-r--r-- 1 staff 848 6 12 18:32 spec_helper.rb 0 drwxr-xr-x 3 staff 102 6 12 18:32 target.example.com ← ͜Ε

Slide 10

Slide 10 text

Tips

Slide 11

Slide 11 text

Tips Rake ӽ͠ʹ Rspec ΁ͷҾ਺Λ౉͢ rake spec SPEC_OPTS="--format documentation" ৗʹಉ͡Φϓγϣϯ͕࢖͍͍ͨ echo "--color" >> .rspec # ৭͕ͭ͘ 4 ੲ͸ spec.opts ͩͬͨ

Slide 12

Slide 12 text

ग़ྗϑΥʔϚοτ 4 --format 4 documentation 4 progress 4 html

Slide 13

Slide 13 text

ςετͷϑΟϧλϦϯά 4 ৭ʑͳঢ়ଶʹΑ͍ͬͯͨ͠/ͨ͘͠ͳ͍ςετ͕͋Δ 4 --tag ΦϓγϣϯΛ࢖͏ 4 --tag 4 ͷ͍͍ͭͯΔςετͷΈ࣮ߦ͢Δ 4 --tag ~ 4 ͷ͍͍ͭͯΔςετΛআ֎͢Δ 4 ଞʹ΋৭ʑग़དྷΔ

Slide 14

Slide 14 text

Usage rake spec SPEC_OPTS="--format documentation --tag ~web" 4 ͜Μͳײ͡Ͱ࢖͏ ࣮ࡍʹҊ݅Ͱ࢖͍ͬͯΔ༷ࢠΛ͝঺հ

Slide 15

Slide 15 text

Enjoy test! and reduce mistakes!