Testing hash contents using RSpec

后端 未结 4 577
南旧
南旧 2021-02-06 20:37

I have a test like so:

it \"should not indicate backwards jumps if the checker position is not a king\" do
    board = Board.new
    game_board = board.create_te         


        
4条回答
  •  孤城傲影
    2021-02-06 20:53

    Just wanna add to @David's answer. You could nest and use matchers in your include hash. For example:

    # Pass
    expect({
      "num" => 5, 
      "a" => { 
        "b" => [3, 4, 5] 
      }
    }).to include({
      "num" => a_value_between(3, 10), 
      "a" => {
        "b" => be_an(Array)
      }
    })
    

    A caveat: a nested include hash must test all keys or the test will fail, e.g.:

    # Fail
    expect({
      "a" => { 
        "b" => 1,
        "c" => 2
      }
    }).to include({
      "a" => {
        "b" => 1
      }
    })
    

提交回复
热议问题