SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
http://xkcd.com/386/




   Wrong
The right way to assert
Time Is Money
       (Test::Unit)
assert_equal money, time
• verb is moved to front
• direct and indirect objects (expected and
  actual) are reversed
Time Is Money
        (RSpec)
time.should ==(money)
• confusing syntax -- space vs. dot vs.
  underscore vs. parens
• == looks familiar, but “should” is inserted
  between parameters so it’s not apparent
  what the calculation is
Time Is Money
       (Minitest)
assert time == money
• Ah, now I see what you mean
• Default failure message is not helpful
      “Failed assertion, no message given.”


•   Making the message helpful violates DRY
    assert time == money, “Time should equal money”
Time Is Money
          (Wrong)
assert { time == money }
 • Failure message is helpful:
Expected (time == money), but 6 is not equal to 27
    time is 6
    money is 27
How do we do it?
Magic

• RubyParser and Ruby2Ruby by Ryan
  Davis
• We turn the block into source code,
  parse it into an AST, break it down into
  parts, then convert back to code for the
  messages
Also, we cheat

• We open the source file on disk, jump to
  the right line, and parse it
• If you’re constructing your tests with
  metaprogramming, you’ve got bigger
  problems than not being able to use
  Wrong
Less Is More
Test::Unit Asserts                            RSpec Matchers
assert_block { x }                            x.should be_true
assert(x)                                     x.should be_false
assert_equal x, y
assert_raise LoadError { x }                  x.should be_nil
assert_raise { x }                            x.should == y
assert_raise LoadError.new("why") { x }       x.should >= y




       assert { ... }
assert_raise(RuntimeError, LoadError) { x }   x.should be_something(y)
assert_raise_kind_of(LoadError) { x }
assert_instance_of(String, x)                 x.should be_close(y, delta)
assert_instance_of([String, Fixnum], x)       x.should be_instance_of y
assert_nil x                                  x.should be_an_instance_of y
assert_kind_of                                x.should be_kind_of y
assert_respond_to x, :to_y
assert_match /regex/, s                       x.should be_a_kind_of y"
assert_same x, y                              x.should eql(y)




        deny { ... }
assert_operator x, :>=, y                     x.should equal(y)
assert_nothing_raised x                       x.should exist
flunk
assert_not_same x,y                           team.should have(11).players
assert_not_equal x,y                          [1,2,3].should have(3).items
assert_not_nil                                "this string".should have(11).characters
assert_no_match regex, x                      x.should have_at_least(number).items
assert_throw
assert_throws                                 x.should have_at_most(number).items
assert_nothing_thrown                         x.should include(y)
assert_in_delta f, g, delta                   x.should match(/regex/)
assert_send [o, m, arg1, arg2]                lambda { do_something_risky }.should raise_exception
assert_boolean x
assert_true x                                 lambda { do_something_risky }.should raise_exception
assert_false x                                (PoorRiskDecisionError)
assert_compare x, ">=", y                     lambda { do_something_risky }.should raise_exception
assert_fail_assertion { x }                   (PoorRiskDecisionError) { |exception|
assert_raise_message m, { x }
assert_const_defined Test, :Unit              exception.data.should == 42 }
assert_not_const_defined Test, :Unit          lambda { do_something_risky }.should raise_exception
assert_predicate o, :empty?                   (PoorRiskDecisionError, ""that was too risky"")
assert_not_predicate                          lambda { do_something_risky }.should raise_exception
assert_alias_method
assert_path_exist "/foo"                      (PoorRiskDecisionError, /oo ri/)
assert_path_not_exist "/foo"                  x.should respond_to(*names)
Helpers

• rescuing { }
• capturing { }
• close_to?
 • assert { x.close_to?(y) }
 • assert { x.close_to?(y, delta) }
Frameworks

• Minitest
• RSpec
• Test::Unit
• ???
Explanations


assert("since we're on Earth")
        { sky.blue? }
Color
• Because you can’t succeed without it
Info
•   Authors
    •   Steve Conover - <sconover@gmail.com>
    •   Alex Chaffee - <alex@stinky.com> -
        <http://alexch.github.com>
•   Github: <http://github.com/alexch/wrong>
•   Tracker: <http://www.pivotaltracker.com/
    projects/109993>

Weitere ähnliche Inhalte

Was ist angesagt?

Array in php
Array in phpArray in php
Array in phpilakkiya
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arraysKumar
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2Heather Rock
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String FunctionsGeshan Manandhar
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional SwiftJason Larsen
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iteratorssdevalk
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operatorsJesus Obenita Jr.
 
SPL: The Undiscovered Library - DataStructures
SPL: The Undiscovered Library -  DataStructuresSPL: The Undiscovered Library -  DataStructures
SPL: The Undiscovered Library - DataStructuresMark Baker
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in HaskellHiromi Ishii
 

Was ist angesagt? (18)

Array in php
Array in phpArray in php
Array in php
 
