Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Rspec Essentials

You're reading from   Rspec Essentials Develop testable, modular, and maintainable Ruby software for the real world using RSpec

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781784395902
Length 222 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Tadayon Tadayon
Author Profile Icon Tadayon
Tadayon
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

RSpec Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Exploring Testability from Unit Tests to Behavior-Driven Development 2. Specifying Behavior with Examples and Matchers FREE CHAPTER 3. Taking Control of State with Doubles and Hooks 4. Setting Up and Cleaning Up 5. Simulating External Services 6. Driving a Web Browser with Capybara 7. Building an App from the Outside In with Behavior-Driven Development 8. Tackling the Challenges of End-to-end Testing 9. Configurability 10. Odds and Ends Index

Technical assumptions


This book assumes that the reader is comfortable reading and writing Ruby code. Familiarity with RSpec is strongly recommended, though a total beginner to RSpec should find it possible to understand most of the recipes with the help of the online RSpec documentation. Each code example has been tested and works. I have used the latest stable versions available at the time of writing: Ruby 2.3.0 with RSpec 3.4.0.

RSpec 3 uses a different syntax from RSpec 2. Version 2.13 introduced a new syntax for assertions while 2.14 introduced a new syntax for doubles and expectations. RSpec 3.0 introduced a number of new features and changes as well. I have used the new syntax and features throughout the book:

require 'rspec'

describe 'new RSpec syntax' do
  it "uses the new assertion syntax" do
    # new                           # deprecated
    expect(1 + 1).to eq(2)          # (1 + 1).should == 2
  end

  context "mocks and expectations" do
    let(:obj) do
      # new                          # deprecated
      double('foo')                  # obj = mock('foo')      
    end
    
    it "uses the new allow syntax for mocks" do
      # new                          # deprecated
      allow(obj).to receive(:bar)    # obj.stub(:bar)
    end

    it "uses the new expect syntax for expectations" do
      # new                          # deprecated
      expect(obj).to receive(:baz)   # obj.should_receive(:baz)
      
      obj.baz
    end    
  end
end
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images
Modal Close icon
Modal Close icon