Rspec Rake Task: How to parse a parameter?

半腔热情 提交于 2019-12-06 03:16:42

You could stub out HighLine:

describe "rake task setup:admin" do
  let(:highline){ double(:highline) }
  let(:email){ "test@example.com" }
  let(:password){ "password" }

  before do
    load File.expand_path("../../../lib/tasks/setup.rake", __FILE__)
    Rake::Task.define_task(:environment)
    allow(HighlLine).to receive(:new).and_return(highline)
    allow(highline).to receive(:ask).with("Email: ").and_return(email)
    allow(highline).to receive(:ask).with("Enter password: ").and_return(password)
    allow(highline).to receive(:ask).with("Confirm password: ").and_return(password)
  end

  let :run_rake_task do
    Rake.application["db:setup:admin"]
  end

  it "creates a new User" do
    run_rake_task
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!