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
390
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
960
Kingdom of the Machine
yui_knk
2
1.8k
Ruby Parser progress report 2025
yui_knk
1
930
Understanding Ruby Grammar Through Conflicts
yui_knk
1
860
Ruby's Line Breaks
yui_knk
4
6.1k
What is Parser
yui_knk
11
5.6k
Ruby Parser progress report 2024
yui_knk
2
520
最高の構文木の設計 2024年版
yui_knk
9
6.8k
Converting AST
yui_knk
4
450
Other Decks in Programming
See All in Programming
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.4k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
890
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
210
OSもどきOS
arkw
0
580
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
670
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
290
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
570
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
410
Vite+ Unified Toolchain for the Web
naokihaba
0
330
Inside Stream API
skrb
1
750
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
600
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Navigating Weather and Climate Data
rabernat
0
220
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
440
Leo the Paperboy
mayatellez
7
1.8k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Discover your Explorer Soul
emna__ayadi
2
1.1k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
210
Speed Design
sergeychernyshev
33
1.9k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
The agentic SEO stack - context over prompts
schlessera
0
820
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