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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.5k
Ruby Parser progress report 2025
yui_knk
1
970
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.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
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
Deep dive into the select statement (GopherCon UK)
jespino
0
170
バグを直したら useEffect が消えた
colorful12
3
830
Flow は今どうなっているか
mizdra
PRO
0
870
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
810
ソフトウェアラスタライザ
fadis
1
780
XHTMLが残したもの
yosuke_furukawa
PRO
1
380
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
130
Press start. Python's next generation.
willingc
PRO
3
300
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
280
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
620
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Designing for Timeless Needs
cassininazir
1
470
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
[SF Ruby Conf 2025] Rails X
palkan
2
1.3k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
640
Embracing the Ebb and Flow
colly
88
5.2k
How to Ace a Technical Interview
jacobian
281
24k
Building Adaptive Systems
keathley
44
3.2k
For a Future-Friendly Web
brad_frost
183
10k
Into the Great Unknown - MozCon
thekraken
41
2.7k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
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