spec/tailor/configuration_spec.rb in tailor-1.0.0.alpha2 vs spec/tailor/configuration_spec.rb in tailor-1.0.0

- old
+ new

@@ -26,39 +26,40 @@ describe "#file_set" do before do subject.instance_variable_set(:@file_sets, {}) end - + it "adds the set of stuff to @file_sets" do - subject.file_set(:bobo) do - trailing_newlines 2 + subject.file_set('some_files', :bobo) do |style| + style.trailing_newlines 2 end subject.instance_variable_get(:@file_sets).should == { bobo: { file_list: [], style: { - :allow_camel_case_methods=>false, - :allow_hard_tabs=>false, - :allow_screaming_snake_case_classes=>false, - :allow_trailing_line_spaces=>false, - :indentation_spaces=>2, - :max_code_lines_in_class=>300, - :max_code_lines_in_method=>30, - :max_line_length=>80, - :spaces_after_comma=>1, - :spaces_before_comma=>0, - :spaces_before_lbrace=>1, - :spaces_after_lbrace=>1, - :spaces_before_rbrace=>1, - :spaces_in_empty_braces=>0, - :spaces_after_lbracket=>0, - :spaces_before_rbracket=>0, - :spaces_after_lparen=>0, - :spaces_before_rparen=>0, - :trailing_newlines=>2 + allow_camel_case_methods: [false, { level: :error }], + allow_hard_tabs: [false, { level: :error }], + allow_screaming_snake_case_classes: [false, { level: :error }], + allow_trailing_line_spaces: [false, { level: :error }], + allow_invalid_ruby: [false, { level: :warn }], + indentation_spaces: [2, { level: :error }], + max_code_lines_in_class: [300, { level: :error }], + max_code_lines_in_method: [30, { level: :error }], + max_line_length: [80, { level: :error }], + spaces_after_comma: [1, { level: :error }], + spaces_after_lbrace: [1, { level: :error }], + spaces_after_lbracket: [0, { level: :error }], + spaces_after_lparen: [0, { level: :error }], + spaces_before_comma: [0, { level: :error }], + spaces_before_lbrace: [1, { level: :error }], + spaces_before_rbrace: [1, { level: :error }], + spaces_before_rbracket: [0, { level: :error }], + spaces_before_rparen: [0, { level: :error }], + spaces_in_empty_braces: [0, { level: :error }], + trailing_newlines: [2, { level: :error }] } } } end @@ -76,20 +77,37 @@ subject.instance_variable_set(:@config_file, 'pants') subject.config_file subject.instance_variable_get(:@config_file).should == 'pants' end end - + context "@config_file is nil" do - it "returns DEFAULT_RC_FILE" do - subject.config_file - subject.instance_variable_get(:@config_file).should == - Tailor::Configuration::DEFAULT_RC_FILE + context "DEFAULT_PROJECT_CONFIG exists" do + before do + File.should_receive(:exists?).with(/\.tailor/).and_return true + end + + it "returns Dir.pwd + './tailor'" do + subject.config_file + end end + + context "DEFAULT_PROJECT_CONFIG does not exist" do + before do + File.should_receive(:exists?).with(/\.tailor/).and_return false + File.should_receive(:exists?).with(/\.tailorrc/).and_return true + end + + it "returns DEFAULT_RC_FILE" do + subject.config_file + subject.instance_variable_get(:@config_file).should == + Tailor::Configuration::DEFAULT_RC_FILE + end + end end end - + describe "#file_list" do before do FileUtils.mkdir_p 'one/two' File.new('one/two/three.rb', 'w') { |f| f.write "stuff" } end @@ -99,19 +117,19 @@ it "returns all files in the glob" do results = subject.file_list(['one/two/three.rb']) results.last.should match /one\/two\/three.rb/ end end - + context "the Array has a directory" do context "the directory has files" do it "returns all files in the directory" do results = subject.file_list(['.']) results.last.should match /one\/two\/three.rb/ end end - + context "the directory is empty" do before do FileUtils.mkdir 'empty' FileUtils.rm_rf 'one' end @@ -121,11 +139,11 @@ results.should == [] end end end end - + context "glob is a glob" do it "returns all files in the glob" do results = subject.file_list('one/**/*.rb') results.last.should match /one\/two\/three.rb/ end @@ -135,13 +153,14 @@ it "returns all files in the glob" do results = subject.file_list('one') results.last.should match /one\/two\/three.rb/ end end - + context "glob is a file" do it "returns all files in the glob" do - subject.file_list('one/two/three.rb').last.should match /one\/two\/three.rb/ + subject.file_list('one/two/three.rb').last. + should match /one\/two\/three.rb/ end end end end