Your SlideShare is downloading. ×
0
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Ruby Blocks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ruby Blocks

636

Published on

Slides for a section teaching about blocks in Ruby

Slides for a section teaching about blocks in Ruby

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
636
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby Blocks<br />Test Driven Performance Monitorwith Stubs<br />
  • 2. Blocks<br />A block is an anonymous function. <br />my_array.each do |value|<br /> do_something(value)<br />end<br />
  • 3. Performance Monitor Example <br />How it works:<br />Record Time<br />Run Code<br />Report Time Difference<br />Hmmm… how do we test when time is always changing?<br />
  • 4. A Test Double replaces the &quot;real&quot; instance of an object used by the production code with something suitable for the currently running test, but with the same interface<br />Stubs<br />Hard-coded values<br />Mocks<br />Pre-programmed with expectations<br />Fail-fast<br />Test Doubles in general are often called Mock Objects, so be careful about terminology<br />Fakes<br />Can store values across calls, but don&apos;t really do what the live object would do<br />E.g. in-memory database<br />Test Doubles<br />
  • 5. How to Test Code with Dependencies<br />Example from The Rspec Book by David Chelimsky<br />
  • 6. Isolating the Subject<br />Example from The Rspec Book by David Chelimsky<br />
  • 7. Stub in RSpec<br />my_instance.stub!(:msg).and_return(value)<br />MyClass.stub!(:msg).and_return(value)<br />
  • 8. Stub in RSpec<br />my_obj.stub!(:msg).and_return(&quot;1&quot;,2)<br />my_obj.stub!(:msg).and_return { ... }<br />
  • 9. Stub for Specific Values<br />my_obj.stub!(:msg).with(1).and_return(2)<br />
  • 10. Stub in RSpec<br />my_obj.stub!(:msg).and_return { ... }<br />

×