【问题标题】:issue with stubs and rspec old syntax存根和 rspec 旧语法的问题
【发布时间】:2015-03-18 23:18:59
【问题描述】:

我正在编写一些代码并使用 rspec,但收到一条警告说语法太旧,我不知道应该如何编写它?

it "should calculate the value correctly" do 
        mock_cards = [Card.new(:clubs, 5), Card.new(:diamonds, 10)]
        hand = Hand.new
        hand.stub(:cards) { cards } #stub out cards and have it return cards
        expect(hand.value).to eq (15)
    end

错误消息如下:使用来自 rspec-mocks 的旧 :should 语法的 stub 而不显式启用该语法已被弃用。改用新的:expect 语法或显式启用:should

【问题讨论】:

    标签: ruby rspec stubs


    【解决方案1】:

    改为这样:

    allow(hand).to receive(:cards) { cards }
    

    https://github.com/rspec/rspec-mocks#method-stubs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多