require 'rails_helper'
require 'generator_spec'

require 'generators/dunlop/install/base/base_generator'
describe Dunlop::Install::BaseGenerator, type: :generator do
  #destination File.expand_path("../../tmp", __FILE__)
  destination Rails.root.join('tmp')
  #arguments %w(something)

  before :all do
    prepare_destination
    FileUtils.cp_r(Rails.root.join('config'), Rails.root.join('tmp'))
    destination = Rails.root.join('tmp')
    Dir.mkdir(destination.join('spec'))
    FileUtils.touch destination.join('Gemfile')
    File.open(destination.join('spec/rails_helper.rb'), 'w+') do |file|
      file.puts "require 'rspec/rails'"
      file.puts "RSpec.configure do |config|"
      file.puts "end"
    end
    run_generator
  end

  specify do
    expect( destination_root ).to have_structure {
      directory "spec" do
        file "rails_helper.rb" do
          contains "Capybara.javascript_driver = :poltergeist"
          contains "require 'rspec/dunlop'"
          contains "Rspec::Dunlop::GeneralHelpers"
        end
      end
    }
  end
end
