0
0

More than 1 year has passed since last update.

#Ruby Rspec expect with keyword args example

Last updated at Posted at 2020-05-02
require "rspec"

class Foo
  def self.run(x:, y:)
    Bar.run(x: x, y: y)
  end
end

class Bar
  def self.run(x:, y:)
    false
  end
end

describe do
  subject { Foo.run(x: "X", y: "Y") }

  describe do
    before do
      expect(Bar).to receive(:run).with(x: "X", y: "Y").and_return true
    end

    it { is_expected.to be true }
  end

  describe do
    let(:param) { { x: "X", y: "Y" } }

    before do
      expect(Bar).to receive(:run).with(**param).and_return true
    end

    it { is_expected.to be true }
  end

  describe do
    let(:param) { { "x" => "X", "y" => "Y" } }

    before do
      expect(Bar).to receive(:run).with(x: "X", y: "Y").and_return true
    end

    it { is_expected.to be true }
  end

end

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
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
0
0