spec/fontcustom/options_spec.rb in fontcustom-1.1.1 vs spec/fontcustom/options_spec.rb in fontcustom-1.2.0

- old
+ new

@@ -1,5 +1,6 @@ +# encoding: utf-8 require 'spec_helper' describe Fontcustom::Options do def options(args = {}) Fontcustom::Options.new(args) @@ -123,11 +124,12 @@ it "should set instance variables for each option key" do o = options o.instance_variable_set :@config_options, {} o.send :merge_options - o.instance_variables.length.should == Fontcustom::DEFAULT_OPTIONS.length + 2 # @shell, @mock_proxy (rspec) + o.send :remove_instance_variable, :@mock_proxy if o.instance_variable_get(:@mock_proxy) + o.instance_variables.length.should == Fontcustom::DEFAULT_OPTIONS.length + 1 # @shell end it "should overwrite defaults with config file" do o = options o.instance_variable_set :@config_options, { :input => "config" } @@ -152,99 +154,99 @@ o.instance_variable_get(:@font_name).should == "A_stR4nG3--nAm3---" end end context ".set_data_path" do - it "should set :data_cache in the config dir by default" do + it "should set :manifest in the config dir by default" do silent o = options o.instance_variable_set :@config, "path/to/config/fontcustom.yml" - o.instance_variable_set :@data_cache, nil - o.remove_instance_variable :@cli_options + o.instance_variable_set :@manifest, nil + o.send :remove_instance_variable, :@cli_options o.send :set_data_path - o.instance_variable_get(:@data_cache).should == "path/to/config/.fontcustom-data" + o.instance_variable_get(:@manifest).should == "path/to/config/.fontcustom-manifest.json" end end context "#send :set_input_paths" do - it "should raise error if input[:vectors] doesn't contain vectors" do + it "should raise error if input[:vectors] doesn't contain SVGs" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, "shared/vectors-empty" - o.remove_instance_variable :@cli_options - expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /doesn't contain any vectors/ + o.send :remove_instance_variable, :@cli_options + expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /doesn't contain any SVGs/ end context "when @input is a hash" do it "should set :templates as :vectors if :templates isn't set" do hash = { :vectors => "shared/vectors" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_input_paths input = o.instance_variable_get :@input input[:templates].should == fixture("shared/vectors") end it "should preserve :templates if it's set" do hash = { :vectors => "shared/vectors", :templates => "shared/templates" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_input_paths input = o.instance_variable_get :@input input[:templates].should == fixture("shared/templates") end it "should raise an error if :vectors isn't set" do hash = { :templates => "shared/templates" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /contain a :vectors key/ end it "should raise an error if :vectors doesn't point to an existing directory" do hash = { :vectors => "shared/not-a-dir" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /should be a directory/ end end context "when @input is a string" do it "should return a hash of locations" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, "shared/vectors" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_input_paths input = o.instance_variable_get :@input input.should have_key(:vectors) input.should have_key(:templates) end it "should set :templates to match :vectors" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, "shared/vectors" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_input_paths input = o.instance_variable_get :@input input[:templates].should == fixture("shared/vectors") end it "should raise an error if :vectors doesn't point to a directory" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, "shared/not-a-dir" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_input_paths }.to raise_error Fontcustom::Error, /should be a directory/ end end end @@ -254,22 +256,22 @@ silent o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@font_name, "Test-Font" o.instance_variable_set :@output, nil - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output[:fonts].should == fixture("Test-Font") end it "should print a warning" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@font_name, "Test-Font" o.instance_variable_set :@output, nil - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options stdout = capture(:stdout) { o.send :set_output_paths } stdout.should match("Test-Font") end end @@ -277,11 +279,11 @@ it "should set :css and :preview to match :fonts if either aren't set" do hash = { :fonts => "output/fonts" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output[:css].should == fixture("output/fonts") output[:preview].should == fixture("output/fonts") end @@ -293,11 +295,11 @@ :preview => "output/preview" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output[:css].should == fixture("output/styles") output[:preview].should == fixture("output/preview") end @@ -308,32 +310,32 @@ "special.js" => "assets/javascripts" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output[:"special.js"].should == fixture("assets/javascripts") end it "should raise an error if :fonts isn't set" do hash = { :css => "output/styles" } o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, hash - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_output_paths }.to raise_error Fontcustom::Error, /contain a :fonts key/ end end context "when @output is a string" do it "should return a hash of output locations" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, "output/fonts" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output.should be_a(Hash) output.should have_key(:fonts) output.should have_key(:css) @@ -342,22 +344,22 @@ it "should set :css and :preview to match :fonts" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, "output/fonts" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_output_paths output = o.instance_variable_get :@output output[:css].should == fixture("output/fonts") output[:preview].should == fixture("output/fonts") end it "should raise an error if :fonts exists but isn't a directory" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@output, "shared/not-a-dir" - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_output_paths }.to raise_error Fontcustom::Error, /directory, not a file/ end end end @@ -365,11 +367,11 @@ it "should expand shorthand for packaged templates" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, { :templates => "shared/templates" } o.instance_variable_set :@templates, %w|preview css scss bootstrap bootstrap-scss bootstrap-ie7 bootstrap-ie7-scss| - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_template_paths templates = o.instance_variable_get :@templates templates.should =~ [ File.join(Fontcustom.gem_lib, "templates", "fontcustom-preview.html"), File.join(Fontcustom.gem_lib, "templates", "fontcustom.css"), @@ -384,21 +386,21 @@ it "should find custom templates in :template_path" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, { :templates => fixture("shared/templates") } o.instance_variable_set :@templates, %w|custom.css| - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options o.send :set_template_paths templates = o.instance_variable_get :@templates templates.should =~ [fixture("shared/templates/custom.css")] end it "should raise an error if a template does not exist" do o = options o.instance_variable_set :@project_root, fixture o.instance_variable_set :@input, { :templates => "shared/templates" } o.instance_variable_set :@templates, %w|fake-template.txt| - o.remove_instance_variable :@cli_options + o.send :remove_instance_variable, :@cli_options expect { o.send :set_template_paths }.to raise_error Fontcustom::Error, /does not exist/ end end end