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

  • RSpec Essentials
  • Mani Tadayon
  • 206字
  • 2021-07-09 19:33:36

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
主站蜘蛛池模板: 瓮安县| 抚宁县| 义马市| 江陵县| 福清市| 石楼县| 建水县| 岑巩县| 福安市| 衡水市| 图木舒克市| 古交市| 韶山市| 洪湖市| 南皮县| 岳池县| 安阳市| 沁水县| 乐昌市| 武强县| 永定县| 安化县| 大化| 宝兴县| 霍山县| 马龙县| 丰台区| 基隆市| 德兴市| 柳林县| 道真| 邢台市| 瑞金市| 永顺县| 双桥区| 衡山县| 平远县| 阿坝| 花莲县| 梅州市| 兰溪市|