Slide 1

Slide 1 text

Yuichiro Kaneko SKIYAKI Inc. Power Assert × Pry

Slide 2

Slide 2 text

I am … • @yui-knk (github) / @spikeolaf (twitter) • pry commit (ghosting / ͓͞΅Γ) • Interested in “Binding” (Don’t throw “Masakari”)

Slide 3

Slide 3 text

Pry ?? • An IRB alternative and runtime developer console $ pry ! [1] pry(main)> "ruby".capitalize => "Ruby" [2] pry(main)> ls 10 Comparable#methods: between? Numeric#methods: +@ coerce i phase quo rectangular to_c ... Integer#methods: ceil denominator floor vcdlcm ... Fixnum#methods: % * + -@ < ...

Slide 4

Slide 4 text

Power Assert ?? • Power Assert shows each value of variables and method calls in the expression. It is useful for testing, providing which value wasn't correct when the condition is not satisfied. (test-unit) ! assert do "0".class == "3".to_i.times.map {|i| i + 1 }.class end

Slide 5

Slide 5 text

assert do "0".class == "3".to_i.times.map {|i| i + 1 }.class end ! ! Failure: ! "0".class == "3".to_i.times.map {|i| i + 1 }.class | | | | | | | | | | | Array | | | | [1, 2, 3] | | | # | | 3 | false String test_failed(MyTest)

Slide 6

Slide 6 text

For more detail of Power Assert • https://speakerdeck.com/k_tsj/power-assert-in-ruby

Slide 7

Slide 7 text

I think • Power Assert is Cool !! • Power Assert is Magical !! • Want to Power Assert Easily !! (not only Failure case in test)

Slide 8

Slide 8 text

So I made pry plug-in!

Slide 9

Slide 9 text

How to install and use it • Type “pa RUBY_CODE” in pry $ gem install pry-power_assert $ pry ! [1] pry(main)> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class "0".class == "3".to_i.times.map {|i| i + 1 }.class | | | | | | | | | | | Array | | | | [1, 2, 3] | | | # | | 3 | false String [2] pry(main)>

Slide 10

Slide 10 text

Edge case 1 ( [], {}, ->) • (Maybe) these are not treated as method calls (TracePoint) [1] pry(main)> prc = -> x { -> y {x * y}} => # [2] pry(main)> pa prc[10][2] prc[10][2] | | | | | 20 | # # ! [3] pry(main)> pa -> x { -> y {x * y}}[10][2] -> x { -> y {x * y}}[10][2]

Slide 11

Slide 11 text

Edge case 2 ( A ? B : C / if ) • Why? [1] pry(main)> pry(main)> a = 10 => 10 [2] pry(main)> pa (a.to_s == 12) ? 1 : 0 (a.to_s == 12) ? 1 : 0 ! [3] pry(main)> pa 10 if a.to_s == 12 10 if a.to_s == 12

Slide 12

Slide 12 text

OFF TOPIC (What P.A. needs) • Proc (yield, variables(proc.binding)) • String (Ripper.sexp(@line) for idents) > Proc.new {"0".class == "3".to_i.times.map {|i| i + 1 }.class} => # ! > %Q["0".class == "3".to_i.times.map {|i| i + 1 }.class] => "\"0\".class == \"3\".to_i.times.map {|i| i + 1 }.class"

Slide 13

Slide 13 text

OFF TOPIC (What P.A. needs) 1SPD 4USJOH UFTUVOJU BSH PQFO QBUI NJOJUFTU BSH PQFO QBUI QSZQ@B FWBM1SPDOFX \\TUS^^ BSH STQFD PQFO QBUI • RSpec is not supported

Slide 14

Slide 14 text

OFF TOPIC (What P.A. needs) • How to get Proc in RSpec ? (rspec) ! describe “class of string should be String” do “0”.class.should == String end