Sha256: f577b3cbbae0d94770104bec63fe8073614953bb8563753a30b667c2899e4eb9

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path("../../../../base", __FILE__)

describe Vagrant::Action::Builtin::Confirm do
  let(:app) { lambda { |env| } }
  let(:env) { { ui: double("ui") } }
  let(:message) { "foo" }

  ["y", "Y"].each do |valid|
    it "should set the result to true if '#{valid}' is given" do
      expect(env[:ui]).to receive(:ask).with(message).and_return(valid)
      described_class.new(app, env, message).call(env)
      expect(env[:result]).to be
    end
  end

  it "should set the result to true if force matches" do
    force_key = :tubes
    env[force_key] = true
    described_class.new(app, env, message, force_key).call(env)
    expect(env[:result]).to be
  end

  it "should ask if force is not true" do
    force_key = :tubes
    env[force_key] = false
    expect(env[:ui]).to receive(:ask).with(message).and_return("nope")
    described_class.new(app, env, message).call(env)
    expect(env[:result]).not_to be
  end

  it "should set result to false if anything else is given" do
    expect(env[:ui]).to receive(:ask).with(message).and_return("nope")
    described_class.new(app, env, message).call(env)
    expect(env[:result]).not_to be
  end

  it "should ask multiple times if an allowed set is given and response isn't in that set" do
    times = 0
    allow(env[:ui]).to receive(:ask) do |arg|
      expect(arg).to eql(message)
      times += 1

      if times <= 3
        "nope"
      else
        "y"
      end
    end
    described_class.new(app, env, message, allowed: ["y", "N"]).call(env)
    expect(env[:result]).to be_true
    expect(times).to eq(4)
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.9.5.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.9.1.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.5.2 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.5.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.4.2 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.4.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.1.2 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-unbundled-1.8.1.1 test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/unit/vagrant/action/builtin/confirm_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/unit/vagrant/action/builtin/confirm_test.rb