Created
October 23, 2012 04:43
-
-
Save BrianJoyce/3936735 to your computer and use it in GitHub Desktop.
being concise with RSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # the way I was used to doing it | |
| describe Dog do | |
| it 'respond to name' do | |
| dog = Dog.new | |
| dog.should respond_to(:name) | |
| end | |
| end | |
| # "subject" allows you to instantiate Dog in a cooler way | |
| describe Dog do | |
| it "responds to name" do | |
| subject.should respond_to(:name) | |
| end | |
| end | |
| # I later learned you can drop the entire "subject" off and do a "respond_to" to call the (:method) | |
| describe Dog do | |
| it "responds to name" do | |
| should respond_to(:name) | |
| end | |
| end | |
| # An even simpler way to do it in one line, wihtout doing the "respond to" awkward repitition | |
| describe Dog do | |
| it 'responds to name' { should respond_to(:name) } | |
| end | |
| # The simplest way to do one line | |
| describe Dog do | |
| it { should respond_to(:name) } | |
| end | |
| # Same way as above in case you want to test variable assignment, not method functionality | |
| describe Dog do | |
| it { subject.name.should == "Bowser" } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment