# encoding: utf-8 require "spec_helper_dev" module Generators describe Install, :sandbox do describe "#invoke_all" do def run_with_options(options = {}) try_in_sandbox do subject = Install.new [], options subject.invoke_all end end let(:files_in_sandbox) { Dir["#{ sandbox }/**/*.*"] } context "without options" do let!(:dir) { "#{ sandbox }/db/migrate" } before { run_with_options } it "copies migrations to 'db/migrate'" do migrations.each { |file| expect(dir).to have_migration_from file } end it "doesn't add other files" do expect(files_in_sandbox.count).to eq migrations.count end end context "dummy: true" do let!(:dir) { "#{ sandbox }/spec/dummy/db/migrate" } before { run_with_options dummy: true } it "copies migrations to 'spec/dummy/db/migrate'" do migrations.each { |file| expect(dir).to have_migration_from file } end it "doesn't add other files" do expect(files_in_sandbox.count).to eq migrations.count end end context "folder: 'folder'" do let!(:dir) { "#{ sandbox }/folder/db/migrate" } before { run_with_options folder: "folder" } it "copies migrations to 'some_path/db/migrate'" do migrations.each { |file| expect(dir).to have_migration_from file } end it "doesn't add other files" do expect(files_in_sandbox.count).to eq migrations.count end end context "if a migration is already added" do before do run_with_options Timecop.travel(Time.now + 10) { run_with_options } end it "doesn't copy it again" do expect(files_in_sandbox.count).to eq migrations.count end end end end end