Rakudo
RakudoRakudo
Rakudo
 
Array in php
Array in phpArray in php
Array in php
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 
03 Php Array String Functions
03 Php Array String Functions03 Php Array String Functions
03 Php Array String Functions
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional Swift
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iterators
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
PHP 101
PHP 101 PHP 101
PHP 101
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
SPL: The Undiscovered Library - DataStructures
SPL: The Undiscovered Library -  DataStructuresSPL: The Undiscovered Library -  DataStructures
SPL: The Undiscovered Library - DataStructures
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 

Ähnlich wie Wrong

Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, loopingMuthuganesh S
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testingVincent Pradeilles
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala LanguageAshal aka JOKER
 

Ähnlich wie Wrong (20)

SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
Meet scala
Meet scalaMeet scala
Meet scala
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
 
Introduction to-scala
Introduction to-scalaIntroduction to-scala
Introduction to-scala
 
Next Level Testing
Next Level TestingNext Level Testing
Next Level Testing
 
Python to scala
Python to scalaPython to scala
Python to scala
 

Kürzlich hochgeladen

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Wrong

  • 1. http://xkcd.com/386/ Wrong The right way to assert
  • 2. Time Is Money (Test::Unit) assert_equal money, time • verb is moved to front • direct and indirect objects (expected and actual) are reversed
  • 3. Time Is Money (RSpec) time.should ==(money) • confusing syntax -- space vs. dot vs. underscore vs. parens • == looks familiar, but “should” is inserted between parameters so it’s not apparent what the calculation is
  • 4. Time Is Money (Minitest) assert time == money • Ah, now I see what you mean • Default failure message is not helpful “Failed assertion, no message given.” • Making the message helpful violates DRY assert time == money, “Time should equal money”
  • 5. Time Is Money (Wrong) assert { time == money } • Failure message is helpful: Expected (time == money), but 6 is not equal to 27 time is 6 money is 27
  • 6. How do we do it?
  • 7. Magic • RubyParser and Ruby2Ruby by Ryan Davis • We turn the block into source code, parse it into an AST, break it down into parts, then convert back to code for the messages
  • 8. Also, we cheat • We open the source file on disk, jump to the right line, and parse it • If you’re constructing your tests with metaprogramming, you’ve got bigger problems than not being able to use Wrong
  • 9. Less Is More Test::Unit Asserts RSpec Matchers assert_block { x } x.should be_true assert(x) x.should be_false assert_equal x, y assert_raise LoadError { x } x.should be_nil assert_raise { x } x.should == y assert_raise LoadError.new("why") { x } x.should >= y assert { ... } assert_raise(RuntimeError, LoadError) { x } x.should be_something(y) assert_raise_kind_of(LoadError) { x } assert_instance_of(String, x) x.should be_close(y, delta) assert_instance_of([String, Fixnum], x) x.should be_instance_of y assert_nil x x.should be_an_instance_of y assert_kind_of x.should be_kind_of y assert_respond_to x, :to_y assert_match /regex/, s x.should be_a_kind_of y" assert_same x, y x.should eql(y) deny { ... } assert_operator x, :>=, y x.should equal(y) assert_nothing_raised x x.should exist flunk assert_not_same x,y team.should have(11).players assert_not_equal x,y [1,2,3].should have(3).items assert_not_nil "this string".should have(11).characters assert_no_match regex, x x.should have_at_least(number).items assert_throw assert_throws x.should have_at_most(number).items assert_nothing_thrown x.should include(y) assert_in_delta f, g, delta x.should match(/regex/) assert_send [o, m, arg1, arg2] lambda { do_something_risky }.should raise_exception assert_boolean x assert_true x lambda { do_something_risky }.should raise_exception assert_false x (PoorRiskDecisionError) assert_compare x, ">=", y lambda { do_something_risky }.should raise_exception assert_fail_assertion { x } (PoorRiskDecisionError) { |exception| assert_raise_message m, { x } assert_const_defined Test, :Unit exception.data.should == 42 } assert_not_const_defined Test, :Unit lambda { do_something_risky }.should raise_exception assert_predicate o, :empty? (PoorRiskDecisionError, ""that was too risky"") assert_not_predicate lambda { do_something_risky }.should raise_exception assert_alias_method assert_path_exist "/foo" (PoorRiskDecisionError, /oo ri/) assert_path_not_exist "/foo" x.should respond_to(*names)
  • 10. Helpers • rescuing { } • capturing { } • close_to? • assert { x.close_to?(y) } • assert { x.close_to?(y, delta) }
  • 12. Explanations assert("since we're on Earth") { sky.blue? }
  • 13. Color • Because you can’t succeed without it
  • 14. Info • Authors • Steve Conover - <sconover@gmail.com> • Alex Chaffee - <alex@stinky.com> - <http://alexch.github.com> • Github: <http://github.com/alexch/wrong> • Tracker: <http://www.pivotaltracker.com/ projects/109993>