Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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.7k
Ruby Parser progress report 2025
yui_knk
1
970
Understanding Ruby Grammar Through Conflicts
yui_knk
1
900
Ruby's Line Breaks
yui_knk
4
6.2k
What is Parser
yui_knk
11
5.7k
Ruby Parser progress report 2024
yui_knk
2
550
最高の構文木の設計 2024年版
yui_knk
9
6.9k
Converting AST
yui_knk
4
470
Other Decks in Programming
See All in Programming
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
130
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
wkhtmltopdfの次どうするか問題2026
willnet
2
1.2k
AIエージェント時代のコードレビューを設計する
nogu66
6
2.7k
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
240
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
0
260
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
410
アクセシビリティから考える情報設計
high_g_engineer
0
380
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
Intent as Code
shoppingjaws
6
1k
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
500
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
350
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Writing Fast Ruby
sferik
630
63k
Building the Perfect Custom Keyboard
takai
2
870
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
The Language of Interfaces
destraynor
162
27k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
The Limits of Empathy - UXLibs8
cassininazir
1
670
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
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