7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rspec】メソッドが呼び出される順序をテストする

Last updated at Posted at 2014-10-15

スタブして、orderedをつける。

Class AAA
  def abc_def
    puts_abc
    puts_def
  end

  def puts_abc
    puts 'abc!'
  end

  def puts_def
    puts 'def!'
  end
end
describe '#abc_def' do
  let(:aaa) { AAA.new }
  it do
    expect(aaa).to receive(puts_abc).ordered
    expect(aaa).to receive(puts_def).ordered
    aaa.abc_def
  end
  # => Success

  it do
    expect(aaa).to receive(puts_def).ordered
    expect(aaa).to receive(puts_abc).ordered
    # ↑順序が逆
    aaa.abc_def
  end
  # => Failure/Error:
  #     received :puts_abc out of order
end
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?