require 'spec_helper' require 'rformat/environment' describe RFormat::Environment do let(:env) { RFormat::Environment.new } before :each do File.open(RFormat::rformat_env_file, "w+") do |f| f << "test_custom: TestCustom" end end after :each do FileUtils.rm_rf RFormat::rformat_env_file if File.exists? RFormat::rformat_env_file end it "has a rspec_config_file" do expect(env.rspec_config_file).to eq(File.join(ENV['HOME'], '.rspec')) end it "determines the existence of custom formats" do expect(env.has_custom_formats?).to be true end it "can load formatters" do expect(env.load_formatters).to eq({ "default" => "progress", "doc" => "documentation", "fuubar" => "Fuubar", "nc" => "Nc", "nyan" => "NyanCatFormatter", "progress" => "progress", "unicorn" => "UnicornFormatter", "webkit" => "RSpec::Core::Formatters::WebKit" }) end it "can load custom formatters" do expect(env.load_custom_formatters).to eq ({ "test_custom" => "TestCustom" }) end it "has custom_formatters" do expect(env.custom_formatters).to eq({ "test_custom" => "TestCustom" }) end it "has formatters" do expect(env.formatters.empty?).to be false end it "has default and custom formatters" do expect(env.formatters).to include("default") expect(env.formatters).to include("test_custom") end describe '~/.rspec file' do it "can determine if a ~/.rspec config file exists" do expect(env.has_rspec_config?).to be true end end describe 'non-existent ~/.rspec file' do before :each do FileUtils.mv(env.rspec_config_file, SPECS) if File.exists? env.rspec_config_file end after :each do FileUtils.mv("#{SPECS}/.rspec", env.rspec_config_file) if File.exists? "#{SPECS}/.rspec" end it "can determine if a ~/.rspec file does not exist" do expect(env.has_rspec_config?).to be false end it "creates a configuration string" do env.config = { color: true, formats: { default: 'default' } } expect(env.config_string).to eq("--color --format default") end it "can write an ~/.rspec file" do env.write_config expect(env.has_rspec_config?).to be true end it "creates a default configuration" do env.write_config expect(File.read(env.rspec_config_file)).to eq("--color --format default") end end end