Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RubyHiroba 2014
Search
yui-knk
September 21, 2014
Programming
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RubyHiroba 2014
Power Assert with Pry
yui-knk
September 21, 2014
More Decks by yui-knk
See All by yui-knk
Modding RubyKaigi for Myself
yui_knk
0
1.1k
Kingdom of the Machine
yui_knk
2
2.4k
Ruby Parser progress report 2025
yui_knk
1
960
Understanding Ruby Grammar Through Conflicts
yui_knk
1
890
Ruby's Line Breaks
yui_knk
4
6.2k
What is Parser
yui_knk
11
5.6k
Ruby Parser progress report 2024
yui_knk
2
540
最高の構文木の設計 2024年版
yui_knk
9
6.9k
Converting AST
yui_knk
4
460
Other Decks in Programming
See All in Programming
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
240
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
220
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
630
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
330
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
210
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
260
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
250
Hono + Inertia + React で LP を構築した話
oukayuka
2
170
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
370
Go 1.27 における memory allocation の高速化
andpad
0
330
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
400
Dockerfile CMD for Node.js
grazie1999
0
120
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
670
Design in an AI World
tapps
1
290
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
220
A Tale of Four Properties
chriscoyier
163
24k
Odyssey Design
rkendrick25
PRO
2
780
First, design no harm
axbom
PRO
2
1.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
The Curious Case for Waylosing
cassininazir
1
480
Exploring anti-patterns in Rails
aemeredith
3
470
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
180
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Transcript
Yuichiro Kaneko SKIYAKI Inc. Power Assert × Pry
I am … • @yui-knk (github) / @spikeolaf (twitter) •
pry commit (ghosting / ͓͞΅Γ) • Interested in “Binding” (Don’t throw “Masakari”)
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: % * + -@ < ...
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
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] | | | #<Enumerator: 3:times> | | 3 | false String test_failed(MyTest)
For more detail of Power Assert • https://speakerdeck.com/k_tsj/power-assert-in-ruby
I think • Power Assert is Cool !! • Power
Assert is Magical !! • Want to Power Assert Easily !! (not only Failure case in test)
So I made pry plug-in!
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] | | | #<Enumerator: 3:times> | | 3 | false String [2] pry(main)>
Edge case 1 ( [], {}, ->) • (Maybe) these
are not treated as method calls (TracePoint) [1] pry(main)> prc = -> x { -> y {x * y}} => #<Proc:0x007fd1360c9130@(pry):59 (lambda)> [2] pry(main)> pa prc[10][2] prc[10][2] | | | | | 20 | #<Proc:0x007fd13609a9c0@(pry):59 (lambda)> #<Proc:0x007fd1360c9130@(pry):59 (lambda)> ! [3] pry(main)> pa -> x { -> y {x * y}}[10][2] -> x { -> y {x * y}}[10][2]
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
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} => #<Proc:0x007fd136068b00@(pry):79> ! > %Q["0".class == "3".to_i.times.map {|i| i + 1 }.class] => "\"0\".class == \"3\".to_i.times.map {|i| i + 1 }.class"
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
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