官术网_书友最值得收藏!

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
主站蜘蛛池模板: 龙陵县| 慈利县| 金溪县| 天台县| 莱芜市| 馆陶县| 黄大仙区| 西乌珠穆沁旗| 丰顺县| 临泉县| 呼伦贝尔市| 张家港市| 锡林浩特市| 巴彦淖尔市| 民丰县| 平潭县| 伊川县| 延长县| 乌拉特中旗| 南昌市| 开平市| 旬邑县| 镇坪县| 永仁县| 新平| 洱源县| 五大连池市| 洛阳市| 莱芜市| 伊吾县| 庄浪县| 丹阳市| 成安县| 大同县| 砀山县| 天门市| 东辽县| 富宁县| 红安县| 二手房| 绥棱县|