quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

RubyTapas #120 - #124

120 Outside-In

★★

configファイルとかのテスト

stdinを介したテストとか

output, status = Open3.capture2()
output, status = Open3.capture2e(env, %W[hostconfig -c], stdin_data: example_input)

config file

hosts = hosts_from_input($stdin.read)

Writing test first

121 Testing Blocks

yielded = false
get_temp("00000") do
  yielded = true
end
expect(yielded).to be_true

ブロック内の処理をもっと詳しくテスト

yielded_value = :has_not_yielded
get_temp("00000") do |error|
  yielded_value = error
end
expect(yielded_value).to be_a(Exception)
# >>        expected :has_not_yielded to be a kind of Exception

複数回実行するブロックのテスト

yielded_values = []
h.each do |key, value|
  yielded_values << [key, value]
end
expect(yielded_values).to include([:x, 23])

122 Testing Blocks With Rspec

★★

yield_control

expect{|probe| find_email_addresses(input, &probe)}.to yield_control

yield matchers - Built in matchers - RSpec Expectations - RSpec - Relish

yield_control, yield_with_args, yield_with_no_args, yield_successive_args

Yield matchers知らなかった

123 Removing Debug Output

module Kernel
  alias_method :orig_puts, :puts
  def puts(*args)
    if caller[0].include?('mildly-functional-gol.rb')
      raise Exception, 'debug output!'
    else
      orig_puts(*args)
    end
  end
end

# ~> -:18:in `puts': debug output! (Exception)

124 Elixir

longtime Rubyist and Rails core team member Jose valim

Conway's Game of Life ライフゲーム - Wikipedia

'o'-s represent live cells and the dots represent dead cells

def next_state("o", live_count) when live_count in 2..3, do: "o"