Your SlideShare is downloading. ×
RSpec Quick Reference
RSpec Quick Reference
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

RSpec Quick Reference

2,466

Published on

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

No Downloads
Views
Total Views
2,466
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
36
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. Rspec Cheat Sheet loads the file tested by the spec describe [ClassName] do require "thing" • describe declares what is being tested and defines a context describe Thing do • Optionally, you can specify before do some code to run before each @thing = Thing.new example. end • The beginning of each example it "should check universal stability" do is marked by "it" followed @thing.answer.should == 42 by a description of expected end behavior in quotes it "should enforce universal stability" do @thing.val = 3 • the first lines of each spec set @thing.enforce_stability up the conditions required for @thing.val.should == 42 the test to succeed end • if any line of the example fails to execute, the spec fails. end • object.should and • object.should_not are used in rspec to compare actual to expected values (see the next page for syntax for the different types of comparisons) Read more about RSpec http://rspec.info/ http://www.pragprog.com/titles/achbd/the-rspec-book Blazing Cloud • Ruby language Class 1
  • 2. target.should equal <value>target.should not_equal <value>target.should be_close <value>, <tolerance>target.should_not be_close <value>, <tolerance>target.should be <value>target.should_not be <value>target.should be_predicate [optional args]target.should_not be_predicate [optional args]target.should be < 6target.should == 5target.should_not == Samanthatarget.should match <regex>target.should_not match <regex>target.should be_an_instance_of <class>target.should_not be_an_instance_of <class>target.should be_a_kind_of <class>target.should_not be_a_kind_of <class>target.should respond_to <symbol>target.should_not respond_to <symbol>lambda {a_call}.should raise_errorlambda {a_call}.should raise_error(<exception> [, message])lambda {a_call}.should_not raise_errorlambda {a_call}.should_not raise_error(<exception> [, message])target.should include <object>target.should_not include <object>target.should have(<number>).thingstarget.should have_at_least(<number>).thingstarget.should have_at_most(<number>).thingstarget.should have(<number>).errors_on(:field)lambda { thing.destroy }.should change(Thing, :count).by(-1)2 Ruby Language Class • Blazing Cloud

×