require 'spec_helper' require 'rformat/application' describe RFormat::Application do let(:output) { StringIO.new } let(:env) { RFormat::Environment.new } let(:app) { RFormat::Application.new(output) } it "creates a default RFormat::Environment" do expect(app.environment).to be_an_instance_of(RFormat::Environment) end it "outputs a help menu" do output.should_receive(:puts).with(File.read(File.join(ROOT, 'HELP.txt'))) app.help end it "outputs a list of the available formatters" do output.should_receive(:puts).with("Formatters:") output.should_receive(:puts).with(env.formatters.keys.map { |f| " #{f}\n" }) app.list [] end it "outputs the version with copyright information" do version = File.read(File.join(RFormat::root_dir, 'VERSION')) copyright = "Copyright (c) 2012 Dayton Nolan\n" output.should_receive(:puts).with("#{version}\n#{copyright}") app.version end it "can parse the command from an args array" do ARGV = ['list'] expect(app.parse_command).to eq(:list) ARGV = ['nyan', 'unicorn'] expect(app.parse_command).to eq(:write) end it "doesn't count subcommands as arguments" do ARGV = ['list'] list_example = RFormat::Application.new(StringIO.new, RFormat::Environment.new) list_example.parse_command expect(list_example.args).to eq([]) ARGV = ['nyan', 'unicorn'] format_example = RFormat::Application.new(StringIO.new, RFormat::Environment.new) format_example.parse_command expect(format_example.args).to eq(['nyan', 'unicorn']) end it "can parse the options from an args array" do ARGV = ['-v'] app.parse_options expect(app.options[:version]).to be true ARGV = ['-h'] app.parse_options expect(app.options[:help]).to be true end describe 'creating a .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 "should write the formatters to the .rspec file" do output.should_receive(:puts).with('rspec now using format(s): NyanCatFormatter, UnicornFormatter') app.write(['nyan', 'unicorn']) expect(File.read(env.rspec_config_file)).to eq('--color --format NyanCatFormatter --format UnicornFormatter') end end it "should run the write command" do ARGV = ['nyan', 'unicorn'] app.should_receive(:write).with(['nyan', 'unicorn']) app.run end it "should run the list command" do ARGV = ['list'] app.should_receive(:list).with([]) app.run end end